coding-style
When do we need #ifdef before #undef?
See ISO C99 6.10.3.5 paragraph 2. A preprocessing directive of the form # undef identifier new-line causes the specified identifier no longer to be defined as a macro name. It is ignored if the specified identifier is not currently defined as a macro name. Even Visual C++ 6 (which was notorious for bad standards compliance) …
Is usage of anonymous classes in Java considered bad style or good? [closed]
I tend to use anonymous inner classes in situations where I don’t need to have a full-blown class just to perform some task. For example, if I want to implement an ActionListener or Runnable, but I don’t think having an inner class would be necessary. For example, for starting a simple Thread, using an anonymous …
Why is indentation in empty lines bad?
It is probably because merging patches with useless whitespace is harder than it should be. diff(1) and patch(1) treat spaces and tabs as important content. (Ask any Makefile or .py source file — they are important!) And if your “blank line” has four spaces on it, and my “blank line” has eight spaces on it, …
Using len() and def __len__(self): to build a class
There is a huge difference. The __len__() method is a hook method. The len() function will use the __len__ method if present to query your object for it’s length. The normal API people expect to use is the len() method, using a .len attribute instead would deviate from that norm. If the length of self.data …
Private method naming convention [closed]
I’ve never seen any coding convention in C# that distinguished between public and private methods. I don’t suggest doing it, since I don’t see the benefit. If the method name conflicts with public methods, it’s time to become more descriptive; if, as in your case, it contains the actual method implementation for the public method, …
Should I prefer private member functions, or functions in an unnamed namespace? [duplicate]
In the semi large projects where I usually work (more than 2 million lines of code) I would ban private class functions if I could. The reason being that a private class function is private but yet it’s visible in the header file. This means if I change the signature (or the comment) in anyway …
Should you use const in function parameters, and why does it not affect the function signature?
const is pointless when the argument is passed by value since you will not be modifying the caller’s object. Wrong. It’s about self-documenting your code and your assumptions. If your code has many people working on it and your functions are non-trivial then you should mark const any and everything that you can. When writing …
In Python, is it better to use list comprehensions or for-each loops?
If the iteration is being done for its side effect ( as it is in your “print” example ), then a loop is clearer. If the iteration is executed in order to build a composite value, then list comprehensions are usually more readable.
C# coding standards for private member variables [closed]
Besides the two you mention, it is very common in C# to not have a prefix for private members. class Foo { private int i; private string id; } That is what I use, and also what is recommended in Microsoft’s internal naming guidelines. See also these .NET naming guidelines.