Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I see rubbish like this in PHP (and Java) code all the time:

    /**
     * Frobnicates a foobar
     * 
     * @param Foobar $foobar The foobar to be frobnicated
     * @param int $intensity The intensity with which the foobar will
     *    be frobnicated (defaults to 4)
     * @return mixed The result of frobnicating a foobar
     */
    function foobar_frobnicate(Foobar $foobar, $intensity=5)
    {
        // frobnicates the foobar
        return $foobar->frobnicate($intensity);
    }
It's utterly ridiculous.

Pretty sure I've been guilty of this in the past, too. As I recall, the documentor tools make a lot of noise if you don't supply wasteful and irrelevant values for every single little thing even if it's blindingly obvious from the symbol, context or idiom what it means and what it does.



I like how you made the comment say 'defaults to 4' while the code says 5, this pretty much sums up my experience with 'documentation comments' as well.


Funny (and perhaps intentional) that your example comment and code disagree ("$intensity=5").


I think we can all agree that this is the most blatant example of useless documentation.


It's a bit contrived but it's not even as useless as it would appear to be (if you forget about the likely intentional mismatch between the default value and its documented value).

The purpose of this comment is obviously not to clarify the code for someone working on it, but to ensure the automatically generated API docs stay consistent. I write comments like these above functions all the time, because we have a zero-warning policy for doxygen comments over here, to prevent people forgetting to document public API methods (or slacking off out of laziness). Sure, the comment block is redundant since it contains nothing that cannot be derived from the parameter names and the name of the function, but it does make sure a doxygen run will not spew warnings and errors all over the place, drowning out uncommented methods with far less obvious functionality or parameters. The redundancy is a small price to pay to enforce a good self-documented API.

I really don't understand any of the discussions about not documenting code because it should be 'clean and obvious'. First of all that's mixing up 'how' and 'why' code is like it is, second it's a small effort to write and maintain code comments (contrary to what some people like to suggest otherwise), third it can help you organize your thoughts while you are writing the code (write the steps of your algorithm in comments, then translate them to code), etc.

Personally I also like how the syntax highlighting breaks up blocks of code with API doc comments, which makes it much easier to see where functions start and end when scrolling fast, or how they can separate distinct steps of an algorithm. 'No comments' really is the inverse of 'literate programming', like most of the time, the truth is probably somewhere in the middle.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: