What's your opinion on putting a comment at the end of an "IF" statement?



  • The lead developer at my work wants us to put a comment at the end of every IF statement that contains the expression of the IF statement. This supposedly makes it more readable.

    For Example:

        If ((person in stoopid_people) && (person != '')) {
            blah blah blah
            blah blah blah
            blah blah blah
            ...more than a screen of statements...
        } //If ((person in stoopid_people) && (person != ''))
    
        If (dumb_ide_that_cant_show_matching_brackets == true) {
            If (something else to be tested) {
                blah blah
            } //If (something else to be tested) {
        } //If (dumb_ide_that_cant_show_matching_brackets == true)
    

    To me, this makes the code noisier and probably indicates a code smell. If the code is getting too confusing with IF statements, nested IFs, and IFs that have a lot of content within the statement, then maybe the code needs to be cleaned up. What do you think of this "coding standard"?



  • @projecktzero said:

    What do you think of this "coding standard"?

    You're doing a good job of summarizing my thoughts on the matter:

    @projecktzero said:

    If the code is getting too confusing with IF statements, nested IFs, and IFs that have a lot of content within the statement, then maybe the code needs to be cleaned up.

    This is a stop-gap measure that is akin to plugging a leak in your pipes by tightly wrapping some cloth around it and putting a bucket under it to catch any drips. It is very much an anti-pattern and very much to be avoided.

    If your logic flow becomes bloated enough that you cannot immediately visually pair things up, you are in need of refactoring -- period. Break the logic down into several smaller methods or rewrite the conditions into a more simple form. (From my own experience, code where this anti-pattern occurs strongly correlates with code that was written by people that were never schooled on basic boolean algebra. That means you have a very good chance the conditions can be rewritten into a much simpler form.)


  • Discourse touched me in a no-no place

    @projecktzero said:

    dumb_ide_that_cant_show_matching_brackets
    This more or less sums up my thoughts on the matter.



  •  It's stupid and needs to stop.



  • @projecktzero said:

    The lead developer at my work wants us to put a comment at the end of every IF statement

    Comments are supposed to explain what's going on (comments are for the human, code for the computer). They should explain WHY you]re doing it, not what you're doing.

    @projecktzero said:

    that contains the expression of the IF statement.

    What if the comment differs from the IF condition? Which is deemed to be correct? What's the logic behind this?

    @projecktzero said:

    This supposedly makes it more readable.

    Fuck right off. I'll tell you a condition, then tell you what to do when that condition arises.. and when you ask for clarification, I'll repeat the condition - because that explains everything, right?

    Shitfuck pastry.



  • @Cassidy said:

    Fuck right off ... Shitfuck pastry

    ...is the correct answer. Ten points.



  • If your IF statements need comments at the end, you should really move on to the chapter of your programming language handbook that tells about functions.



  • @Cassidy said:

    What if the comment differs from the IF condition? Which is deemed to be correct? What's the logic behind this?
    Extra points on the WTF scale, that's the logic.

    I'll tell you a condition, then tell you what to do when that condition arises.. and when you ask for clarification, I'll repeat the condition - because that explains everything, right?
    +1

     



  • @TGV said:

    @Cassidy said:
    I'll tell you a condition, then tell you what to do when that condition arises.. and when you ask for clarification, I'll repeat the condition - because that explains everything, right?
    +1
     

    .. and yet people do this outside of programming: they seem to believe repeating the same confusing sentence more slowly and LOUDLY seems to clear things up.


Log in to reply