Sloppy Code, Band-Aid Code, and Quality Code

In my short happy life as a programmer I've noticed that most code seems to fall into the above three buckets.

The biggest offenders in the Sloppy Code camp usually come from the VB.NET camp, simply because the language has become so distorted from efforts by Microsoft at giving it new life instead of a decent burial that they've perpetuated gobs of crutch and helper methods, most of which live in the non-CLS-Compliant Microsoft.VisualBasic namespace. (I see where in VS.NET 2005, this is actually marked as CLS-Compliant for the first time, but I'll need to see proof before I believe it).

In order to do the things that .NET needed, Microsoft decided that they had to "break compatibility" with previous VB versions. VB programs had been mostly "upward compatible" from VB1 right up to VB6. A program written in the first version of VB would still compile and run in the next version. But with VB.NET, they found they just couldn't make the language completely OOP and maintain this upward compatibily. So, once this fundamental decision was made, the floodgates opened, and now you have VB.NET, which has become a real mess, IMHO.

Variants are an example. They're gone. Probably no other single feature of Visual Basic being "Not.Net" better represents the philosophy of "easy and loose". I remember my first introduction to VB 3.0: "Well, Mama, Lookee here! With this here Variant data type, we don't have to declare no variables or nothin'! We can just think 'em up and code at 'em! Whoopee!"

Of course, now you have crutch code that attempts to do the same thing with the Object datatype with LateBinding.This and Information.That, etc.

But the biggest offense with Sloppy Code (both in VB.NET and C#) is the failure to put in any exception - handling. I know - we get post after post to the eggheadcafe.com messageboards with people asking "what went wrong", or even "There's a BUG in...". Look for a try - catch block in their code sample -- it ain't there.

Band-Aid Code is a little more sophisticated. It's the attempt to "Fix" what shouldn't have been done wrong in the first place. I have seen entire corporate operations literally CONSUMED with the maintenance of "Band-Aid Code"! Sad, but true.


Finally, we've got Quality Code.

Quality code is carefully written, it's Object Oriented, it uses interfaces, structured exception handling, its easy to read, and its maintainable. To write quality code, you have to study. You have to RTFM and know where the F1 key is. And -- (gasp!) --you have to think. Viva la Quality Code!

Comments

  1. Anonymous8:01 AM

    It is true that there are a lot of VB coders that produce sloppy code. However, starting every source file with Option Strict On / Option Explicit On seperates the men from the boys. Once you do that, you have about as much possiblity to write sloppy code in C# as you have in VB.NET.
    There are people who code in VB.NET just because their mind is not compatible with curly braces, for them, the choice between VB.NET and C# is only a syntactical one ...

    ReplyDelete
  2. Anonymous8:44 AM

    I would also say one key aspect of quality code is test coverage. If you have no test coverage you have no quality. If you have tests you can easily change your code (refactor) and know if you've broken anything or not.

    ReplyDelete
  3. Regarding Option Strict, etc. I agree and covered that extensively in another post.

    Jason, based on my knowledge of your credentials, I'd say that you're well ahead of me on the quality code issue. Test coverage, agreed, is a key aspect. But- we gotta learn how to handle exceptions first!

    ReplyDelete
  4. Anonymous12:32 PM

    Wow. This made me really step back and examine my coding. I didn't learn programming in recent years, so OOP has been something I've learned on my own and having worked mainly as a lone programmer, I haven't benefitted a lot from mentors, etc. I think my code is a lot better than it used to be, but could improve a lot. I don't use a lot of interfaces, although I use interfaces in a couple of cases and it works well. I've also read alot of posts and heard mention of design patterns. How would you recommend I go about learning more about these things so that I can write more and more quality code? Thanks for the blog.

    Chad

    ReplyDelete

Post a Comment

Popular posts from this blog

Some observations on Script Callbacks, "AJAX", "ATLAS" "AHAB" and where it's all going.

IE7 - Vista: "Internet Explorer has stopped Working"

FIREFOX / IE Word-Wrap, Word-Break, TABLES FIX