True Memes of development: variable naming
At first you may wonder "could this be true". Then you might think "why a platypus?". This is one of the simplest of the memes and yet one of the truest.
Variable naming has been said to take 60% of the time of many developers, and I feel that to be true.
The first problems to plague most students are syntax, typos, and then poorly named variables. Poorly named variables are the most insidious problem, because the pain doesn't manifest right away. It happens days or months later.
The first problem: while trying to figure out your own code it can be hard to follow your own logic. If you name a variable as 'a', it's going to be very difficult later on to remember what it was for. I see this more often with for loops, when people name their index something like i or x. Or even worse, with nested loops, i and j which look very similar, to add extra confusion.
If you're going to name your indices something useful, name them as an index of something. If it's a list of people you are iterating through, name your index personIndex or personPosition
The second problem comes from your coworkers and bosses. How will they be able to quickly understand what your code is doing? A lot of people peg their future on good comments, but good comments are a distant third to good variable names and good function names.
Name your functions with a verb in mind. Functions do things to something. What does this function to what. What does it start with? If it's a function that removes all negative numbers from an array and returns an array, this is a decent function name removeNegativeNumbersFromArray. It may seem silly and overly long, but there will be absolutely no confusion as to what it does and what it works on.
The third problem: you reading the same code in 6 months time. It will be hard enough to remember what you did even if you name it well. Well-named variables is a gift you give your future self. Name them well now, and they will serve you well later when you go to update the code or, hopefully, on a job interview when someone asks you how you did something amazing. The last thing you want to say is "uh, I don't know".
Take the time and name your variables well. Some guidelines:
Go bigger before you go succinct. Over time you can learn how you like to shorten those long names, but long names will be generally understandable.
Keep with a naming convention. Don't swing wildly between camelCase, PascalCase, kabob-case, or any other format you prefer. SCREAMING_SNAKE_CASE anyone? Stick with one type so you don't wonder which type you used for this particular variable when reusing it. And when you start a job, find out what convention they prefer and use that.
Add verbs to function names, not to variable names. Verbs convey a sense of doing, which is what functions are for!
Try to talk about what a variable will be used for more than the contents of it. If you have an array of ages of people, don't call it arrayOfNums even though that is very accurate. peopleAgeList will be not only better to give you a sense of what you should put in it, but also what you shouldn't put in it. And if you suddenly decide to store string ages, you don't have a variable that is wrongly named.
Got any more memes, job postings, or technologies you would like to see me cover? Leave me a comment below!
For those wondering about the platypus and "shaving hours off development time". The platypus is probably "if I had to name this thing, what would I name it? fuzzyDuckBeaverMammal? And the "shaving hours" is for those that don't use good variable names because it takes too long. You shave hours off development time now and probably have to spend days of development time later. It's an aspect of what we call "tech debt"