Wednesday, 30 March 2016

Words to separate value from counting

I'm a developer as well, I try to make my variables easily understandable for the poor soul who comes after me and has to maintain my code. For number of a given set of things, I'll use thingCount. For the value of that or those things, I'll use thingValue and if there's a total amount of things, I'll use thingTotal. I don't worry about the verbosity of the variable names because it makes them more understandable and the compiler (at least in modern languages) doesn't care and they take up just as much space as terse variable names.



When I first started developing code (for AutoCAD of all things), I used to condense my variable names down to things like: tv which made perfect sense to me as long as I was actively working on the code, but let a couple of weeks go by, and tv again meant television instead of "thingValue", and I had to go back through my code to figure it out again. Much-much easier to simply name things after what they are regardless of verbosity because it's much-much easier to figure things out when you're deep down in the bowels of your code (or worse, someone else's that you have no history of). There's a good Uncle Bob (I think) quote & blog post on this that I'll try to find & update my answer with.



This isn't exactly the blog post I was looking for, but it's still a good start. I'll find the other one and get it in here as well.
Uncle Bob's Naming Conventions



Here's the original blog post, some of the humor may not ring true with folks like the OP who didn't grow up in the US, so apologies for that. However, the post is still very valid:
Uncle Bob's Bad Variable Names

No comments:

Post a Comment