Archive for July, 2007

CodeRush features that I’ve been spoiled by: String.Format and Introduce Local

Ok, some of the features may not be CodeRush; they may be Refactor! Pro instead. Since I have both installed, I never know which one is which… anyway, whoever buys CodeRush should definitely go with Refactor! Pro as well.  🙂

String.Format

This is refactoring that you can use to replace pieces of a string with variables. For instance, say I have the following string:

And I want to replace the text highlighted with variables, I can select the first part ("Claudio"), and then hover over the selection. CodeRush then shows me a smart tag, and if I hover over the smart tag, I get the following:

Notice that it shows a preview of how it is going to change my code, in case actually click on the "Introduce Format Item" option. Next, I can select the word "Houston", and do the same as I just did above:

So the code after the refactoring look like this:

As you may have noticed, "Introduce Format Item" is the only option available on the smart tag under that context. As a shortcut, instead of hovering over the selected text, wait for the smart tag to show up, click on it, and click on the option, you could also just select the text, and press Ctrl+~; that action performs the refactoring automatically. And you can keep selecting text within the string and hitting the shortcut, and CodeRush will keep adding variables to the String.Format call. Ain’t that pretty cool?

In case you want to do the opposite (take the variable and put it inline within the formatted text), just select the variable (for instance, the "Claudio" one), and select "Inline Format Item":

And this is the final result of that refactoring (notice that when it was done creating the variable, I typed "myName" to rename the variable to something more appropriate, and CodeRush fixed both the name of the variable and the place where it was being used):

By the way, the graphic elements on the snapshots (such as the arrows and the strike-through) were rendered in Visual Studio by CodeRush; I didn’t add that in any image editor. 

Introduce Local

Expanding on the previous topic, we may want to replace the variables on the String.Format call by actual local variables.

Same deal here: select the string that you want to store to a local variable, press Ctrl+~ (or hover over the selection to get the smart tag), and select "Introduce Local". That does the job of creating a local variable for you and assigning the value to it.

That’s it for now. There’s more to come in the next few days.

Leave a comment

Trying to keep the sanity…

Just in case you don’t know, I keep another blog out there just to post about things that are not related to my life as a software developer. Here’s a link to that blog:

I just posted something related to my band, just in case you’re into music you might want to check it out.  🙂

I promise the next post on this blog is going to be technical.  😉

Leave a comment

CodeSnippets, CodeRush, ReSharper…

Let’s continue the series on productivity…

My main motivation for using the tools and tips that I’ve shared on the series is so that I can have less interruption when I’m trying to write code and implement something. The idea being that when I’m writing code I want to have the least friction between me and my task possible. This line of thinking also applies to writing code.

VS 2005 Code Snippets

VS 2005 brought to the table a feature called VS 2005 Code Snippets. Code Snippets are just what the name implies: snippets of code that you can use. For instance, in order to create a class, instead of typing the full class definition, one could just type class and hit the spacebar, and the main skeleton of a new class gets created automatically. Or in order to create a property and the field that goes along with it, one could just type prop and hit the spacebar.

These are just a few examples: there’s a lot more that comes with VS 2005, and you can also search on the web for other code snippets that other developer have put out there.

I can’t really say a lot about Code Snippets because I don’t use them. Instead, I use a tool called CodeRush, which I’m going to talk about next. I’ve decided to stick with CodeRush for two main reasons: one is because CodeRush was available even going back to VS 2002, so I was using it way before Code Snippets showed up with VS 2005. The other reason is that, as far as I’m concerned, CodeRush is way better than Code Snippets.

DevExpress’ CodeRush

If you have never seen CodeRush before, I suggest you check out the product’s Training Videos (try out the ones on Navigation, Cool Templates, and Refactoring). Those videos can show the product in a much better way that I can explain it hear.

If you’re already used to VS 2005 Code Snippets, all I can say is that, as far as I’ve seen, CodeRush is waaaaaaaay superior to that.

I’ve been using this product for about 3 years or so now. When I first started, like most people, I thought it was getting in my way. The main reason for that is because CodeRush tries to predict what your next action is, and it takes the action for you. For instance, if you type if and hit the spacebar, CodeRush will open and close parentheses for you. Until you get used to that, you end up having double parentheses: the one CodeRush puts in for you, and the one that you manually type in.

After I got used to that kind of thing, oh boy, it is really hard to work on a computer that doesn’t have CodeRush installed; one has to type a LOT more code. I sure prefer typing less code and focus more on the task I’m trying to accomplish.

I also like the fact that CodeRush helps me I’m constantly switching between C# and VB code. For instance, in order to create a method that returns a DataSet, all I need to type is mds (as in method dataset); this will cause a template to expand in the appropriate way, both in C# and in VB. That means that I don’t have to worry about the C# curly braces, or the VB verbosity.

I also like how easy it is to create your own templates (there’s a training video about this on their site). The last I’ve seen about VS Code Snippets, one has to deal with some nasty XML to create custom templates (maybe somebody created a visual IDE for it by this time, but there doesn’t seem to be anything in VS for that). To make the life of the developers who use our Milos framework easier, I’ve created a bunch of CodeRush Templates that expand to code that we use a lot but can’t really always remember exactly how to write it. You can checkout what kinds of templates we’ve create here.

Well, again, there’s a lot to be said about this tool. If you aren’t using anything like that, I suggest you give it a shot; download the trial version and watch the training videos so that you can see what you can do with it.

Since there’s a lot of features I like about it, I’ll just be posting a few of those that I really use all the time. Stay tuned.

ReSharper

ReSharper is another tool very popular out there. Unfortunately, I can’t say a lot about it, because I haven’t used it myself. I’ve seen people using it, and it seems like it’s another very good product.

I’ve heard of people using both CodeRush and ReSharper, combining the unique features of both tools to boost up even more the productivity. What I heard is that it takes a while to set that up, since we end up with Visual Studio, CodeRush, and ReSharper, fighting over shortcuts and stuff like that, but it can be done. Maybe I’ll try that at some point.

Conclusion

It doesn’t matter whether you’re using VS Code Snippets, CodeRush, ReSharper, or whatever other tool available out there; make sure you use something!!! Writing code in VS without using some tool like that feels like writing code in NotePad; and that’s nasty!!!

Bottom line is, when you’re writing code, stop for a moment and think whether you’re being as productive as you can when doing so.

Leave a comment

C#3.0 WebCast for the VBUG – Material

Just finished the presentation. It went pretty well, I think (or so was I told).  🙂

The slide deck and source code can be download here.

And for those of you waiting on my next posts on productivity, it is coming! I started writing my next post, but haven’t finished yet. I should have it out on the next few days.

Leave a comment

WebCast for the VBUG

Next week, on July 10th, I’ll be presenting another webcast for the VBUG. This time around it’s going to be about the New Features in C# 3.0. Here’s the session’s description:

There are a great number of new features coming with C# 3.0, such as Object Initializers, Anonymous Types, Type Inference, Extension Methods, &Lambda Expressions. This session introduces – What the main new features in C# 3.0 are, how the new features can improve & empower the code you write & the relationship between the new features & LINQ.

This is a free webcast, so I’m hoping to "see" you there.  🙂

2 Comments

Houston TechFest

Houston TechFest has been announced (well, it’s been a few weeks now, actually…). It’s going to happen on August 25th, at the main campus of the University of Houston. 

I’m going to present three sessions:

  • Object Oriented Programming in .NET
  • Design Patterns in .NET
  • Tips & Tricks to Improve Productivity

I think this event is going to be pretty cool, and am definitely looking forward to it.

Leave a comment