SlideShare ist ein Scribd-Unternehmen logo
1 von 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.




         

Weitere ähnliche Inhalte

Was ist angesagt? (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
 

Ähnlich wie Red Flags in Programming

Ähnlich wie 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
 
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
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 

Mehr von xSawyer

do_this and die();
do_this and die();do_this and die();
do_this and die();xSawyer
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)xSawyer
 
Asynchronous programming FTW!
Asynchronous programming FTW!Asynchronous programming FTW!
Asynchronous programming FTW!xSawyer
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012xSawyer
 
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 variablesxSawyer
 
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 DancerxSawyer
 
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)xSawyer
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)xSawyer
 
Perl Dancer for Python programmers
Perl Dancer for Python programmersPerl Dancer for Python programmers
Perl Dancer for Python programmersxSawyer
 
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)xSawyer
 
Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)xSawyer
 
Source Code Management systems
Source Code Management systemsSource Code Management systems
Source Code Management systemsxSawyer
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)xSawyer
 

Mehr von 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)
 

Kürzlich hochgeladen

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Kürzlich hochgeladen (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

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.