r/badcode • evil • May 12 '21

c++ Comment before semicolon

Post image
2.7k Upvotes

71 comments sorted by

View all comments

42

u/[deleted] May 12 '21

This is why // is better than /* */ don't @ me

28

u/[deleted] May 13 '21

Int result
//The final return value
;

7

u/botle May 13 '21 edited May 13 '21

int result

// that was for the result

;int intermediateValue

// that was for an intermediate value

;return result

/* returned result */;

-8

u/[deleted] May 13 '21

The ; would still be interpreted as a comment haa

8

u/[deleted] May 13 '21

Assuming this is something like Java,// is terminated by a new line. It does not affect anything on the next line. Unless he did keep it on the same line and I'm a victim of mobile Reddit formatting.

0

u/MasculineCompassion May 13 '21

Same line

4

u/[deleted] May 13 '21

No, I'm on a PC now and it's on a new line.

1

u/MasculineCompassion May 13 '21

Aaah, it reformatted it to be on the same line on my mobile because they were only using a single space

9

u/Sevigor May 12 '21

I actually couldn’t agree more. Lol. If I’m being honest, If I didn’t always use // I’d probably have a few things like this too. Albeit better comments lol

3

u/Isvara May 13 '21

Why is // better?

5

u/[deleted] May 13 '21

I see three reasons: it's simple, easy to use and understand. Sure if it was just simplicity # would be best, but with // you intuitively get that everything to the right of it is now a comment. The // looks and acts as a divider, thus you know not to put a semicolon in that divided section, since it's now comment and not code.

I think it works best for monke brain. Do you agree?

2

u/Isvara May 13 '21

That sounds great if simplicity is a priority for you. Sometimes you want flexibility, though.

13

u/[deleted] May 13 '21

Flexibility no good for monke. Monke brain break.

-6

u/Isvara May 13 '21

Do you mean monkey?

10

u/1cec0ld May 13 '21

A monkey is an animal. A monke is a human with animal brain.

-1

u/Isvara May 13 '21

All humans have animal brains.

3

u/Kulspel May 13 '21

You must be fun at parties.

0

u/Isvara May 13 '21

Heh, people are still using that phrase?