Content with Style

Web Technique

abbr. Fri

by Matthias Willerich on October 1 2010, 12:33

This is not at all from us, but from my colleague Andrew, who showed them to me last Friday in Perl.

I am not sure if I would use either of those in production code, it's... slightly cheeky. Nevertheless, enjoy:

<?php
//turn anything into a boolean
$boolean_flag = !! $any_variable;
//does the same as
$boolean_flag = (bool) $any_variable;

I like the importance the double exclamation marks trigger when you read this in code. IT'S LIKE WHEN PEOPLE WRITE MUNDANE STUFF IN CAPS!!

<?php
//I'm clearly iterating towards 0
$counter = 100;
while($counter-->0) {
	//do stuff
}
//does the same as
$counter = 100;
while($counter > 0) {
	$counter--;
	//do stuff
}

This one's great, too. The arrow seems to make the loop a very dynamic element. Great, have I really just explained my joke post? Shocking, I must get out more. If you've been inside for too long, let me know what unusual syntax you've come across.

Comments

  • Ha, I take your "I must get out more" and raise you the fact that I haven't left the house for 7 days straight now.

    by Pascal Opitz on October 1 2010, 16:54 #

  • $counter = 100; while($counter--) { // do stuff.. but prettier :) }

    by Carl Helmertz on October 1 2010, 18:52 #