Okay, just a hint: if you are writing C, C++ or any other compiled language you aren’t doing anyone a favor using one character variable names. It literally costs nothing to make things clear. One character variable names are terrible.
While I’m on it, gotos are similarly bad. If you feel you need to do either of these, DON’T.
A good friend of mine said, jokingly, “Good code is hard to write, it should be difficult to understand!”
I leaned the hard way: global replace a single character name. It’s far easier to do it right than shoot yourself in the foot. Even if it is “index1, index2”’you may want to change those to something more meaningful later on.
@feloneouscat Most of my almost C++ coding is for Arduino. The Arduino is a simple beast and there is no multi-threading. After learning the wrong way, thanks to popular tutorials, I got serious about learning how to develop non-blocking code. If anything, I tend to be too verbose when naming variables.
Majority of my work has been on processors that didnt have more than a couple of K of ram. Arduino is spacious. You can never go wrong being verbose.
I worked on an open source project once and people were deleting comments. I asked why and they said, “Becausr it is obvious from the code”—I quit.
Obvious today. Three months from now? Not so much.
Been there done that.
@feloneouscat Yes! I totally agree about the variable names, with the possible exception of if you're implementing some very abstract mathematical function whose variables can't really be mapped onto more meaningful names.
I have only *somewhat* more mixed feelings about gotos - while I certainly don't want to see them in lasting code, I sometimes use them when I'm testing something something out & realize I made boneheaded structural mistakes... then refactor them out later.
Rule of thumb: if you feel you”need” a go to, you need to create another function. It costs nothing and adds clarity.
Some clarification: some I mentioned this to have argued that a three line function is silly.
My counter argument is, “Then it should be easy to write” — the computer doesn’t care, why should we? What is important is does it make the code easier to read and update? If it does, then it is a win.
Gotos are messy and hard to follow. I wrote assembly language for almost a decade where it is unavoidable. Avoid it. This is why assembly is hard and error prone.
@feloneouscat I have made my coworker rewrite code because the variable names weren't clear and I needed to make a change. Literally told him to fix it because he was blocking me lol. He shamefully agreed it needed to be done.
There are 4 single character variables names I agree with being allowed: i, j, k, _. Granted, if you reach k, you've got other problems.