The Importance of Variable Prefixing

I remember my first official University programming course. We were to learn the language Pascal. Pascal is a socalled "teaching" programming language primarily to teach structured programming.

During the first semester we learned a lot about syntax and conditions, looping, and a whole bunch of other things. An incredibly important, in the eyes of our professor, was the subject of variable notation. He was a die-hard fan of the Hungarian Notation, I remember receiving poor marks on a perfectly running code assignment because my variables were not appropriately named. This method of variable naming or prefixing resolved itself later into my professional life into mainly just CamelCase and followed on into Java naming conventions. Java naming conventions are fine in a case sensitive language but only help to increase readability in a case in-sensitive language like Coldfusion.

I then noticed a blog post by Sami Hoda about how CF9 doesn't like Mango Blog. In his blog post he mentions a couple of errors that led me to believe that the programmers of a couple of the Mango plugins:

  • a) Created functions that are now part of CFML and
  • b) used variable names that have now become reserved words or functions.
Two examples are ArrayFind and Location, both are new in CF9, the first one is obvious, the second one is a function wrapper for the cflocation tag.

This goes to show that Hungarian Notation still has a very important place in todays programming, if the Developers of Mango blog used Hungarian notation to prefix their variables and functions the likely hood that a conflict would arise due to changes in the core language would be non-existent. If "location" was "strLocation" and ArrayFind() was fnArrayFind() a conflict would have been prevented.

I will be the first one to admit that I don't use the full Hungarian Notation, but i do follow the official declared guidelines at my place of work.

The upgrade problems seen in Mango Blog highlight the need for programmers to be aware that they should also code for the future, not just the now.

3 Comments to "The Importance of Variable Prefixing"- Add Yours
Todd Rafferty's Gravatar You raise very good points.
# Posted By Todd Rafferty | 10/10/09 1:09 AM
Sami Hoda's Gravatar I would say this is especially important when adding code to 3rd party apps, like in building plugins, etc. You never know how people will name stuff, so if you keep yours according to some standard, you definitely lessen the chance of something like this happening. Something like ArrayFind could also be a part of a different CFML engine, so that's a bad name to pick all around.
# Posted By Sami Hoda | 10/12/09 9:14 AM
Gary Gilbert's Gravatar I have noticed that a lot of people prefix private functions with an underscore e.g. _myPrivateFunction() while not "hungarian notation" conform it does eliminate potential conflicts
# Posted By Gary Gilbert | 10/12/09 6:50 PM

Powered By Railo

Subscribe

Subscribe via RSS
Follow garyrgilbert on Twitter Follow me on Twitter
Or, Receive daily updates via email.

Tags

adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript max2007 max2008 misc open source programming railo software technology ui

Recent Entries

No recent entries.

Blogroll

An Architect's View
CFSilence
Rey Bango
TalkingTree

Wish List

My Amazon.com Wish List