Comments and Mnemonic Variable names

One of the important components to programming are comments. As the program gets bigger and more complicated the comments are necessary in order to give an additional and helpful information about the program code. Formal languages are dense, and it is often difficult to look at a piece of code and figure out what it is doing or why.
The notes are called comments, and they start with the # symbol:
# C is  x + 5
>>> c = x + 5
Everything from the # to the end of the line is ignored-it has no effect on the program. Comments are most useful when they document non-obvious features of the code. It is reasonable to assume that the reader can figure out what the code does; it is much more useful to explain why.
Good variable names can reduce the need for comments, but long names can make complex expressions hard to read, so there is tradeoff.
It’s very important to use good variable names in order to easily read variables inside your program code and to understand what the program code does. If you use good variable names there is less need for commenting every single line of your code.
The Python interpreter sees all three of these programs as exactly the same but humans see and understand these programs quite differently. Humans will most quickly understand the intent of the second program because the programmer has chosen variable names that reflect the intent of the programmer regarding what data will be stored in each variable.

We call these wisely-chosen variable names “mnemonic variable names”. The word mnemonic means “memory aid”. We choose mnemonic variable names to help us remember why we created the variable in the first place.While this all sounds great, and it is a very good idea to use mnemonic variable names, mnemonic variable names can get in the way of a beginning programmer’s ability to parse and understand code. This is because beginning programmers have not yet memorized the reserved words (there are only 31 of them) and sometimes variables which have names that are too descriptive start to look like part of the language and not just well-chosen variable names

Nema komentara:

Objavi komentar