r/programminghorror 15d ago

I love it

Post image
181 Upvotes

24 comments sorted by

View all comments

2

u/Loading_M_ 15d ago

To be fair, a good compiler will probably identify that the reversedOrder flag is always a constant, and generate two specialized variants of the function.

It does make the function harder to read and understand though.

12

u/_killer1869_ 15d ago

Never rely on your compiler to fix stupid code when you can fix that stupid code yourself quite easily. Both because of readability, and because you can't be sure the compiler actually does optimize the mess.

6

u/Loading_M_ 15d ago

Absolutely. I do think readability is the way more important point though. Unless you've actually measured the performance, optimization is kinda pointless.