Avoid bad variable names in programming

preview_player
Показать описание
How do you write code with less bugs and errors? How do you make your code more readable and easier to maintain? Well, one crucial part of the answer is choosing good variable names.

Note: There is one more programming error hidden in this video. Can you find it? (scroll down for answer)

E=mc^2 is incorrect, it should be E=m*c^2 (or E=m*c**2 depending on what programming language you're using). If you happen to have a variable named mc, this bug might be really tricky to find.
Рекомендации по теме
Комментарии
Автор

Pardon me, I think that long variable names are more readable than short variable names in general, because they immediately remind the reader of the context. A reader might not immediately recall that certain abbreviations stand for certain concepts (e.g. "s" stands for distance, "a" stands for acceleration etc.), especially if their primary field of work is not close to the field the code or text is written for (e.g. the reader might specialize in software engineering, while the code or text is written for mechanical engineering). As for not being able to check expressions with long variable names at a glance, a good solution, in my opinion, is to use variable names that include only the first few letters of the concept name (e.g. "dist" instead of "distance" or "s", "vel" instead of "velocity" or "v").

Sidenote: This is an aspect of mathematics and natural sciences I don't like; the writers often assume the readers always remember the meanings of the variable names. While this is fine for short expressions or formulas, when making or studying long calculations (e.g. across several pages) this becomes confusing.

ringyring
Автор

Why in the second formula presented (1:25) is the fourth “a” value denoted as “a2” instead of “a1”?

johnistre
visit shbcf.ru