Sitemap
Danny Fenstermaker

Danny Fenstermaker

UI Engineer Manager and tech lead

The power of Naming Conventions

3 min readNov 16, 2014

--

As developers we are constantly being challenged with learning new libraries and frameworks, these challenges along with the projects we work on are what ultimately shape our skills and abilities.

Personally I have found the challenges both rewarding and capable of making me wish I could punch baby seals. One of the biggest frustrations when working with someone else’s code is the ability to quickly grok what they are trying to accomplish and jump into or branch off of their functionality.

I wish I could say that I am not guilty of the above but after doing some soul searching and with the help of my team, I have realized that this is an area that I can use some work. So then my goal here is to take my thoughts in addition to some research I have done online and make an argument for being extremely critical when it comes to naming conventions.

The first article I read was in a blog post by Chris Parsons in which he stated:

Naming things is hard. Why do we expend so much effort to get them right? Because naming programming concepts well gives us a big insight into how they fit into the system we’re designing. Continually renaming things records our insights as we go: the right names for our objects, methods and variables will yield fresh insight and in turn shape the design of the system.

This to me defines the necessity for naming conventions and if taken as a hard and fast rule I feel it could clean up the inability to grok someone else’s work and quickly get up to speed. Naming all objects properly and with intent gives someone else a blueprint to your project, this is especially true with file names. If your file structure is properly defined and named one could follow a path of “parts” and find the functionality they’re looking for without even needing to step through code.

Get Danny Fenstermaker’s stories in your inbox

Join Medium for free to get updates from this writer.

The biggest offense I make is with variable and property names. I often find myself trying to name a field or variable something very short and quick. This works for the now but in a few weeks or days when I come back to look I find myself cursing old me. For the sake of progress I generally keep moving forward and committing the ultimate sin which is not cleaning it up and improving my skills. That being said I am working on it and getting better and after all I mean as Martin Fowler says:

There are two hard problems in computer science: Cache invalidation, naming things, and off by one errors.

So properly named variables can mean the difference between following a blueprint through our code or spending time putting breakpoints in and identifying the functionality via application and variable states. The most important reason I see for good naming is stating intent and clearly defining what the end result of the functionality should be. To drive my point I have created this Gist that shows the difference between good and bad naming:

https://gist.github.com/dfenstermaker/94d1a91c0eb6eba14e60#file-badconventions-js

The top file BadConventions.js has by all means the proper functionality and structure. With such little code you can both grok this very quickly and for the most part infer the intent. The code is very short though and this type of naming in large applications would quickly lead to some loss in our ability to know the intent of our systems inner-workings.

The bottom file GoodConventions.js from the start displays intent. We quickly learn that we are dealing with a list and that the two functions are intended to act upon the list. With more knowledge into our system as well as the applications purpose we could derive much more meaningful naming conventions. The end result is a systematic and fluid flow through our code ultimately leading one from the beginning of your app out to the different endpoints without needing to punch baby seals.

Thanks for reading and I look forward to any comments or feedback.

--

--