Hungarian Notation for ColdFusionMX

Loose typing of ColdFusion variables is arguably one of the key factors that contribute to rapid application development.

However, the lack of any standard in which variables are named causes considerable grief, especially when working on large-ish ColdFusion application, in a medium to moderate sized team, over a period of time. Different developers start using different “conventions” for variable names and those “conventions” become more like fashions that come and go with each season.

And of course this is bad because it adds to the total time spent on maintaining legacy code.

Over a period of time, after trying various ways of naming variables (or using Hungarian Notation), I settled on using following.

Prefix Data Type Example
a array aItems
b boolean bValue
c single char cVar
i int iNumber
f float fNumber
l list lItems
o object oComponent
q query qGetRecords
s string sName
st struct stItems
u UUID uObject
w wddx wPacket
x xml xPacket

5 thoughts on “Hungarian Notation for ColdFusionMX”

  1. 90% of the time, you don’t care if foo is a number or a string though, you Just Use it.

    I tend to mark things like structs and queries in Hungarian though, because it does matter what they are because struts have different methods.

  2. Hi Tom. You are right to a large extent. I end up using Hungarian primarily for strings, booleans, queries structures, xml and objects.

    Using hungarian for chars, uuids and others is quite infrequent, at least for me.

  3. I tend to use the simular notation too.
    Since CF is typeless, it’s more so I can look at the name of a varaible and at least know how I *expect* it to be used.

    It’s another situation in CF where you can take it or leave it and comes down to a matter of style.

  4. Your first comment is an interesting one, Tom. I pretty much always care what data type my variables contain before I use them. Even in CF in which one does not have to declare specific data types, grammar rules and logic dictate that the variables are not "typeless", and the type is pretty important in all bar the most trivial situations.

    "dog" * catArray, anyone?

    For reasons apparent to Indy and Dave, I rather agree with that particular standard of Indy’s 😉

    I like the notion of being able to do this:

    lNames = "angela,barry,chuck,denise,edgar";
    for (iName=1; iName=listLen(lNames); iName=iName+1){
    sName = listGetAt(lNames, iName);
    }

    That’s a pretty contrived example but it’s pretty distinct how each variable fits into the equation, and amongst other code it’s easy to keep track of which variables are related to what.

    It’s also simply less typing without losing information to have "stPeople" as opposed to "peopleStruct", and such like.

    There’s probably other patterns around which achieve the same ends, but it’s good in a team environment to have a standard (any standard) and stick to it. It makes for more homogeneous code, which makes for easier maintenance.


    Adam

  5. I use hungarian notation alot with a slight variation on the boolean variables. I regularly use ‘is’ and ‘has’ (ie: isLoggedIn or hasPermissions) as I find this improves readability in some cases

Comment on this blog post...