Do you (still) enjoy using any of the following stuff in pictures below? If yes, read no further.
The backdrop story for context and inspiration
In one of the training gigs for clean code at a so called ivy-league company, I was enquiring the team that attended my training on what is their code conventions for a variable name in their projects. The folks voiced in absolute enthusiasm that they follow industry standards of using a datatype as prefix for the variable name and ensure that the variable name is short enough to make sense for the developer to understand what it means.
Some personal and informal discussions with the folks led to the following observations:
- They are basically clueless on why they do that they do. All they can claim is that they follow some best practices or industry standards.
- Not one could say that they are actually following Hungarian notation as convention to naming variables. Personal discussion gave me an insight that they believe it is an industry standard because that is what their technical manager or some senior engineer who they can't question has insisted them to follow.
This is something you can witness more often than not in the mid-sized and large corporates that always cling to the imaginary "best practices" laid by the seemingly unquestionable superior (read it as senior) folks. These folks in my observation and understanding don't code every-day, have little respect for coders, yet interestingly enough set the technical standards.
Trouble with (bad) experience is difficulty in unlearning. Trouble with ego (that a stupid job title gives) plus half-baked experience is difficulty in reasoning. I empathise with the former and sympathise the latter. If you fall in the later category, read this post no further. If you fall in the former category, I'm with you and this blog post is for you to read and chew on.
Ok, now back to the business of picking some code snippets from the production code bases. The code snippets below meets the "industry standards" by the definition of the said team.
Now before we delve into why this is redundant to say the least, let us understand what is this practice all about by getting into some academics of it.
First off, the naming convention that the team followed is Hungarian Notation, to be more specific they were following Systems Hungarian notation.
Hungarian notation (HN) is the practice of prefixing metadata (mostly the data-type) of the variable to its name. And there are two types of Hungarian notation - the Systems and the Apps. They both are similar in that they are prefixes to the name of a variable. They are different from one another in that the former advocates prefixes indicating the actual data type of the variable, while the latter advocates prefixes indicating the logical data type.
Some examples of Hungarian Notation to make things clear.
There was a time when this (HN) was a big thing and made some sense - the times when IDEs were not as powerful as the contemporary ones. In the bad olden days the IDEs perhaps didn't have intelli-sense
- to tell the programmer that they are using the variable of a particular type on hover,
- to help the programmer with auto-completion of method names on adding a dot to the variable name
For a moment, think about putting in practice the convention of HN for object naming as you code. Would you like yourself to care about
- translating the solution in mind to code and validate it or
- worry about conforming to the such conventions while coding
Still not convinced? Here goes the question I ask my attendees who love HN in code. Would you like to prefix 'm' or 'f' to your name based on your sex, as in mAndy or fSandra? You certainly don't, right? Why then discriminate the code you read/write? Give it the respect it deserves.
Always strive to make code self-explanatory and easy for your fellow buddies to get acquainted with.
Happy code reading and writing!