Re:Principle of Least Astonishment
by enraged_camel on Monday April 06, 2020 @03:14PM
(#22796841)
This is why I am a fan of long function names, like openUpgradeDowngradeSubscriptionDialog(). Even though they add a bit of verbosity to the code, I can immediately tell what they do without having to scroll to the function definition, and there is zero astonishment when they are called from elsewhere. To a lesser extent, same with variable names: speaking for myself (and perhaps only myself), I like long variable names -- as the saying goes, code is read many more times than it is written, so saving a few keystrokes just to shorten a variable name tends to carry a high cost that is paid down the line.
[ Parent
| on HN ]
Re:Principle of Least Astonishment
by jasonpeacock on Monday April 06, 2020 @03:37PM
(#22797019)
You're describing self-documenting code. Well written code shouldn't require any "what" comments, only "why" comments.
Too often you see code with a generically-named function/variable, and a comment next to it describing what it does. Why not just name the function/variable correctly?!
There's a strong cargo-cult idea that "real" programmers use short/abbreviated names, and yet there's absolutely no value to using "idx" over "index", or a more appropriately named "last_name_index".
Naming is always hard, but sometimes the "what" requires a full paragraph, and even very long variable names shouldn't exceed 80 characters all on their own.
torque_aux_motor_braking_only_safety_threshold_nm is a good variable name, but I wouldn't want to let them get much longer than that.
Re:Principle of Least Astonishment
by Ididntdothis on Monday April 06, 2020 @04:47PM
(#22797681)
Totally agree. At least don’t use generic names like “Config”. Call it “”DatabaseConfig” that has some meaning.