garote: (machine)
[personal profile] garote
''        ==   '0'           // false
0         ==   ''            // true
0         ==   '0'           // true
!0        ==   true          // true
!1        ==   false         // true
false     ==   'false'       // false
false     ==   '0'           // true
false     ==   undefined     // false
false     ==   null          // false
null      ==   undefined     // true
" \t\r\n" ==   0             // true
NaN       ===  NaN           // false
!!NaN     ===  !!NaN         // true
I recently saw someone prefacing their code with
var t=!0;
... Because they wanted to save space in their code by replacing every occurrence of true with t, and also wanted so save two bytes while declaring what t was.

And I thought Perl invited abuse!

If you see anyone doing this, pour your drink on their head.

Date: 2013-03-16 03:18 am (UTC)
From: [identity profile] beatings.livejournal.com
I see nothing wrong with abusing constructs like "!0",... HOWEVER! ...

In the interest of creating human-readable and maintainable code, such hacks should only be applied by machines in a pre-processing phase. (Such as JS minify'rs. "!0" is something that a smart JS compressor ought to handle for you.)

Recently I found a JS compressor that builds an array of every alphanumeric word used in your code, then packs the code as a series of digits and performs a massive search-and-replace-and-then-eval() at runtime.

Also: The PHP truth table.

Also: All languages are terrible in specific ways.

</rant>

Date: 2013-03-16 03:23 am (UTC)
From: [identity profile] beatings.livejournal.com
Yarggg, that truth table. array() == NULL, everybody!
Edited Date: 2013-03-16 03:24 am (UTC)

Date: 2013-03-16 12:25 pm (UTC)
From: [identity profile] nibot.livejournal.com
Well, PHP is worse. :-/

"NaN == NaN" is false by IEEE standard. However, the whole idea of "!NaN" (logical negation of NaN?!) is crazy.

Profile

garote: (Default)
garote

June 2025

S M T W T F S
1234567
891011 121314
15161718192021
2223 2425262728
2930     

Most Popular Tags

Page generated Jul. 1st, 2025 07:17 am