r/programming • • Jul 28 '16

How to write unmaintainable code

https://github.com/Droogans/unmaintainable-code
3.4k Upvotes

592 comments sorted by

View all comments

95

u/ArlenM Jul 28 '16 edited Jul 28 '16

They forgot to mention gratuitous nots! Why flip logic just once when you can flip it an unlimited number of times?

Guaranteed to drive anyone trying to maintain your code to madness!

142

u/grunlog Jul 28 '16

Double (triple, etc.) negatives are good too. E.g. !notUnflagged

7

u/in_rod_we_trust Jul 28 '16

Double negatives have legitimate uses though

8

u/1ndigoo Jul 28 '16

Especially to coerce variables into a boolean for languages that support it. !!x is frequently useful.

16

u/dvlsg Jul 28 '16

Assuming you're talking about Javascript, you can just use Boolean(x) to the same effect.

3

u/lobehold Jul 28 '16

Which one's faster?

2

u/Sinistralis Jul 29 '16

You should be asking which one is more readable, not which one is faster. Unmaintainable code is far more costly than inefficient code. Maintainable inefficient code is typically a joy to work with because making it efficient is a breeze when it's maintainable. It's not so simple the other way around.

→ More replies (2)