5 ms·
When your coding standard enforces 80 characters, you end with a single logical statement split across many lines. This quickly approaches un-readability if you
by patrick451 5y ago
When your coding standard enforces 80 characters, you end with a single logical statement split across many lines. This quickly approaches un-readability if you fetishize self documenting code. In my opinion, short variable and function names with a comments are often more readable that self documenting behemoths, e.g.,
double compute_angular_acceleration_in_radians_per_second_per_second(double torque_in_newtons_per_meter, double moment_of_inertia_in_kilogram_meters_meters);
vs
// Units are base unitsSI.
double compute_angular_accel(double tau, double J);
I'll take the second any day.
- pydry 5y agoWhat about the day the Mars climate orbiter was lost because one piece of code wrongly assumed that the units of figures out of the other piece of code? :) I find that you do sometimes need symbol names that long even though it's a code smell indicating something else is up - usually scopes that are too large or insufficiently expressive types. I view excessively long variable names as a midpoint on a journey to improving code quality on really bad code bases.
- adrian_b 5y agoWhile what you say about long variable names can be right in certain circumstances, the example with the wrong units is inappropriate. In my opinion any code that deals with physical quantities, but which does not use dedicated types for each kind of physical quantity, where the type definitions include the units used, is erroneous. Any mistake like in the Mars orbiter must be detected at compile time.
- bccdee 5y agoIt's also substantially easier to update a comment, making it more descriptive, than it is to update a variable name.