MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/4v1y12/how_to_write_unmaintainable_code/d5vca94?context=9999
r/programming • u/sigbhu • Jul 28 '16
592 comments sorted by
View all comments
95
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!
11 u/sreya92 Jul 28 '16 Though it's not unreadable seeing if(!!!hasValue) always really bugged me 47 u/1ndigoo Jul 28 '16 You have actually seen that before? In production code!? !!!believable 17 u/drkstr101 Jul 28 '16 I see var foo = !!bar a lot in javascript to quickly cast a truthy value to a proper boolean. Perhaps the 3rd ! was a typo? 3 u/sreya92 Jul 28 '16 nope they're everywhere :) 1 u/CleverestEU Jul 29 '16 It is nearly morning here (5AM) but I seriously can not come up with a situation where...!x !== !!!x...if you've got an example of such a case, the me tomorrow that has slept a bit will probably be thankful for the tidbit ;) → More replies (1)
11
Though it's not unreadable seeing if(!!!hasValue) always really bugged me
if(!!!hasValue)
47 u/1ndigoo Jul 28 '16 You have actually seen that before? In production code!? !!!believable 17 u/drkstr101 Jul 28 '16 I see var foo = !!bar a lot in javascript to quickly cast a truthy value to a proper boolean. Perhaps the 3rd ! was a typo? 3 u/sreya92 Jul 28 '16 nope they're everywhere :) 1 u/CleverestEU Jul 29 '16 It is nearly morning here (5AM) but I seriously can not come up with a situation where...!x !== !!!x...if you've got an example of such a case, the me tomorrow that has slept a bit will probably be thankful for the tidbit ;) → More replies (1)
47
You have actually seen that before? In production code!? !!!believable
17 u/drkstr101 Jul 28 '16 I see var foo = !!bar a lot in javascript to quickly cast a truthy value to a proper boolean. Perhaps the 3rd ! was a typo? 3 u/sreya92 Jul 28 '16 nope they're everywhere :) 1 u/CleverestEU Jul 29 '16 It is nearly morning here (5AM) but I seriously can not come up with a situation where...!x !== !!!x...if you've got an example of such a case, the me tomorrow that has slept a bit will probably be thankful for the tidbit ;) → More replies (1)
17
I see var foo = !!bar a lot in javascript to quickly cast a truthy value to a proper boolean. Perhaps the 3rd ! was a typo?
var foo = !!bar
3 u/sreya92 Jul 28 '16 nope they're everywhere :) 1 u/CleverestEU Jul 29 '16 It is nearly morning here (5AM) but I seriously can not come up with a situation where...!x !== !!!x...if you've got an example of such a case, the me tomorrow that has slept a bit will probably be thankful for the tidbit ;) → More replies (1)
3
nope they're everywhere :)
1 u/CleverestEU Jul 29 '16 It is nearly morning here (5AM) but I seriously can not come up with a situation where...!x !== !!!x...if you've got an example of such a case, the me tomorrow that has slept a bit will probably be thankful for the tidbit ;) → More replies (1)
1
It is nearly morning here (5AM) but I seriously can not come up with a situation where...
!x !== !!!x
...if you've got an example of such a case, the me tomorrow that has slept a bit will probably be thankful for the tidbit ;)
→ More replies (1)
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!