It's been quite the week in my Twitter notifications. More than 6M "impressions". I had no idea this method would trigger all this. I simply thought it looked funny and visually interesting.
People love making assumptions though. Many assumed I thought it was it was horrible code. I don't think it's great code, but I certainly wouldn't rewrite it if I encountered it.
If I were to review this pre-commit, I would ask for the first condition to be <= 0, remove the redundant conditions and add an else to the last if. This would make it visually more consistent and easier to see everything matches up.
I would also add an assertion at the top to document the expected range of percentage.
From the replies to my tweet I learned a number of things: 1) Many are eager to argue about or "improve" the method, but are too lazy to lookup the context of were it is used. 2) Floating point comparisons are scary to some programmers. 3) Dunning-Kruger is real.
• • •
Missing some Tweet in this thread? You can try to
force a refresh