Upload
xsawyer
View
210
Download
0
Embed Size (px)
DESCRIPTION
Various coding styles I hate seeing. It's a rant, but a fun one. Uses Spiderman to help illustrate my angst. This talk was originally given at Cluj.pm, on November 7th, 2013.
Citation preview
I WILL KILL YOUAKA, do_this() and die;
AKA, things that piss me off
Sawyer X ( )@PerlSawyer
WORDS OF CAUTIONTIMTOWTDIYour mileage may varyNo batteries includedDon't drink and drive
And lastly...
SMALL PROBLEMSunless()Postfix if()
REALLY STUPID STUFF$a, $b,$i, $j, $k, $l, $m, $n$f, $u, $c, $k, $y, $o, $uTrailing spaces STOP IT!$var, @array, %hash
TABS VS. SPACESThe eternal struggle
Do not mix tabs and spacesDo NOT mix tabs and spacesDO NOT mix tabs and spacesDO NOT MIX TABS AND SPACES!
Best rule? No tabs, only spaces
MISUNDERSTANDINGSmap without checking value
C-style for/foreach
# map EXPR,LISTmy %ages = map +( $_ => $kids{$_}{'age'} ), keys %kids;
# map BLOCK LISTmy @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, checksum($_) ] } @sizes;
# for/foreach LISTmy @kids = qw<jenny jeff john jackie jim john joan june jude josh>;for ( my $i = 0; $i < @kids; $i++ ) { say "-> $kids[$i]";}
foreach my $kid (@kids) { say "-> $kid";}
say "-> $_" for @kids;
SWITCHESif ($one) {...}elsif ($two) {...}elsif ($three) {...}else {...}
my %dispatch = ( $one => sub {...}, $two => sub {...}, $three => sub {...},);
if ( exists $dispatch{$input} ) { $dispatch{$input}->(...);} else {...}
EMPTY IF CLAUSEif ($something) { # do nothing} else { # the actual work}
RETURN VARIABLESmy $return;
if ($this) { ... $return = 'this';} elsif ($another_thing) { ... $return = 'that';}
return $return;
CLASS METHODSSome::Class->my_method
WORKFLOW TRY/CATCHNOT FOR WORKFLOW!
GOTO HELL;NOT FOR WORKFLOW!
# C label jumpsgoto HELL;
# somewhere elseHELL: continue_DBIx_Class_code();
# overrides the current frame in the stack# good, when necessarygoto &my_function;
WHY?Because code is alive and grows
Sometimes to ridiculous age
You might not be the last
And the next might know your address
THANK YOU
HIDDEN SLIDES
AN ODD ODETO A SPECIAL SOMEONE...
You are the air beneath my wings
You are the sunlight in my garden
And I am happy you are here
And to Cluj.pm...I warned you!