SlideShare uma empresa Scribd logo
1 de 31
Red Flags in Programming




    Doing things that are probably...
                    not good for us


                           
Some words of caution...

    ­ We Perlers have a saying...
       TIMTOWTDI
    ­ Be nice, no flaming
       (only I'm allowed)
    ­ Not a Perl lecture, more like “bad
       programming habits”
    ­ “Your mileage may vary”, “no batteries
       included”, “don't drink and drive”
                        
:
     #1 
    ag
              Repeated code
Fl



­ We overlook repeated patterns without even noticing
­ N more to read, understand, debug, test, maintain
­ N more places to have bugs!
­ Updating multiple places is error prone..
   ­ it's boring
   ­ distracting
   ­ lose focus
   ­ make mistakes
   ­ OMFG BUGZ!
­ Really, the worst thing a programmer can do
                             
:
     #1 
    ag
               Repeated code
Fl



­ Abstract your code... correctly!
   ­ Class?
   ­ Abstract Class? (role)
   ­ Package?
   ­ Collection of Functions?
   ­ Loops?
   ­ Switches?
   ­ Dispatch tables?


                               
:
     #2 
    ag
             Reinvent the Wheel
Fl



­ You probably won't do it better... seriously
­ Development and maintenance grows because you 
now have another (usually big) chunk of code
­ It's just repeated code, really...




                           
:
     #2 
    ag
               Reinvent the Wheel
Fl



­ Modules
­ Libraries
­ Roles
­ Frameworks
­ Whatever the hell [Free] Pascal has
­ Write patches for what doesn't work for you
­ In extreme cases reinvent, but try to implement
as little as required.
­ Sometimes it's necessary to do it all from scratch:
Perlbal, Git, Linux :)
                               
:
     #3 
    ag
               Switches without default
Fl



­ Not always wrong                   if ( is_alpha($num)    ) {}
­ Usually wrong
­ Unexpected behavior              elsif ( is_numeric($num) ) {}
­ Not the worst of things...
   but please think of it




                                
:
     #3 
    ag
           Switches without default
Fl



                            if ( is_alpha($num)   ) {}
                        elsif ( is_numeric($num) ) {}
                        else {
                        }




                     
:
     #4 
    ag
                Long Switches
Fl



­ Gross, really                     given ($foo) {
­ Not fun to read or debug
­ Not easily maintainable               when (/^10$/) {}
­ It's basically a long if()            when (/^20$/) {}
elsif()... even if seems                when (/^30$/) {}
otherwise                               default      {}
                                    }


                                 
:
     #4 
    ag
              Long Switches
Fl



­ Dispatch tables               my %dispatch = (
    (if you can)
­ Use code references in             10 => CODEREF,
switches instead of code             20 => CODEREF,
itself
                                     30 => CODEREF,
    (if you can)
                                );


                                $dispatch{$num}->();
                             
:
    #5
     
 ag
              Try and Catch (workflow)
Fl



­ Try and Catch isn't for          try {
workflow!!
­ That's what we have                  do_something_simple();
conditions and loops for           } catch {
­ Internal functions should 
                                       print “Dear god, this is a
have return codes, not 
throw exceptions                   really stupid thing to do!”;
­ PHP is fscking stupid            }
­ Try and Catch is for when 
external functions might 
crash the program
                                
:
     #5 
    ag
              Try and Catch (workflow)
Fl



­ Functions, subroutines,         do_something_simple()
return codes!
­ Try and Catch is for              or die “you suck!n”;
external programs or 
things that are suppose to 
crash




                               
:
     #6 
    ag
              String Booleans
Fl



­ The string “false” is                if ( $bool eq 'true' ) {
actually true => confusing!
­ Unnecessary value                   DO SOMETHING
check/comparison                  } elsif ( $bool eq 'false' ) {
­ Misses the point of 
                                      DO SOMETHING
booleans.
                                  }
                                  $bool = 'false';
                                  if ( $bool ) { BUG }
                               
:
     #6 
    ag
               String Booleans
Fl



­ Use real booleans               $bool = do_that(@params);
­ Use zero (0), empty 
strings and undefined 
variables                         if ($bool) {
­ Sometimes you can't 
                                      # wheee... actual booleans
control it (using modules, 
etc.)                             }




                               
:
     #7 
    ag
              External Binaries
Fl



­ Compatibility problems
­ Portability problems
­ Unexpected results (`ps` for example is different on BSD 
and has different command line switches)
­ Insecure!




                              
:
     #7 
    ag
              External Binaries
Fl



­ Shared libraries
­ Bindings
­ APIs
­ libcurl is an example
­ Modules for running binaries more safely and controllably 
(IPC::Open3, IPC::Open3::Simple, IPC::Cmd, 
Capture::Tiny)
­ Taint mode (if language supports it – Perl does!)
­ Sometimes you can't control it (external binaries, closed 
programs, dependencies at $work)
                              
:
     #8 
    ag
              Intermediate Programs
Fl



­ Quite possibly insecure
­ Hard to maintain
­ No damned syntax highlighting!!!11




                             
:
     #8 
    ag
              Intermediate Programs
Fl



­ If same language, use a subroutine/function
­ Different language && use an Inline module
­ Else, use templates
­ External file




                             
:
     #9 
    ag
                Empty if() Clauses
Fl



­ Not DWIM/SWYM                    if ( $something ) {
­ Having an empty if() for 
the sake of the else().. is            # do nothing
horrible                           } else {
                                       CODE
                                   }




                                
:
      #9 
     ag
               Empty if() Clauses
Fl



­ SWYM... please?                 if ( !$something ) {
­ Use unless() [Perl]
­ Don't really use unless()           CODE
                                  }
                                  unless ( $something ) {
                                      CODE
                                  }

* Shlomi Fish is allowed to do otherwise :)
                               
0:
     #1 
    ag
             Array Counters
Fl



­ Some older languages          foreach my $i ( 0 .. $n ) {
have no way to know how 
many elements are in an             $array[$i] = 'something';
array...                            $array_counter++;
­ Some people are too 
                                }
used to older (more low­
level) languages
­ Some people don't know 
there's a better way

                             
0:
     #1 
    ag
              Array Counters
Fl



­ Higher level languages 
have no problem
­ Using the number of the        print $#array + 1;
last element
­ The number of elements
                                 print scalar @array;




                              
1:
     #1 
    ag
              Variable abuse
Fl



­ Are you kidding me?             sub calc_ages {
­ Awful awful awful
­ The reasons people get              my ( $age1, $age2, $age3,
their hands chopped off in        $age4 ) = @_;
indigenous countries
                                  }


                                  calc_ages( $age1, $age2,
                                  $age3, $age4 );
                               
1:
     #1 
    ag
             Variable Abuse
Fl



­ That's why we have            my @ages = @_;
compound data structures 
(arrays, hashes)                my %people = (
­ Even more complex data             dad => {
structures, if you want
                                          brothers => [],
                                          sisters   => [],
                                          },
                                     },
                                };
2:
     #1 
    ag
              C Style for() Loop
Fl



­ Not really an issue        for ( $i = 0; $i < 10; $i++ ) {
­ Harder to understand
­ And just not needed            …
                             }




                          
2:
     #1 
    ag
              C Style for() Loop
Fl



­ Higher level languages          foreach my $var (@vars) {
have better/cooler things
­ foreach (where available)           ...
                                  }




                               
3:
     #1 
    ag
               Goto Hell
Fl



­ OMGWTF?!1                     if ( something_happened() ) {
­ But seriously folks, goto() 
strips away all of our ability      WHINE: say_it('happened');
to profoundly express               my $care = your($feelings);
ourselves using languages 
                                    if ( !$care ) {
that finally let us
­ And yes, if you use                   goto WHINE;
goto(), I also think your           }
mother is promiscuous
                                }
                                
3:
     #1 
    ag
              Goto Hell
Fl



­ DON'T USE GOTO!              if ( something_happened() ) {
­ You're not a hardcore 
assembly programmer,               my $care;
you shouldn't have                 while ( !$care ) {
spaghetti code
                                       say_it('happened');
­ Even xkcd agrees with 
me!                                    $care = your($feelings);
                                   }
                               }
                            
     
ff
           tu
         s
     od           Dry, Rinse, Repeat
   go
 e 
m
so




 DRY (Don't Repeat Yourself)
 Don't duplicate code, abstract it!

 KISS (Keep It Simple, Stupid)
 Don't write overtly complex stuff. Clean design yields 
   clean code. (yet some things are complex, I know...)

 YAGNI (You Aren't Gonna Need It)
  Start from what you need. Work your way up.
                               
Thank you.




         

Mais conteúdo relacionado

Mais procurados

Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
Wen-Tien Chang
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
Joe Jiang
 
WTFin Perl
WTFin PerlWTFin Perl
WTFin Perl
lechupl
 

Mais procurados (20)

Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...
 
PerlScripting
PerlScriptingPerlScripting
PerlScripting
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Cleancode
CleancodeCleancode
Cleancode
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
PerlTesting
PerlTestingPerlTesting
PerlTesting
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Ruby 2.0
Ruby 2.0Ruby 2.0
Ruby 2.0
 
WTFin Perl
WTFin PerlWTFin Perl
WTFin Perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
 
lab4_php
lab4_phplab4_php
lab4_php
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Mastering Grammars with PetitParser
Mastering Grammars with PetitParserMastering Grammars with PetitParser
Mastering Grammars with PetitParser
 

Semelhante a Red Flags in Programming

Semelhante a Red Flags in Programming (20)

Ruby Gotchas
Ruby GotchasRuby Gotchas
Ruby Gotchas
 
Ruby Gotchas
Ruby GotchasRuby Gotchas
Ruby Gotchas
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
ShellProgramming and Script in operating system
ShellProgramming and Script in operating systemShellProgramming and Script in operating system
ShellProgramming and Script in operating system
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 

Mais de xSawyer

Mais de xSawyer (14)

do_this and die();
do_this and die();do_this and die();
do_this and die();
 
XS Fun
XS FunXS Fun
XS Fun
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Asynchronous programming FTW!
Asynchronous programming FTW!Asynchronous programming FTW!
Asynchronous programming FTW!
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
 
Our local state, my, my - Understanding Perl variables
Our local state, my, my - Understanding Perl variablesOur local state, my, my - Understanding Perl variables
Our local state, my, my - Understanding Perl variables
 
Your first website in under a minute with Dancer
Your first website in under a minute with DancerYour first website in under a minute with Dancer
Your first website in under a minute with Dancer
 
Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)
 
Perl Dancer for Python programmers
Perl Dancer for Python programmersPerl Dancer for Python programmers
Perl Dancer for Python programmers
 
When Perl Met Android (YAPC::EU 2010)
When Perl Met Android (YAPC::EU 2010)When Perl Met Android (YAPC::EU 2010)
When Perl Met Android (YAPC::EU 2010)
 
Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)
 
Source Code Management systems
Source Code Management systemsSource Code Management systems
Source Code Management systems
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Red Flags in Programming

  • 1. Red Flags in Programming Doing things that are probably... not good for us    
  • 2. Some words of caution... ­ We Perlers have a saying... TIMTOWTDI ­ Be nice, no flaming (only I'm allowed) ­ Not a Perl lecture, more like “bad programming habits” ­ “Your mileage may vary”, “no batteries   included”, “don't drink and drive”  
  • 3. : #1  ag Repeated code Fl ­ We overlook repeated patterns without even noticing ­ N more to read, understand, debug, test, maintain ­ N more places to have bugs! ­ Updating multiple places is error prone.. ­ it's boring ­ distracting ­ lose focus ­ make mistakes ­ OMFG BUGZ! ­ Really, the worst thing a programmer can do    
  • 4. : #1  ag Repeated code Fl ­ Abstract your code... correctly! ­ Class? ­ Abstract Class? (role) ­ Package? ­ Collection of Functions? ­ Loops? ­ Switches? ­ Dispatch tables?    
  • 5. : #2  ag Reinvent the Wheel Fl ­ You probably won't do it better... seriously ­ Development and maintenance grows because you  now have another (usually big) chunk of code ­ It's just repeated code, really...    
  • 6. : #2  ag Reinvent the Wheel Fl ­ Modules ­ Libraries ­ Roles ­ Frameworks ­ Whatever the hell [Free] Pascal has ­ Write patches for what doesn't work for you ­ In extreme cases reinvent, but try to implement as little as required. ­ Sometimes it's necessary to do it all from scratch: Perlbal, Git, Linux :)    
  • 7. : #3  ag Switches without default Fl ­ Not always wrong if ( is_alpha($num) ) {} ­ Usually wrong ­ Unexpected behavior elsif ( is_numeric($num) ) {} ­ Not the worst of things... but please think of it    
  • 8. : #3  ag Switches without default Fl if ( is_alpha($num) ) {} elsif ( is_numeric($num) ) {} else { }    
  • 9. : #4  ag Long Switches Fl ­ Gross, really given ($foo) { ­ Not fun to read or debug ­ Not easily maintainable when (/^10$/) {} ­ It's basically a long if()  when (/^20$/) {} elsif()... even if seems  when (/^30$/) {} otherwise default {} }    
  • 10. : #4  ag Long Switches Fl ­ Dispatch tables my %dispatch = ( (if you can) ­ Use code references in  10 => CODEREF, switches instead of code  20 => CODEREF, itself 30 => CODEREF, (if you can) ); $dispatch{$num}->();    
  • 11. : #5   ag Try and Catch (workflow) Fl ­ Try and Catch isn't for  try { workflow!! ­ That's what we have  do_something_simple(); conditions and loops for } catch { ­ Internal functions should  print “Dear god, this is a have return codes, not  throw exceptions really stupid thing to do!”; ­ PHP is fscking stupid } ­ Try and Catch is for when  external functions might  crash the program    
  • 12. : #5  ag Try and Catch (workflow) Fl ­ Functions, subroutines,  do_something_simple() return codes! ­ Try and Catch is for  or die “you suck!n”; external programs or  things that are suppose to  crash    
  • 13. : #6  ag String Booleans Fl ­ The string “false” is  if ( $bool eq 'true' ) { actually true => confusing! ­ Unnecessary value  DO SOMETHING check/comparison } elsif ( $bool eq 'false' ) { ­ Misses the point of  DO SOMETHING booleans. } $bool = 'false'; if ( $bool ) { BUG }    
  • 14. : #6  ag String Booleans Fl ­ Use real booleans $bool = do_that(@params); ­ Use zero (0), empty  strings and undefined  variables if ($bool) { ­ Sometimes you can't  # wheee... actual booleans control it (using modules,  etc.) }    
  • 15. : #7  ag External Binaries Fl ­ Compatibility problems ­ Portability problems ­ Unexpected results (`ps` for example is different on BSD  and has different command line switches) ­ Insecure!    
  • 16. : #7  ag External Binaries Fl ­ Shared libraries ­ Bindings ­ APIs ­ libcurl is an example ­ Modules for running binaries more safely and controllably  (IPC::Open3, IPC::Open3::Simple, IPC::Cmd,  Capture::Tiny) ­ Taint mode (if language supports it – Perl does!) ­ Sometimes you can't control it (external binaries, closed  programs, dependencies at $work)    
  • 17. : #8  ag Intermediate Programs Fl ­ Quite possibly insecure ­ Hard to maintain ­ No damned syntax highlighting!!!11    
  • 18. : #8  ag Intermediate Programs Fl ­ If same language, use a subroutine/function ­ Different language && use an Inline module ­ Else, use templates ­ External file    
  • 19. : #9  ag Empty if() Clauses Fl ­ Not DWIM/SWYM if ( $something ) { ­ Having an empty if() for  the sake of the else().. is  # do nothing horrible } else { CODE }    
  • 20. : #9  ag Empty if() Clauses Fl ­ SWYM... please? if ( !$something ) { ­ Use unless() [Perl] ­ Don't really use unless() CODE } unless ( $something ) { CODE } * Shlomi Fish is allowed to do otherwise :)    
  • 21. 0: #1  ag Array Counters Fl ­ Some older languages  foreach my $i ( 0 .. $n ) { have no way to know how  many elements are in an  $array[$i] = 'something'; array... $array_counter++; ­ Some people are too  } used to older (more low­ level) languages ­ Some people don't know  there's a better way    
  • 22. 0: #1  ag Array Counters Fl ­ Higher level languages  have no problem ­ Using the number of the  print $#array + 1; last element ­ The number of elements print scalar @array;    
  • 23. 1: #1  ag Variable abuse Fl ­ Are you kidding me? sub calc_ages { ­ Awful awful awful ­ The reasons people get  my ( $age1, $age2, $age3, their hands chopped off in  $age4 ) = @_; indigenous countries } calc_ages( $age1, $age2, $age3, $age4 );    
  • 24. 1: #1  ag Variable Abuse Fl ­ That's why we have  my @ages = @_; compound data structures  (arrays, hashes) my %people = ( ­ Even more complex data  dad => { structures, if you want brothers => [], sisters => [], }, },     };
  • 25. 2: #1  ag C Style for() Loop Fl ­ Not really an issue for ( $i = 0; $i < 10; $i++ ) { ­ Harder to understand ­ And just not needed … }    
  • 26. 2: #1  ag C Style for() Loop Fl ­ Higher level languages  foreach my $var (@vars) { have better/cooler things ­ foreach (where available) ... }    
  • 27. 3: #1  ag Goto Hell Fl ­ OMGWTF?!1 if ( something_happened() ) { ­ But seriously folks, goto()  strips away all of our ability  WHINE: say_it('happened'); to profoundly express  my $care = your($feelings); ourselves using languages  if ( !$care ) { that finally let us ­ And yes, if you use  goto WHINE; goto(), I also think your  } mother is promiscuous }    
  • 28. 3: #1  ag Goto Hell Fl ­ DON'T USE GOTO! if ( something_happened() ) { ­ You're not a hardcore  assembly programmer,  my $care; you shouldn't have  while ( !$care ) { spaghetti code say_it('happened'); ­ Even xkcd agrees with  me! $care = your($feelings); } }    
  • 29.    
  • 30. ff tu  s od Dry, Rinse, Repeat go e  m so  DRY (Don't Repeat Yourself) Don't duplicate code, abstract it!  KISS (Keep It Simple, Stupid) Don't write overtly complex stuff. Clean design yields  clean code. (yet some things are complex, I know...)  YAGNI (You Aren't Gonna Need It) Start from what you need. Work your way up.