Unicode identifiers, FTW.
At least as long as you are developing on a Mac (after all these years, I still have no idea how to type greek letters on a PC keyboard).
Unicode identifiers, FTW.
At least as long as you are developing on a Mac (after all these years, I still have no idea how to type greek letters on a PC keyboard).
I keep seeing it happen, and the problem is that some people actually believe this is optimizing code. The problem becomes code readability, which hurts in the long run, especially as other developers get on with the project.
I don't think that shortcutting var names really optimizes the process. To be frank, we spend a lot more time reading code than writing code, so we should optimize readability, no ease of writing it. Just my 2 cents.
To be frank, we spend a lot more time reading code than writing code, so we should optimize readability, no ease of writing it.
Plus, if there is one thing modern compilers are good at optimizing away, it is variable names :)
I've found that a lot of code is written by mathematicians or physicists, and on paper the formulas all have one-letter-variables, so they will copy that one-to-one when they implement it in code.
For instance, an electronic engineer will know that the formula for calculating a charging voltage of a capacitor in an RC circuit is:
U = U0 * (1-e^(-t/(R*C)))
So in code, I will reflect exactly that:
double U = U0 * 1-pow(e, 0.0-t/(R*C));
Every non-electronic engineer is going to look at that and go "WTF IS THIS CRAP".
I've had moments where I've done the same thing at first glance, but as soon as I research the algorithms being used, the variable names begin to make a lot of sense.
I mean, when you are writing hundreds and hundreds of lines of code, it gets annoying typing in long names.
One word: auto-complete.
Yeah comet, that is what I saw. Even for variables that aren't math formulas I see why such short names were used, and I have started to do the same myself. I am still going to stick with doing longer names for tutorials.
I don't think I have auto-complete, as I am using a plain text editor, without the help of a big IDE. Sometimes I do use Notepad++ which might have auto-complete, but mostly I use Scite.
For instance, an electronic engineer will know that the formula for calculating a charging voltage of a capacitor in an RC circuit is:
U = U0 * (1-e^(-t/(R*C)))
So in code, I will reflect exactly that:
double U = U0 * 1-pow(e, 0.0-t/(R*C));
Every non-electronic engineer is going to look at that and go "WTF IS THIS CRAP".
The electrical engineer might wonder though why you wrote 0.0-t/(R*C) instead of just -t/(R*C) (is -0.0 an issue for the pow function you are using?). And the computer scientist might wonder why you are using pow(e,x) instead of exp(x) which is usually faster. And both might notice you forgot an opening parenthesis In any case it wouldn't hurt anyone to write
double voltage = starting_voltage * (1. - exp(-time/(resistance * capacitance)));
Instead, as then both the electrical engineer and the computer scientist would probably have a rough idea what its about, at the cost of only a few keystrokes (which tend to be fairly cheap ).