40
Lokuzt
7y

Please don't comment in front of the code like this:

doSomething(); // does something

Please just stahp

Do this:

// does something
doSomething();

Much better and friendly for everyone

Comments
  • 8
    If it only explains why one line exists/one line then

    foo(); //bar

    is very fine.
  • 0
    @filthyranter if it's that short on a short file yeah. Large apps with big lines of code and huge amounts of code do not benefit of this
  • 0
    @Lokuzt I always do it. Well, my school lets us fucking do the stuff on paper anyway. -.-
  • 1
    Is that a bad practice? I always do this if the comment is short. And it can show up in the search result in case I have to do a global search.
  • 3
    Seriously that's just an opinion. With no logic driven reason. There are more advantages to using it, just like seeing it in search results.
  • 0
    Or better yet: Don't write the comment at all. If you named your function correctly that comment is completely not necessary.
  • 1
    I do this for short comments.
    However like someone mentioned about longer comments, I prefer multiple lines of comment, each line with roughly 7 words. easy to scan through and does not mess with the flow of the code :)
  • 2
    I do this when I am trying to comment if/else if/else blocks

    if () { // do stuff
    ...
    } else if () { // do other stuff
    ...
    } else { // do other stuff
    ...
    }
  • 0
    @deusprogrammer I can't imagine commenting if/else statements any other way!
  • 0
    I wouldn't generalize this both is ok under the right circumstances
Add Comment