do_this and die();

18
I WILL KILL YOU AKA, do_this() and die; AKA, things that piss me off Sawyer X ( ) @PerlSawyer

Upload: xsawyer

Post on 08-May-2015

210 views

Category:

Technology


0 download

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.

TRANSCRIPT

Page 1: do_this and die();

I WILL KILL YOUAKA, do_this() and die;

AKA, things that piss me off

Sawyer X ( )@PerlSawyer

Page 2: do_this and die();

WORDS OF CAUTIONTIMTOWTDIYour mileage may varyNo batteries includedDon't drink and drive

And lastly...

Page 3: do_this and die();

SMALL PROBLEMSunless()Postfix if()

Page 4: do_this and die();

REALLY STUPID STUFF$a, $b,$i, $j, $k, $l, $m, $n$f, $u, $c, $k, $y, $o, $uTrailing spaces STOP IT!$var, @array, %hash

Page 5: do_this and die();

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

Page 6: do_this and die();

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;

Page 7: do_this and die();

SWITCHESif ($one) {...}elsif ($two) {...}elsif ($three) {...}else {...}

my %dispatch = ( $one => sub {...}, $two => sub {...}, $three => sub {...},);

if ( exists $dispatch{$input} ) { $dispatch{$input}->(...);} else {...}

Page 8: do_this and die();

EMPTY IF CLAUSEif ($something) { # do nothing} else { # the actual work}

Page 9: do_this and die();

RETURN VARIABLESmy $return;

if ($this) { ... $return = 'this';} elsif ($another_thing) { ... $return = 'that';}

return $return;

Page 10: do_this and die();

CLASS METHODSSome::Class->my_method

Page 11: do_this and die();

WORKFLOW TRY/CATCHNOT FOR WORKFLOW!

Page 12: do_this and die();

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;

Page 13: do_this and die();

WHY?Because code is alive and grows

Sometimes to ridiculous age

You might not be the last

And the next might know your address

Page 14: do_this and die();

THANK YOU

Page 15: do_this and die();

HIDDEN SLIDES

Page 16: do_this and die();

AN ODD ODETO A SPECIAL SOMEONE...

Page 17: do_this and die();

You are the air beneath my wings

You are the sunlight in my garden

And I am happy you are here

Page 18: do_this and die();

And to Cluj.pm...I warned you!