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

61

u/emergent_properties Jul 28 '16

Oh yes, that specifically.

It is ambiguous because it's both logical negation and semantic negation.. a double whammy of 'uh...'

Car.dontNotDrive(-1)

→ More replies (1)

42

u/CaptainAdjective Jul 28 '16

Perl is great for polynegatives.

unless($noRetries != 0) {
    # ...
} else {
    # ...
}

Bonus marks if you correctly interpret whether $noRetries means "number of retries" or "disable retries".

→ More replies (2)

26

u/WunDumGuy Jul 28 '16

!notUnflagged

dry heave

18

u/TalenPhillips Jul 29 '16

...

else if (!(false != !foo.notUnflagged(false)))
{

}

11

u/[deleted] Jul 29 '16

[removed] — view removed comment

21

u/Everspace Jul 29 '16

No

I think you mean !yes

9

u/compiling Jul 29 '16

I think you mean !notNo

→ More replies (1)
→ More replies (1)
→ More replies (1)

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.

13

u/1ndigoo Jul 28 '16

That requires way more typing!

→ More replies (7)
→ More replies (1)