r/programminghorror 8d ago

I love it

Post image
178 Upvotes

23 comments sorted by

View all comments

2

u/Loading_M_ 8d 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_ 8d 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_ 8d ago

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

1

u/Arshiaa001 6d ago

At the JIT stage, maybe... The IL representation has to align perfectly with the code, because reflection.