| Profilo di RobThe Ramblings of Rob Coo...BlogElenchi | Guida |
|
06/06/2008 THIS BLOG HAS MOVED! robzyc.spaces.live.com > cantgrokwontgrok.blogspot.comSo, I was thinking last night, following on from me previous post, I am going to migrate to Blogger and cease posting to Live Spaces. If you are intelligent/crazy enough to be following my blog, then please update your RSS reader to: http://cantgrokwontgrok.blogspot.com. I like the title better, definitely describes me a lot more accurately :D Hopefully this will give me the opportunity to get more feedback from [any] followers, as well as “do more” with the blog (polls etc). This will be both interesting for me as well as possibly enhance my learning, as well as others. We are all on a journey here. Also, as a note to Microsoft and the People on the Live Team: Just because I am leaving Spaces, it does mean I am leaving Live. I LOVE the other things happening with Live, and I really cannot stop praising Live Writer, Live SkyDrive and especially Live Mesh (as well as the other bits going on)! Keep up the great work, I really hope Spaces comes on enough to perhaps attract people wanting “more” back to it. See you at “Can’t Grok, Won’t Grok”! Share: 05/06/2008 Thinking of Migrating from Live Spaces to BloggerSo, looks like I am again reviewing some of the services I use against others I could be. I have actually been contemplating leaving Live Spaces for a while. Sadly, I don’t think Spaces have moved enough in the right direction. I think I have remained is due to the excellent production on the rest of the Live Services teams (Writer, SkyDrive, Mesh etc.). However, none of these require this blog. Put simply, I dislike the following:
And I do like:
So, watch this space, I may be migrating, need to run a few more tests to see what Blogger can do for me, but so far looking positive. Share: 04/06/2008 Privacy Online – How Much Would a “I’ll Google You” Get About You?Even though online privacy has been a subject that everyone has known about for a long time, I still cant help but feel that with the explosion in social networking, a lot of the basic principles seem to have been lost somewhere. By “principles” I mean:
Some of the ProblemsThere have been numerous issues with private information being found on the Internet about people ranging from silly pranks being pulled to people losing their money, jobs, or even their lives. People often only think about the former and never the consequences of the latter. It’s serious stuff. Some obvious examples:
As said before, a large part of this is due to the fact that social networking has exploded. With MySpace, Facebook, Twitter, and so on. There is literally MILLIONS of people posting huge amount of data about themselves on various servers around the world. I, like a lot of others think social networking is great. I am now back in touch with people from school, I never forget friends birthdays, its nice to see us all growing up and doing our things and being happy. What people fail to realise is that, left unchecked, ANYONE can see this, and this can be dangerous. Some SolutionsSo? What can we do to help get some sort of control over what the Internet can find out about ourselves? There are several things:
The Biggest Winner (IMO)I am all for rolling your sleeves up and having a go. So, check yourself out. The first place most searches start is Google. So, go to Google, type in your name, what comes up? Can you find information about yourself? Are you happy with it being there? If not, change it, go to the website, log in and check the privacy settings! Vary your searches, name? Phone number? Email address? As soon as you can see where your information is being leaked from, you can fix it. Remember, Google also offers Google Alerts which is a great way to keep on top of it. I have several Google Alerts trawling the net for me to check for my personal information. As of yet, there is nothing on the Internet about me that I would either be unhappy about you knowing, or wouldn’t tell you myself. Exactly how it should be. Share: 03/06/2008 Great GTD Post on RememberTheMilk (Thanks to Doug Ireton)I have recently started trying to invest a little more time in GTD (Getting Things Done). Part of this investment has also meant me signing up to RememberTheMilk (RTM) which is a great, simple-yet-effective “ToDo” list site. Prior to reading this post from Doug Ireton (which RTM posted on their blog) I hadn’t really customised RTM a great deal. This was perhaps a mixture of me not really knowing what I am doing with GTD and lack of time to “play” (expect it was more the former). I found the article clear, concise and damn useful! I spent a good chunk of this morning getting all my work, personal and study items nicely organised within RTM. I feel I perhaps have a little way to go before getting the system refined to my taste, but it’s certainly a hell of a lot closer than it was! It sounds silly but I feel much more confident in the system and can happily “forget” about items and concentrate on actually getting the things done I am supposed to be working on. I will continue to try and let you know how I get on with GTD and any other bits of productivity-boosting bits of information I come across. Links: Share: Its Been a While… Study, Exams, Thoughts and WoWHi All! Sorry its been so long since my last post, been crazy busy of late! Here’s a run down of the things that have been chewing up my time:
Good news is, the study and the work seems to be paying off! I passed the 70-316 exam with a score of 906 (700 was pass mark)! Making me a happy geek! I am now studying towards 70-315 which coincides nicely with my current work project(s). This is one of the main reasons I was pushing hard for 70-316 since I desperately wanted to get into Web. I believe thought and reflection is always good for the soul, so that always deserves some time :) World of Warcraft is addictive! But I have started to limit my time somewhat more on there! Expect more blog posts to follow. Good to be back on top of things :) Share: 06/05/2008 The Ultimate Pro-Vista Argument EVER!While the usual thoughts were flying around between us geek's on Twitter, Windows Vista came up. Basically the general theme was "we don't know why the haters hate it so much, we have no problems and enjoy working with it". I replied to a tweet from Jeff Atwood @ CodingHorror with this, which did make me chuckle to myself after sending: Top that haters! :D Share: 02/05/2008 YouTube Upgrade Quality of VideosGot a Tweet from Loic Le Meur saying that YouTube have upgraded the quality of their videos/videio player. Great stuff, there is nothing worse than watching an awesome video of big squares flying around. Here are some screen shots from Loic's HQ video posted, in Low (on the left) and High (on the right) quality for comparison (click to enlarge): Great improvement! You can switch to High Quality (where available) by clicking "View in High Quality" under the player. Links: Share: James Buck - Demonstrating the Power of the "Tweet"This story came through in the Twitter newsletter:
The CNN coverage can be found here: http://tinyurl.com/4b4hsg I know a lot of people still think Twitter is lame, and I guess there is a part of me that is yet to be convinced, but I think this is an awesome display of the power of short, sharp updates. I think the main part of my problem is that I don't have enough UK/EU contacts on my friends list. Most of my contacts are in the US, and due to obvious time zone differences, we often miss a lot of what each other have to say. So, if you're a UK/EU geek and you fancy another geek to bounce ideas etc. off, feel free to tweet me at http://twitter.com/robzyc. Links: Share: 01/05/2008 MSDN RampUp - Helping Developers on Older/Other Technologies to.. well "Ramp Up" to .NETThis came through on the MSDN Flash newsletter. Microsoft have launched a section on MSDN called "RampUp". Offering materials to help assist developers/aspiring developers that are used to working with VS 2003/2005 or VB6 to get up to speed on .NET 2.0. It also has a track/route for Java developers for those that are interested. Each route offers insights into fundamental areas of .NET 2.0, geared towards your previous knowledge, there is also access to free Microsoft E-Learning Courses, which is pretty cool. I will definitely look this over since I am studying for the (now outdated) MCAD certification, so there may be a few things I can learn in here to help with work. If there are any Java developers reading this that want to get all pissy and suggest that ".NET from Java would be ramping down lol ha :P" then don't, its a free offering from Microsoft, if you want it, take it, if not, shut up and keep developing your Java applications (as you may have noticed, I am a geek who gets real tired of geek fanaticism). I hope you find some of the content useful! Links: Share: 30/04/2008 Great Not-So-WTF-y Post on TDWTFI read "The Daily WTF" religiously. I love it, it provides both laughs and plenty of examples of how not to code. For a newbie like me, I find these sorts of real-world examples of crappy coding, it may not necessarily show me what to do, but if you are shown enough of what not to do, then you will tend to end up somewhere on or near the right trail. We have this as children all the time, we soon learn after being sent to our room enough times that colouring in the wall with crayons is not acceptable. I can now proudly say at age 23, I have shaken this habit as I know it is wrong, and you don't need to send me to my room. :) This morning however, it wasn't really a WTF post, but a good serious post on turnover in the IT industry, and I strongly recommend reading it. I have mentioned this to a couple of friends in the past, one thing I noticed while reading some of my favourite blog posters employment history (where available) I noticed a lot of them changed jobs frequently. Initially, I didn't know how to view this, but I came to the conclusion that its very easy for aspiring developers to become restless. 99.99% of the time, us geeks are consuming huge amounts of information, learning lots, and forever wanting to learn more, there just does not seem to be enough hours in the day. The problem with this, is that the rate of business change is far slower than that. Which simply means that with these energetic developers that are keen to "keep the pace up" they can quickly find themselves wanting more from "9-5". Is this a bad thing? I do not run a software house or manage a software team, but my thoughts would say that even staff turnover would be bad (sorry to lose a good member of the team, pain in the ass of recruiting) I would much rather have a highly motivated team, than a team that feels they are stagnating. This is not necessarily through fault of the business, but simply, the individual outgrowing the business. We always here it, but so few truly believe it. Embrace change! Links: Share: 29/04/2008 This Geek Becomes a "Real" Geek and Gets on "World of Warcraft" (WoW)I have finally done it. Some of the people who's blog I watch play World of Warcraft (Rob Conery springs to mind). I decided to give the study a bit of a break this weekend, and had nothing much else on. I got bored and watched a South Park episode, and it happened to be the one all about World of Warcraft ("Make Love, Not Warcraft"). And I thought "that game does look pretty cool" (being the geek I am, I do remember the good old days playing RPG's for ridiculous amounts of time). So I thought I would check it out :) Blizzard offer a 10-day free trial (with restrictions) after a night of sitting there for hours playing drinking beer I managed to max those out, so my account is currently being upgraded from Trial to Full :) <geek>My little n00b Hunter kicks ass :) He's like level 21 now, I have a pet cat thing in my "stable" called Leo and currently training a pet wolf called Fido. I was training in tailoring and enchanting, but that was kinda pissing me off because it was taking so long to skill up on the enchanting. So I dropped both those (with tailoring at 150!) and re-skilled in leatherworking and skinning. They compliment each other quite well, levelling up much more quickly (too quickly TBH - I am starting to need to skin animals above my level) and making more money from selling my awesome leather goods :) Now, I know you can only find me on my server, but I forgot what that is, and apparantly I have no way of finding out from my account page (which is kinda silly) so I will update this post once I home to say where you can find me :) What ever server I am on, I am currently tearing it up in "Ashenvale Forest" with "Astranarr" being my current home.</geek> On a side note, WoW is where the famous "Leeroy" came about from (if you have never seen it, WATCH IT!). Leading to things such as this Lolcat :) Links: Share: 28/04/2008 Vista Speech Recognition Macros CTP ReleasedThis has been sat in my Inbox for a while as I have yet to play with it, but I thought I should at least do my bit to spread the word, this could be an exciting bit of technology depending on how well it works! Microsoft released the Community Technology Preview (CTP) for Windows Speech Recognition Macros Tool (WSR Macros) on 23/04 (or 04/23 for across the pond!). You can download the CTP from here. I really like the Speech Recognition feature of Vista, contrary to popular belief, it does seem to work well, and I have a cheap crappy headset. I know Scott Hanselman uses speech recognition (mentioned here in his post on his new home) and he reports fantastic detection rates. With macros to perform multiple functions on key words/phrases, the possibilities are endless! Awesome! Note: This is obviously only for Windows Vista! Links: Share: Windows Live FolderShare 14.0.1331.0415 Released - Changes!? Hell if I Know!So, when signing on to my machine at home over the weekend, and of course my work machine this morning. FolderShare automatically loads and I get a little box pop up telling me that it is unable to sign in because I am running an old version, which needs to be updated. So I figure "cool" I will update, I know normally these sorts of releases are security-critical, to stem people logging in when a known issue is located. I thought we'll soon find out once its installed. I go ahead and install the new version (14.0.1331.0415) and wait for the release notes to pop up.. Nothing happens.. "Hmm that's odd" so I begin clicking around to see if I can find a document, web site, anything. And nothing. Zip. Nada. So I Google "foldershare 14.0.1331.0415 "release notes"" and I have a single hit. One single hit, which takes me to a blog of some dude called Blake Handler, his blog looks interesting so I also added it to Google Reader, great. The post Google found had a link to the FolderShare team's blog, which, incidentally I never had on Google Reader, because I had never been told about it. And the development teams very own blog was almost as useful as a Google search with no real results. Not Much From the Horses Mouth... Do you think releasing a new version with no actual release notes is acceptable? Links: Share: 22/04/2008 Finally The Truth About "using" and Dispose()The ProblemDuring the good chat with some fellow students last night, the top of whether or not "using" should be used over an explicit Dispose() method call when using objects like Graphics came up. Now, this one has been bugging me for some time, and I have never actually sat down to investigate it, so I thought I should. I have been told on several occasions that I should use "using", but when questioning why, I get no real answer that makes any sense. Seems like a classic "every knows the best practice but doesn't understand the practice or why its best" scenario! So, I made some very small code samples, one using "using" the other using Dispose(). Here are the samples FYI: "using" Code1: private void Form1_Load(object sender, EventArgs e) 2: {3: using (Graphics g = Graphics.FromHwnd(this.Handle)) 4: {5: MessageBox.Show("this is between the graphics instantiation and disposal"); 6: } 7: }Dispose() Code1: private void Form1_Load(object sender, EventArgs e) 2: {3: Graphics g = Graphics.FromHwnd(this.Handle); 4: MessageBox.Show("this is between the graphics instantiation and disposal"); 5: g.Dispose(); 6: }As you can see, nothing fancy! And here are the results (intermediate language - "IL") courtesy of ILDASM: "using" IL1: .method private hidebysig instance void Form1_Load(object sender, 2: class [mscorlib]System.EventArgs e) cil managed 3: {4: // Code size 36 (0x24) 5: .maxstack 16: .locals init ([0] class [System.Drawing]System.Drawing.Graphics g) 7: IL_0000: ldarg.08: IL_0001: call instance native int [System.Windows.Forms]System.Windows.Forms.Control::get_Handle() 9: IL_0006: call class [System.Drawing]System.Drawing.Graphics [System.Drawing]System.Drawing.Graphics::FromHwnd(native int) 10: IL_000b: stloc.011: .try 12: {13: IL_000c: ldstr "this is between the graphics instantiation and dis" 14: + "posal" 15: IL_0011: call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string) 16: IL_0016: pop 17: IL_0017: leave.s IL_002318: } // end .try 19: finally 20: { 21: IL_0019: ldloc.0 22: IL_001a: brfalse.s IL_0022 23: IL_001c: ldloc.024: IL_001d: callvirt instance void [mscorlib]System.IDisposable::Dispose() 25: IL_0022: endfinally26: } // end handler 27: IL_0023: ret 28: } // end of method Form1::Form1_LoadDispose() IL1: .method private hidebysig instance void Form1_Load(object sender, 2: class [mscorlib]System.EventArgs e) cil managed 3: {4: // Code size 30 (0x1e) 5: .maxstack 16: .locals init ([0] class [System.Drawing]System.Drawing.Graphics g) 7: IL_0000: ldarg.08: IL_0001: call instance native int [System.Windows.Forms]System.Windows.Forms.Control::get_Handle() 9: IL_0006: call class [System.Drawing]System.Drawing.Graphics [System.Drawing]System.Drawing.Graphics::FromHwnd(native int) 10: IL_000b: stloc.011: IL_000c: ldstr "this is between the graphics instantiation and dis" 12: + "posal" 13: IL_0011: call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string) 14: IL_0016: pop 15: IL_0017: ldloc.016: IL_0018: callvirt instance void [System.Drawing]System.Drawing.Graphics::Dispose() 17: IL_001d: ret 18: } // end of method Form1::Form1_LoadConclusionSo, as you can see, the "using" method wraps the code inside the scope of the statement within a "try" block of a "try/finally", placing the Dispose() call in the finally, meaning it will always get executed even if an Exception is thrown. However, using the explicit Dispose() method, if an Exception is thrown, then it will not get disposed of, meaning it could be sat on the heap for a few milliseconds or even a few minutes, not good! I guess this is why MSDN refers to the "using" statement as the "convenient syntax for correct use of IDisposable objects".
Update: I have been told that VB.NET 2.0 does actually have a "using" statement as well, which looks surprisingly like the C# syntax! http://msdn.microsoft.com/en-us/library/htd05whh.aspx 13/04/2008 Vista Problem - Debugging "[Application] has stopped working"Well, it was bound to happen, and it finally has! I have found something I genuinely do not like in Vista. While working on some code while studying Code Access Security (CAS). CAS basically allows you/your admin to control what resources .NET code has access to when running. This can be Dialog boxes, the Registry, Printing, Windows Services, Data Access, whatever, it seems pretty complete. The idea behind the exercise that I was doing was to demo "Imperative" and "Declarative" CAS. "Imperative" checks the permissions before loading the assembly/code, "Declarative" checks the permissions at run-time. So, I create a simple application that will present a FileDialog box to the user prompting to select a file. Nothing flashy. The idea is that initially the application runs OK, I then configure the CLR to restrict access to FileDialog's for the application, then the application should throw an Exception saying "I can't do that". In XP, the code works exactly as expected, you get a nice dialog box with a big fat red "X" telling you there is a problem. However, in Vista, you do not. You get the ever-so-helpful "[Application] has stopped working" error message (shown to the right): This is not good, because this means that if an exception occurs outside of my development machine, the user has no information to report back to me! Now, if I click the "Debug" button, it takes me to Visual Studio and gives me the full exception details that I need to know in order to fix it. I am unsure as to what happens if there is no debugger available on the machine, so I thought I would dig around in the "Problem Reports and Solutions" centre. So I located the crash reports and checked the details: As you can see from the screen shot, not a lot of information is provided! So I thought I would check out the settings for "Problem Reports and Solutions", and looking around, all I can see is how to disable the automatic submission, nothing suggesting a way of getting back to the old error dialog in XP. Is was ugly, but informative! Even disabling the feature all together just creates a simple dialog asking to close or debug! Does anyone know if this is only occurring because I have Visual Studio installed? I cannot test what will happen without because I only have one Vista machine!
Share: 06/04/2008 Vista "Unidentified Network" Issue - Revisited! [TOTALLY RESOLVED NOW!]Well, I am not sure if you guys found my previous post on this, here's some [really] quick history. Brand new PC, Had for about three days, all working fine, one morning, no Internet, Vista Network and Sharing Centre is telling me I am on an "Unidentified Network". I troubleshoot as much as I can, to no avail. I contact the PC vendor, their tech support is also stumped. I send the PC So, yesterday my new PC arrives! I get it set up, everything is running great, I leave it on when I go to bed to allow the drive to defrag (since I had been putting lots of software on etc.). I wake up in the morning, come to my desk, wake the computer up and BAM! "Unidentified Network". I said something that sounded very much like "You gotta be hitting me", I couldn't believe it. This time was different though, I had a lead :) So, I get the name and model of my motherboard, its an "Asus P5N32 SLI". So I google "Asus P5N32" LAN Sleep Vista "Unidentified Network". To get some interesting results.. Looks like this motherboard does not like going to sleep. Tried resetting and going into safe mode, disabling the onboard LAN and re-enabling, all to no avail. I then came across this site - and I came across the best tech support ever - "just pull the plug out". So I did :) Plugged it back in, Vista told me off for not shutting down, back into my desktop, back on the Internet. Problem solved! I repeat: just pull the plug out, while the computer is switched on and running. DO NOT push the power button as it is likely to put the computer to sleep again. I will play with the settings to see if I can get the computer to sleep without destroying the onboard LAN, but in the mean time, I will be getting on to the vendor to get them to send me a NIC. I hope this helps you guys. Fun fun fun! Share: 05/04/2008 Visual Studio Code Snippets - Part 2 - Creating Code SnippetsFollowing on from my previous post on code snippets, here's instalment two! In this part, I want to guide you through creating your own basic code snippets, in part three, we will cover a few "advanced" features of code snippets. To avoid any confusion, I will demo everything in Visual Studio 2005 since 2008 has a few features that may take us away from what we are doing here. Creating a Code SnippetSnippets are basically just XML files that contain some code and metadata. As covered in the introductory post, the code is inserted when you type the shortcut into Visual Studio. The XML files are then stored in "My Code Snippets" (or another folder of your choosing) for use by the IDE. There are a number of ways to create these XML files, and I will talk you through a couple of them. Good Ol' Fashioned Text Editor Obviously, XML is plain text and can be edited in Notepad, Notepad2 (or your text editor of choosing). I like to use Notepad2 for my basic text editing, and here is a screen shot of my "ToDo" code snippet within Notepad2: As you can see, it looks pretty straightforward. I strongly recommend that if you are going to create code snippets in this way, then you copy and paste and existing one and edit that. This makes sure you don't miss any details, and its obvious "what does what". This is especially useful if you are new to code snippets. Snippy While using a text editor is fine, I find that when you are creating a lot of these, or trying to maintain them, then you start to get fed up with it. So I began searching the Internet for a code snippet editor. A Google returns a lot of results and I tried several until I found Snippy. Snippy is a lightweight, simple tool (now found on CodePlex). The screen shot to the right is the same "ToDo" code snippet in Snippy: So, I found Snippy and stuck with it, I didn't want anything fancy, just something to make my life easier, so lets go through creating a code snippet in Snippy! WalkthroughNOTE: In the following scenario, I know I could use generic events etc. but I have opted for the explicit declarations so the code is clear to anyone unfamiliar with generics. OK, let's outline the scenario: I don't know about you, but I create utility methods to raise my Events, since you need to check that the Event is not null, as well as possibly allowing the Event to be raised by subclasses of a superclass, such as the following: 1: public delegate void MyEventHandler(); 2: public event MyEventHandler MyEvent; 3: 4: // event can only be raised by this class. 5: void RaiseMyEvent() 6: {7: if (MyEvent != null) 8: { 9: MyEvent(); 10: } 11: } 12: 13: void Foo() 14: {15: // ... some stuff 16: RaiseMyEvent(); 17: } 18: 19: public delegate void MyEventHandler2(EventArgs e); 20: public event MyEventHandler2 MyEvent2; 21: 22: // this event can be raised by this class, and subclasses. 23: protected void RaiseMyEvent2(EventArgs e) 24: {25: if (MyEvent2 != null) 26: { 27: MyEvent2(e); 28: } 29: } 30: 31: void Bar() 32: {33: // some other stuff... 34: RaiseMyEvent2(new EventArgs()); 35: }So as you can see, the code is pretty simplistic, and repetitive. This is an ideal example of when a code snippet would be useful. Creating the Code Snippet in SnippySo, lets make this into a code snippet! Fire up Snippy and you will be presented with a blank form. Enter the following info into the fields provided. These fields are pretty self-explanatory, but "Shortcut" deserves a special mention, this is the shortcut that you type in Visual Studio, so keep it short and understandable: Title: RaiseEvent Wrapper Ignore the "namespaces" section, this doesn't seem to do anything (yet). Literals and ObjectsThe next section is the "Literals & Objects" section. So "what are these?" you ask. Well, in a code snippet you have replaceable values that you can tab through, as described in Part 1. Literals & Objects are these replaceable values, but they are each intended for different meanings. Literals are should be things like text and values that exist within the code snippet and may be used after. So things like variable names, connection string etc. should be defined as Literals. Objects are elements that are normally defined outside of the code snippet, such as Forms, controls. Object references require that the type is specified. NOTE: Snippy makes no differentiation between Literals and Objects and treats them equally (i.e. no type specification. I have suffered no negative side-effects of just defining everything as "Literal" although of I have yet to investigate this to see the difference between the two (added to ToDo!). I often find that it is easier to complete this section after writing the code, so lets go ahead and put the code in first. The CodePaste in the following base code taken from the above sample into the big text box in the "Code" section: 1: protected void RaiseMyEvent2(EventArgs e) 2: {3: if (MyEvent2 != null) 4: { 5: MyEvent2(e); 6: } 7: }OK, first off, we need to identify what elements of the code are going to change when we use it, from the RaiseEvent code, we will need to change:
So, we essentially need two pieces of information, the event name, and the EventArgs type. It would also be useful if the "EventArgs" type defaulted to "EventArgs" since all classes should derive from this. So we know what we need to replace, so before we need to set the placeholders within the code that will later be replaced by the customised values. You do this by adding an ID to the code, surrounded in dollar symbols ($). As with code, name your values appropriately. We will call our placeholder ID's "$name$" and "$argstype$". Edit the code in the "Code" TextBox to: 1: protected void Raise$name$($argstype$ e) 2: {3: if ($name$ != null) 4: { 5: $name$(e); 6: } 7: }As you can see, its pretty straightforward what is going on here, the placeholders defined will be replaced with the values we enter when using the code snippet in the IDE. Once the code has been entered, change the "Language" drop down list to whatever language the code is in. This is important because Visual Studio will only allow you to use C# code snippets in C# source, C++ snippets in C++ source and so on. Now we need to go back to our Literals and Objects and define the Literals that we are going to be replacing. Literals RevisitedClick the "Add" button to add a Literal, we will start with the Event Name. Enter the following into the fields provided and click "OK": ID: name This tells the code snippet (or the IDE) that when creating the code snippet, any elements in the code block defined as "$name" will be replaced by what we enter. In Visual Studio, the text entered for ToolTip will be displayed, and it will default to "EventName". The "Editable" flag indicates that we want to be able to tab through it and change it. That said, lets go ahead and define the Literal for the "argstype" element. ID: argstype OK, that's it! We are done, lets go ahead and save the snippet! Saving the SnippetClick File > Save As. Then navigate to where you want to save the code snippets, I recommend you save them in My Documents > Visual Studio 2005 (or 2008) > Code Snippets > [Language] > My Code Snippets. As this folder is automatically monitored by the IDE for code snippets. Lets go ahead and name the file "RaiseEvent Wrapper Method". Once saved, we can close Snippy and return to the Visual Studio IDE. Using the SnippetSimply go to the point in the code where you want to insert the code snippet and enter the shortcut and press TAB twice, in this example, the shortcut was "re", and here are the results: Excellent! As you can see, we can then type over the "EventName" with our own event name, and TAB to and replace the EventArgs type definition (if required). This is an excellent example of not only boosting productivity for mundane code, but also enforcing naming conventions by using and adhering to templates. Points to Note:
SummarySo in this post we:
In the next instalments of this series, we will look at some more advanced code snippets such as using functions and creating larger code blocks. I hope you found this post useful and as always, if you have any questions/comments, then please feel free to comment below!
Share: Facebook 01/04/2008 Visual Studio Code Snippets - Part 1 - Using Code SnippetsI recently read this blog post from Peter Lanoie, a great guy who I met through p2p.wrox.com about Visual Studio code snippets, it really got me thinking that I should post my own experiences to try and get more people into using them, and perhaps sharing their own snippets. A Code What?Not sure what a code snippet is? Well, a code snippet is simply some code that can be inserted into Visual Studio by typing a shortcut. These are designed to be time savers, as well as provide the added benefits of consistency of coding standards and style. For example, lets take the most common, as mentioned in Peter's post, the property. Whenever we write classes we need to define fields and properties to enable the outside world (code?) to access it. We can literally do hundreds of these over the course of a project. So it quickly becomes very annoying creating them. Situations like this are the ideal scenarios where a code snippet can save A LOT of time. OK, Sounds Good, How Do I Use It?Inserting a code snippet is easy, thanks to Intellisense. As I said before, each code snippet can be assigned a shortcut, you simply type in this shortcut into your code, and Intellisense will pop up and let you know that you can insert a snippet, see the image, here I am inserting the 'prop' (Property) code snippet: Now, you are probably asking, "fine, I see the 'prop' and the nice Intellisense description, but where's my code?!" Good question, once the item code snippet is highlighted in Intellisense, you simply press TAB twice to insert it, you then get the following: But I Don't Want an 'int' and I Don't Want It Called "MyProperty"!That's fine, they are just the defaults! As you may have noticed, the 'int' and 'MyProperty' are highlighted, this means that you can TAB through them and replace their text. In my example, I want a string called 'Name', so I:
IMPORTANT NOTE: I am using Visual Studio 2008 for this, which has automatic properties (which is what Peter's post was discussing), note, then you are using 2005, you also have the ability to tab over the private field declaration, as shown below: Notice when you change the private field declaration, the values in the getter/setter change? Neat! These are a powerful part in your arsenal of weapons to help make you a more productive developer/programmer. Use Them! One this I am always conscious of is "how long do I spend doing this, is this too long? Can I speed it up?". If you find you are writing the same/similar blocks of code more than once/twice a day, it may well be an excellent candidate for a snippet. For example consider these scenarios:
Think about the common code that you type daily and whether or not it may be worth "snipping" it. Remember, they are freely definable, in part two, I will go over how to create them! Share: Facebook 31/03/2008 Adding Social Bookmarks to Posts Using "Dynamic Template" PluginFollowing on from my previous post on trying to get myself organised and utilising social networking/bookmarking more, I figured I should try and help myself a little and be adding social bookmark links on my blog posts. Sounds easy huh? Well, it's not really the case. I use Windows Live Writer to write my blog posts, its a great tool and I'm well happy the Live Writer Team have created it for us (thanks guys!). Developers are able to create plugins for it, which open up many, many possibilities! So I thought I would check out what plugins could help me out in the Live Writer Gallery. I found two possible candidates: 1. Digg This Plugin for Live Writer by Leo Vildosola (http://tinyurl.com/3x92b6) 2. Social Bookmarking Tags by Rahul Soni (http://tinyurl.com/3cf6xr) The OutcomeSo what did I go with? Neither. Why? I'll explain... Digg This Plugin Social Bookmarking Tags The ResultSo I engaged my grey matter to think about what I could do. I know all of these sites just take the URL and pass it to a script for processing, which then adds it to their cloud. So, all I need is some HTML right with my post address and some images to sexy it up right? That's not hard in itself, the hard bit is entering it quickly onto each blog post. Enter "Dynamic Template" Plugin from Joe Cheng (http://tinyurl.com/24bzp3) I've had this plug in for a while now, it's freaking awesome. It allows you to put ASP-esque C# code to create a template for output. The really cool thing is that you can also make it prompt for input. Sounds like just the tool! So here's what I did (or you would need to do):
You can see the result for yourself at the bottom of this post! Be aware, that the address of your post is not available until after you have posted, so you need to do the following :
These instructions are based on using the template I have created, if you would like to download this template file, it's available on my Live SkyDrive here (http://tinyurl.com/37fpdw). NOTE: I have used the images that Rahul Soni's plugin links to, based on the assumption that if he is happy for users to anonymously download his plugin and use them, you are able to do the same. If he is not happy with this, I will remove them from my template and politely request that you do the same. I would like to say a special thanks to Leo, Rahul and Joe for their efforts in making all this stuff possible :) 30/03/2008 Now Digging, Feeding my Friends and a Facebook App Worth Installing!OK, just a quick update that serves two purposes:
OK, in an effort to try and organise myself a bit better online, I have finally signed up to the two following services/sites: digg (http://www.digg.com) Digg also serves as a great hub for finding new content. FriendFeed (http://friendfeed.com) Special thanks to Loic Le Meur for inspiring me to do it via his blog post!
|
|
|