Geeks With Blogs
Bill Jones Jr. MVP Visual Basic Charlotte NC - MCP C# and VB.Net - Founder and President of the Enterprise Developers Guild (.Net User Group)

CodeSmith 3.0: Are you a CodeSmith fan?  When you move up to version 3 Release Candidate 1, be aware that Eric “cleaned up” the GetCamelCaseName function name by changing it to CodeSmith.BaseTemplates.StringUtility.ToCamelCase().  By the way, v3 is nifty even if Eric did temporarily lose sight of the fact that “consistency is its own reward”.  Good work Eric!


Consistency is its own reward: This fact cannot be overstressed at the project level and has real benefits at the shop level.  Here are a few of the big ones.  Pick a naming convention and stick with it.  This works for code and stored procedures.  It makes it easier for you and others to read your code. 


Consistency also works for data access and error handling.  Again, pick a solution that works and stick with it.  If you find something better, wait until the next project unless you are willing to go back and change all the existing code in the current project to use your “new and improved” technique. 


Does this advice fly in the face of the refactoring mania?  Yeah, but what’s your point?  Refactoring is often just rewriting running code on a developer’s whim.  If your code works, can be understood by your target staff and can be maintained, why should you refactor?  If not, then you’re still developing.  If you define refactoring as fixing your code so it can be reviewed, OK.  Otherwise, we all have way too much to do to ask somebody to pay us for making our code “better” just because we like to code.  Rewriting code that is “plenty good enough” sure hurts our productivity.


What is elegant code? Once upon a time, Jack Blanton, a treasured friend, sent me a ten or twelve line routine to refactor.  His email explained that he knew it could be done in less lines of code and he wanted to see what “the master coder” could do with it.  Picking up the gauntlet, I sent back a one line routine.  Was it elegant?  No.  I also included a more elegant three line routine that a real programmer could take in at a glance.  Since Jack was only two cubes away, I got the satisfaction of hearing his laughter when he opened the return email.


What’s the point? Elegant code is a simple, neat, “ah ha”, solution to a specific problem.  It is not a complicated hack that a real programmer could never understand.  Many, but not all, of the GoF patterns can be called elegant.  Sometimes the required solution prevents elegance, but that does not reduce our quest for concise, readable code.

Posted on Sunday, May 15, 2005 10:27 PM 2. Code Practice | Back to top

Comments on this post: CodeSmith, Consistency and Elegance

# re: CodeSmith, Consistency and Elegance
Requesting Gravatar...
There is much to be learned from consistency:
"Consistency is contrary to nature, contrary to life. The only completely consistent people are the dead." -- Aldous Huxley

Left by Peter Bromberg on Jun 12, 2005 7:42 PM

Your comment:
 (will show your gravatar)

Copyright © Bill Jones Jr. | Powered by: