Python name mangling

When in doubt, leave it “public” – I mean, do not add anything to obscure the name of your attribute. If you have a class with some internal value, do not bother about it. Instead of writing: class Stack(object): def __init__(self): self.__storage = [] # Too uptight def push(self, value): self.__storage.append(value) write this by default: … Read more

Correct Bash and shell script variable capitalization

By convention, environment variables (PAGER, EDITOR, …) and internal shell variables (SHELL, BASH_VERSION, …) are capitalized. All other variable names should be lower case. Remember that variable names are case-sensitive; this convention avoids accidentally overriding environmental and internal variables. Keeping to this convention, you can rest assured that you don’t need to know every environment … Read more

What is the purpose of the single underscore “_” variable in Python?

_ has 3 main conventional uses in Python: To hold the result of the last executed expression in an interactive interpreter session (see docs). This precedent was set by the standard CPython interpreter, and other interpreters have followed suit For translation lookup in i18n (see the gettext documentation for example), as in code like raise … Read more

Using i and j as variables in MATLAB

Because i and j are both functions denoting the imaginary unit: http://www.mathworks.co.uk/help/matlab/ref/i.html http://www.mathworks.co.uk/help/matlab/ref/j.html So a variable called i or j will override them, potentially silently breaking code that does complex maths. Possible solutions include using ii and jj as loop variables instead, or using 1i whenever i is required to represent the imaginary unit.

What is the meaning of single and double underscore before an object name?

Single Underscore Names, in a class, with a leading underscore are simply to indicate to other programmers that the attribute or method is intended to be private. However, nothing special is done with the name itself. To quote PEP-8: _single_leading_underscore: weak “internal use” indicator. E.g. from M import * does not import objects whose name … Read more

What are the rules about using an underscore in a C++ identifier?

The rules (which did not change in C++11): Reserved in any scope, including for use as implementation macros: identifiers beginning with an underscore followed immediately by an uppercase letter identifiers containing adjacent underscores (or “double underscore”) Reserved in the global namespace: identifiers beginning with an underscore Also, everything in the std namespace is reserved. (You … Read more