Variable names, their types and choice of language – a 5 day experiment
- You have to have knowledge of your types, either through tools or through syntax.
- Have different naming conventions for different languages.
- A strongly typed compiled language can have any naming convention but a weekly typed should have the types integrated in the variable names.
Should one use Hungarian notation (sName, oCustomer), type suffixing (nameString, customerObject) or leave out the type (name, customer). The Rulez have come full circle and we are now back at keeping it simple so name and customer is what we write in coding standards nowadays. I am a die hard fan of compiled and strongly typed languages and I really don’t care. My compiler, my IDE and my plugin take care of finding misspellings and type mismatches.
So I set out on a 5 day experiment.
updateCustomers( customers )
which iterates and calls
updateCustomer( customer )
and returns a bool if everything worked as expected.
My conclusion is that this is a bad idea.
I spent way too much time debugging and tracing the-object-property-having an-array-of-another-object-type and whether the final property had a plural “s” or not. The example is not contrived; I had a view model object containing an object which contained a list of Customers which contained properties, or a property which was a list.
To add insult to injury – Knockout was involved so I had to trace through method calls which made the debugging even more tedious. (don’t get me wrong – Knockout still does it’s work properly – it is my own objects and their relations and above all naming that trips me)
After this real world experiment I now have a case for having the type in the identifier names.
bUpdateCustomers( aCustomer )
which iterates the the parameter and calls
bUpdateCustomer( oCustomer )
I am not saying hungarian notation is better than suffixing the type but it makes for shorter names. Which makes for less possibility to mistype.
[ before gong berserk on Hungarian notation – please check into the difference between System and Apps. ]