Coding style

In production code, or code that might be delivered to a customer I try and adopt an enlightened pro developer style of coding. I.e. I only do stuff that I think adds value.

In personal project coding I have several alternate styles. By habit I normally code in the style of Father Ted (sub style – Father Jack Hackett). Which dictates the first procedure is called ‘feck’ and the second is called ‘Arse’ (by LAW!). The traditional ‘Hello World’ becomes (somewhat obviously) ‘Feck Off’. Yes/No dialogs become ‘Ah go on, go on now’

My most recent project (indexing the codematic site) I coded in the style of Bodie and Namond (inspired by his explanation of the game of chess) from the Wire. So the first routine is ‘FindDemBitches’ quickly followed by ‘DeleteDemMuthas’. Which contained the immortal line

Dim DatLiddleBitch as Range

What coding styles so you use? And do you do an edit replace as soon as that ‘personal code’ finds its way into production? Or perhaps before??

(I remember one time a user contacting my to ask why they had just had a error message that said ‘Guess again, donkey’.)




22 Responses to “Coding style”

  1. alastair harris Says:

    I tend to go with whatever I was watching with the kids on nickleodian the night before – which means spongebob figures quite often – although I did go through a Dirty Harry phase

  2. Will Riley Says:

    There’s a small UK bank that still has


    in one of their SWAP data entry upload files

    and a rogue clippy on the Finance Director’s Word install that is forever saying

    “Ah, it looks like you’re typing your resignation, do you need help with that?”

    Never quite did get around to replacing those before I left ;-)

  3. Adam Vero Says:

    “So, did I loop 6 times or only 5?”

    do while “punk”=”feels lucky”

  4. Harlan Grove Says:

    Almost every VBA procedure I post to newsgroups is named foo, and when I need a second it’s named bar. And as anyone who’s seen my code can attest, I’m an ardent advocate of conservation of keystrokes when it comes to variable names.

  5. Jon Peltier Says:

    I might be amused by variable names like that, but in three months when I revisit the code, I’m sure to be confused. Descriptive variable names are for the programmer, not the client.

  6. Harlan Grove Says:

    Desriptive variable names are one thing, but too often I’ve seen object references assigned to variables where the variable name was the object reference with the periods removed.

    An example of my style: ur always means used range. Unless I’m using used ranges from multiple worksheets simultaneously, I see no reason to qualify it further. Same for sr meaning selected range. As for For loop counters, I see no reason to depart from using i, j, k, etc. If it was good enough for FORTRAN in the 1950s, it’s good enough today! Seriously, I actually find a(i, j) more readable than a(iRowCounter, iColCounter) [or the excruciating iColumnCounter].

    Most of my udfs involve serious numerical programming or regular expression manipulations, and my comments usually reference pages in textbooks. Those texts usually use single letter array and index tokens, and I just follow the text.

    I do tend to be a bit wordier with subs, but not by much.

  7. Jim Cone Says:

    Something to consider is the possibility that ones’ sub/function/udf name could duplicate the name in use by some other piece of code.
    I learned the hard way that “SortSheets” is not a really good name to use.

  8. Jon Peltier Says:

    Harlan –

    That’s perfectly acceptable. If my sub only references one chart or onw range, I use cht and rng. For most looping I use i, j, k for loop counters (yeah, I remember fortran too). And for demos, sna(), foo(), and bar() are as good as anything else.

    But descriptives like rngRawData, rngChartData, or rngCalcOutput are very useful without being excruciatingly verbose.

  9. Simon Says:

    Alistair – spongebob is a great idea, I have used ‘you are a gooby goober’ in a messagebox, but not thought of doing a fully themed project – next time.
    Will – subverting clippy is exactly the right thing to do.
    Jon – like I said not in production code.
    Harlan – I use short names for loop counters too
    Jim – good point, and further evidence that ‘IndexThatBitch’ is a good name as it’s unlikely to clash with other loaded code (unless Alistair was watching the wire whilst coding his index system)

  10. Jon Peltier Says:

    @Simon: “like I said not in production code.”

    I don’t see the point in changing my coding habits just because I’m writing something for internal use. A huge amount of “production” code, that is, client work and especially commercial add-ins, started as work done for my own use.

    By using the same style for my own code as for production code, I don’t need to write any code twice, to make sure I don’t offend anyone or to make sure that shortcuts I may have taken won’t backfire.

  11. Steve Says:

    Saw this in one of the first access databases that i opened at a large bank

    On Error GoTo WTFH

    i.e. What the f… happened, lol

    + all the usual VBA cowboy stuff, Global variables etc etc etc

    Never actually met the guy, just changed all WTFH in the code and recomplied

    I my experience 90% + of VBA coders are cowboys
    Its the main reason why C# is my main code direction these days
    Just tired really
    You know, you get a contract, sit down, sort it out and all around you are
    a bunch of cowboys

  12. Simon Says:

    yehaw Steve!

  13. Steve Says:


    fast forward 3 years…

    In my experience 90% + of C# coders are just cowboys
    Its the main reason why ?? is my main code direction these days


  14. Steve Says:

    Hi Simon


    cheers man

  15. Simon Says:

    ha ha!
    don’t tell me C++?
    you know it makes sense, its too hard for all the numpties.
    ITs not lisp is it?
    c’mon Steve tell us what it is, email me if you don’t want to start a stampede

  16. Steve Says:

    no, I will just keep you hanging…


    actually C# all the way baby
    the thing is u have to pick one and stick to it
    otherwise you never get to know it in depth

    for me:
    1. SQL (various flavours) cause i work with databases

    2. VBA (no VBScript, VB6, VB.NET) just pure VBA, stopped all other flavours
    of VBx, just VBA and only for tactical solutions

    3. C# for all the important stuff

  17. Steve Says:

    by the way…

    all code i do these days in VBA is class based
    the upfront set up time is greater but man does it make a BIG difference towards the end of a large build when deadlines are looming

    except for the rare occasions of module based public functions for xl spreadsheet UDFs and access queries UDFs

    after all a module in VBx is just like a static class in C#



  18. Simon Says:

    behave, no ons uses classes in VBA they are crap.

  19. Steve Says:

    yes, of course
    its not a proper class based system
    but then again VBA is half baked for just about everything
    what i find tho is that it does satisfy one of the main points of classes
    just makes coding easier, all i have to worry about is the entry points
    to the class and everything else is contained within the class
    it also makes the calling code much clearer
    (i am talking about projects with 2+ thousand lines of code)

    on a side note

    I have been using .NET Reflector (Red Gate) a lot recently
    Take Reflector and have a peek at the .NET framework like System…etc
    Open sourced :)

    Now take Reflector and point it at itself Reflector.exe, the source has been obfuscated with dotfuscator available in visual studio

    The irony – i love it.


  20. Simon Says:

    If you got rid of all those
    dim x as myCrappyVBAToyClass

    set x = new myCrappyVBAToyClass

    set x= nothing

    and replaced with Usefulmodule.usefulMethod(…)
    your 2k+ projects would probably only be a couple of hundred lines.

    Do you charge by the line? ;-)
    I see a lot of VS devs using classes in VBA, but they are so weak compared to C# personally I don’t bother. I switch off OO mentality and switch on functional/procedural mentality for VBA.
    Are you using vs2010? C# 4.0?
    I may go back to C# then as the Office story starts to make more sense.

  21. Steve Says:

    VS 2010 Beta 2, C# 4.0, Framework 4.0
    and VSTOooooooooooooooooooooooooo
    Its a lot better now
    The idea is to leverage my knowledge of the office object models
    so office VBA -> VSTO

    I won’t stop using classes in VBA

  22. Steve Says:


    is it still called VSTO?? who cares
    MS seems to rename it with every release

    the key point is that VSTO is now part of VS 2010 Pro
    No longer isolated like 2005 SE and all that crap

    These will result in better uptake (and a better market) for devs


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: