I knew there was a reason I hated the "m_" naming convention

Posted by admin, Fri Aug 27 18:52:28 UTC 2004

For years, I’ve been diligently erasing all traces of pre- and post-fix naming conventions from the source code under my control. I’ve always hated it. The argument I most commonly make for this is that, IMO, it makes the code less readable. Now, in a happy coincidence, I have been reminded about this topic, when I have actual proof to point at to back it up.

Now, “readable” is a very subjective term. Some people would insist that the prefix “m_” provides additional semantic meaning to the field, telling you that you are dealing with a class field instead of a parameter or local variable. In Java, so does “this.”. Others would add tags like “str” to the beginnings of every String field name. Again, yes, it adds semantic meaning, but any decent IDE will provide the same information in several different forms (tooltips, find definition, etc) without the extra baggage.

So, what about this proof? Consider the following:

Aoccdrnig to rsaerech, it dseon’t mttear in waht odrer the ltteers in a wrod are, the olny iroptmant tihng is taht the fsirt and lsat lteetr be at the rghit pclae. The rset can be a taottl mses and you can sitll raed it wouthit any perbolms.

Now, I hope you see where I am going. The real problem with all these pre- and post-fix notations is that they screw up that first/last letter recognition that seems to be hard-wired into readers of the English language, mostly because of some redundancy features of English. (See the links at the bottom of this post for more information about this.) So, there you have it. Proof that readability in your code is diminished by the use of pre- and post-fix naming conventions.

So let’s all get out there and start improving the readability of our code. JBuilder has some nice Rename Refactorings to help. ;-)

References Comments from a researcher at Cambridge A letter purportedly from the original researcher of the topic

And thanks to Anders for the inspiration from his new CafePress shop.

Filed Under: | Tags:

Comments

Have your say

A name is required. You may use HTML in your comments.