Tag: programming tidbits
March 18, 2012
Too Clever?
In many weakly-typed languages, such as Javascript and PHP, you might find code that takes some ambiguous value and coerces it into a straightforward boolean like so:
$boolean = (boolean) $mixed;
But what about this radically shorter alternative?
$boolean =…
The Beautiful Ternary
I am a fan of the ternary operator. Yes, it’s alien the first time you meet it, but wow, talk about getting things done! In a single line you can succinctly express a test and two options, making for truly compact yet clear…