Wednesday, November 04, 2009

CodeRush Scenarios

This is a simple post to point out some scenarios in which a tool like CodeRush can be invaluable.


Bashing out a quick algorithm.

I have no fear. I can hack out a working solution pretty quickly when I’m called upon to do so, but when done this way, it’s typically not very pretty. However, with a few keystrokes I can extract component parts of my ‘rough and ready’ algorithm to other methods, allowing me to sensibly reuse code which I might otherwise have copied and pasted and then had to maintain independently.

Tidy that Code.

The code I wrote last year is ugly. Hell, the code I wrote last week is ugly, when compared with what I wrote yesterday or today. All code can stand to be improved, but it’s rare that you want to go back and actually improve it because that code you wrote yesterday, is yesterday’s news. You don’t want to have to reconsider your old code because its time consuming and boring. Well some simple Refactorings, like ‘Rename’, ‘Extract Local’ and ‘Inline Temp’, really do help speed the process to the point where you can feel your code quality rising by the second, which can really enthuse you to do more.

Spreken zie code?

Ok… I don’t really speak any foreign languages but I do know what it’s like to have to interpret a foreign codebase. It’s hard. you rarely have the ear of someone whose uses the code, much less the moron who created it in the first place. With CodeRush, I can glide around the codebase renaming types, methods and variables as I see fit… Morphing the codebase ever closer to that illusive “Readable code”. I can do this completely safe in the knowledge that I am not altering the way the code works, just the way it reads.

Efficient Code Review.

Code-Reviews can take up a lot of time. The important part, is not tidying up the code, but imparting knowledge of why the suggestions are real improvements. You want to spend as much of your time “teaching the man to fish” rather than “throwing fish in the his general direction hoping he’ll catch one”. After all… if you “teach a man to code *well*” you wont have to “code well for him”. CodeRush helps you spend less of your time improving or correcting the code being reviewed, so that you can spend more of your time either explaining why the improvements are so good or simply get on with improving more code. Also, using CodeRush (even the Xpress version) has an added benefit that in addition to demonstrating good code, you are demonstrating the use of good coding tools.



API-By-Example (also known as consume-first development) is a process where in you call a non-existent method… in a way you imagine that you would like to be able to call it… passing parameters in a way you see as sensible to do … and using any return value it produced in a way you see as reasonable… all without ever having actually coded the signature, or indeed any of the implementation, of the method in question. It’s like a big ol’ game of ‘Let’s pretend’. except that when you’re finished doing all of that, you get to hit a single key and generate this method’s signature exactly according to it’s usage.

You have just designed your first API-By-Example. Once generated, the method’s own signature can be used a partial spec against which a implementation can be built, safe in the knowledge that the call already makes sense in situĂ©.

This sort of technique is great for creating library or framework code because you first define how you'd like to use it and then move on from there to the implementation. You arrive at a library which is much more usable because it was designed with it's usage in mind from the outset.

The CodeRush SmartTag
The CodeRush SmartTag contains both Refactorings and CodeProviders specific to the context in which you find yourself.

My personal favourites are:

  • Refactorings
    • Rename
    • Extract Local
    • Extract Method
    • Extract Property
    • Inline Temp
  • Code Providers
    • Declare Local
    • Declare Method (With parameters all in place based on your usage.)
    • Declare Property
    • Declare Field With Initializer

..but there are many more. :)

Which ones do you use most and in what situations ?

For more details on CodeRush and other DevExpress products, check out their Facebook page

1 comment:

Gerhard Weiss said...

Nice posting Rory!

I will have to check out the API-By-Example and SmartTag.

I never knew it would be this nice to get smacked in the face with a fish.

Keep the fish and the Blog post flying!

Auf Wiedersehen ;)