|
|
|
|
|
by randomdata
5000 days ago
|
|
I would love to see a good example of your first case. It is difficult to imagine and learn from it without seeing it action. As I mentioned before, it seems the number of people who can actually pull off good comments are exceedingly small. I've looked at some prolific open source projects that have a decent amount commenting around method definitions as you suggest is good practice, but found the comments to be no more enlightening than just looking at the source code itself. I will assume they were just poor examples. I do agree with everything else you said though. |
|
An example would be:
"Verify account takes an account ID, an optional enabled flag which, if specified, will only search for accounts that have a matching enabled status. The default is to search against all accounts. The return value is true if the account is valid, false otherwise."
These are extremely important in loosely typed languages where there is little indication as to what constitutes an acceptable argument. In a more rigid language like C++ there are usually a lot more hints in the language about what the input and output is.
Still, in programming "by contract" it is important to manage expectations and comments can communicate a lot of this.