SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
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.




         

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

Similar a Red Flags in Programming

Similar 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
 
test ppt
test ppttest ppt
test ppt
 
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
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
name name2 n
name name2 nname name2 n
name name2 n
 

Más de 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
 

Más 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

Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 

Último (20)

Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 

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.