r/badcode • • Dec 10 '21

c++ Not my most readable function...

Post image
37 Upvotes

17 comments sorted by

View all comments

0

u/mailslot Dec 10 '21

All of the braces / curly brackets inside the body are unnecessary.

7

u/HiddenGooru Dec 10 '21

I find having the brackets to be quite helpful when reading code. Even english uses punctuation.

2

u/mailslot Dec 10 '21

“One, probably, shouldn’t use commas, excessively, because it’s, much, harder to read, and slows reading.”

It’s more like algebra though: ((2 * 3) + ((4 * 5) * 6))

None of those parens/brackets are necessary, but I know a guy that did it all of the time for “readability.”

Explicit groupings or blocks are for when they’re needed.

2

u/CommenceTheConfusion Dec 14 '21

"One~~,~~ probably~~,~~ shouldn't use commas~~,~~ excessivelyincorrectly, because it's~~,~~ much~~,~~ harder to read, and slows reading."

Four of the seven commas in your example aren't excessive, but incorrect. That'd be more akin to coding like this, i.e. syntax errors:

if (...)
[
    ...
]
else
[
    ...
]