4 ms·
It depends on the language. Perhaps Haskell will not need such comment at all. In C++, at the very least the preconditions X and Y, as well as the invariant Z,
by TeMPOraL 6y ago
It depends on the language. Perhaps Haskell will not need such comment at all.
In C++, at the very least the preconditions X and Y, as well as the invariant Z, will usually not be apparent from the function signature. Whether the argument is modified? That's usually clear from the use of const... except when it isn't, e.g. because the function is a universal-reference template, or some C compat thing that must use bare pointers because reasons.
In JavaScript, you won't even know Foo, Bar and Quux, unless someone puts it in the function name.
The primary benefit of such comments is to encode enough information that isn't obvious from the signature, that you don't need to read the actual implementation. It's particularly useful if you're using an editor or IDE that can pull signature comments and show them during auto-completion - it saves you from constantly jumping into other places in the codebase, just to verify if you're picking the correct function for the task.