SlideShare a Scribd company logo
1 of 29
ni.com
Code Smells
Part 1 – Basic Smells
Mark Ridgley
Owner, Radius Teknologies, LLC
About the Session Author
Mark Ridgley
CLD, CTA, CPI, LabVIEW Champion
Owner, Radius Teknologies, LLC
What’s in it for me?
 What a code smell is
 What the most common code smells are
 Why code smells happen
 The good news about code smells
 Why you should be concerned about code smells
 What you can do when you encounter a code smell
 Tools to help eradicate code smells
You’ll learn:
What is a code smell?
Code Smell – A symptom in the source code that possibly indicates a
deeper problem
Definition
Common Code Smells
 Poor naming
 Overly complicated
 Contrived complexity
 Too many modules
 Duplicate logic
 Disorganization
 Breaks dataflow
 Outdated practices
 Too many parameters
 Excessive use of literals
 Cyclomatic complexity
 Others???
Why do code smells happen?
 Time constraints
 We are pressured to look for the quickest implementation instead of the best
implementation
 “If it runs, it’s done.”
 Start coding without requirements
 Cut/Paste/Rename
 Easy and fast ‘reuse’
 Development team size
 No ownership of code
There is good news, though…
A code smell:
 Is not a Bug
 Is not technically incorrect
 Does not currently prevent the code from functioning
If these statements are true, then why should we be concerned?
Why be concerned?
 Code smells:
 Make code less readable
 Make code less maintainable
 Affect all phases of the software lifecycle
 Development
 Support
 Troubleshooting
 Modification
 Maintenance
 May lead to bugs
What can we do?
 Be vigilant – Code smells are all around us
 We just have to look for them
 Can be in any code (LabVIEW VIs, TestStand sequences)
 Don’t look the other way when you discover a code smell
 Take the initiative and time to refactor the code
 If you don’t, who will?
Refactoring
Refactoring – The process of redesigning software to make it more
readable and maintainable so that the cost of change does not increase
over time
Definition
When to Refactor
 When you are adding features to or debugging your source code
Demonstrations
Code From The Real-World
(You can’t make this stuff up!)
Demonstration
Poor Naming
 Excessively short identifiers
 Excessively long identifiers
Demonstration
Overly Complicated
Demonstration
Contrived Complexity
 Complexity for complexity’s sake
Can you easily
determine the
functionality of
the code in the
while loop?
Demonstration
Too Many Modules
Demonstration
Evolution of a Code Smell
Demonstration
Duplicate Logic
Demonstration
Disorganization
Demonstration
Breaks Dataflow
Demonstration
Outdated Practices
Demonstration
Too Many Parameters
Demonstration
Excessive Use of Literals
Demonstration
Cyclomatic Complexity
 Function or method has too many branches or loops
 Complicates testing and troubleshooting
 Indicates that the code should be simplified
Tools to Help Eradicate Code Smells
 LabVIEW: VI Analyzer
 Tools >> VI Analyzer >> Analyze VIs…
 TestStand: Sequence Analyzer
 Debug >> Sequence Analyzer >> Analyze <Sequence Name>
Topics Covered
 Poor naming
 Overly complicated
 Contrived complexity
 Too many modules
 Duplicate logic
 Disorganization
 Breaks dataflow
 Outdated practices
 Too many parameters
 Excessive use of literals
 Cyclomatic complexity
 Tools to help eradicate code smells
Next Steps
 Learn more about detecting and correcting smelly code
 LabVIEW Help
 Search “VI Analyzer, analyzing an open VI”
 TestStand Help
 Search “TestStand Sequence Analyzer”
Questions / Comments
Mark Ridgley
CLD, CTA, CPI, LabVIEW Champion
Owner, Radius Teknologies, LLC
Thank You!

More Related Content

What's hot

Comparing the code quality of ECMs
Comparing the code quality of ECMsComparing the code quality of ECMs
Comparing the code quality of ECMsNuxeo
 
Test Driven Development Part 1
Test Driven Development Part 1Test Driven Development Part 1
Test Driven Development Part 1Gamal Shaban
 
Agile analysis development
Agile analysis developmentAgile analysis development
Agile analysis developmentsetitesuk
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestableRoyKlein
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDDavid Rodenas
 
Code Review
Code ReviewCode Review
Code ReviewTu Hoang
 
Code Review
Code ReviewCode Review
Code Reviewrantav
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your codePascal Larocque
 
Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Aditya Bhuyan
 
Seeding a Tree in a Gherkin
Seeding a Tree in a GherkinSeeding a Tree in a Gherkin
Seeding a Tree in a GherkinPaul Rohorzka
 
Tdd practices
Tdd practicesTdd practices
Tdd practicesaxykim00
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Editionjexp
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven DevelopmentLim Chanmann
 
Importance of the quality of code
Importance of the quality of codeImportance of the quality of code
Importance of the quality of codeShwe Yee
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and WhenPaul Gower
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...VincitOy
 

What's hot (20)

Comparing the code quality of ECMs
Comparing the code quality of ECMsComparing the code quality of ECMs
Comparing the code quality of ECMs
 
Tdd com Java
Tdd com JavaTdd com Java
Tdd com Java
 
Test Driven Development Part 1
Test Driven Development Part 1Test Driven Development Part 1
Test Driven Development Part 1
 
Agile analysis development
Agile analysis developmentAgile analysis development
Agile analysis development
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestable
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
 
Tdd
TddTdd
Tdd
 
Code Review
Code ReviewCode Review
Code Review
 
Code Review
Code ReviewCode Review
Code Review
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)
 
Seeding a Tree in a Gherkin
Seeding a Tree in a GherkinSeeding a Tree in a Gherkin
Seeding a Tree in a Gherkin
 
Tdd practices
Tdd practicesTdd practices
Tdd practices
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
Ensuring Software Quality in the cloud
Ensuring Software Quality in the cloudEnsuring Software Quality in the cloud
Ensuring Software Quality in the cloud
 
Importance of the quality of code
Importance of the quality of codeImportance of the quality of code
Importance of the quality of code
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and When
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
 
Code Quality
Code QualityCode Quality
Code Quality
 

Similar to Code Smells Part 1: Basic Smells

Waste Driven Development - Agile Coaching Serbia Meetup
Waste Driven Development - Agile Coaching Serbia MeetupWaste Driven Development - Agile Coaching Serbia Meetup
Waste Driven Development - Agile Coaching Serbia MeetupLemi Orhan Ergin
 
How To Tidy Up Your Test Code
How To Tidy Up Your Test CodeHow To Tidy Up Your Test Code
How To Tidy Up Your Test CodeRock Interview
 
Stop fearing legacy code
Stop fearing legacy codeStop fearing legacy code
Stop fearing legacy codeYaki Koren
 
Revisiting refactoring
Revisiting refactoringRevisiting refactoring
Revisiting refactoringNick Harrison
 
Revisiting Refactoring
Revisiting RefactoringRevisiting Refactoring
Revisiting RefactoringNick Harrison
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@Alex Borsuk
 
Code smells quality of code
Code smells   quality of codeCode smells   quality of code
Code smells quality of codeHasan Al Mamun
 
Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design PatternsLiraz Shay
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Developmentsatya sudheer
 
Unit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonUnit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonSeb Rose
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...DevDay.org
 
Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015Mirco Hering
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionPyxis Technologies
 
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Abdelkrim Boujraf
 
DevOps The Cultural revolution
DevOps The Cultural revolutionDevOps The Cultural revolution
DevOps The Cultural revolutionSomenath Ghosh
 

Similar to Code Smells Part 1: Basic Smells (20)

Waste Driven Development - Agile Coaching Serbia Meetup
Waste Driven Development - Agile Coaching Serbia MeetupWaste Driven Development - Agile Coaching Serbia Meetup
Waste Driven Development - Agile Coaching Serbia Meetup
 
How To Tidy Up Your Test Code
How To Tidy Up Your Test CodeHow To Tidy Up Your Test Code
How To Tidy Up Your Test Code
 
Put to the Test
Put to the TestPut to the Test
Put to the Test
 
Stop fearing legacy code
Stop fearing legacy codeStop fearing legacy code
Stop fearing legacy code
 
Code smell overview
Code smell overviewCode smell overview
Code smell overview
 
Revisiting refactoring
Revisiting refactoringRevisiting refactoring
Revisiting refactoring
 
Revisiting Refactoring
Revisiting RefactoringRevisiting Refactoring
Revisiting Refactoring
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Code smells quality of code
Code smells   quality of codeCode smells   quality of code
Code smells quality of code
 
Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design Patterns
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Development
 
Testing and symfony2
Testing and symfony2Testing and symfony2
Testing and symfony2
 
Unit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonUnit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking Skeleton
 
Mine Your Own Code
Mine Your Own CodeMine Your Own Code
Mine Your Own Code
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
 
Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
 
Code quality
Code quality Code quality
Code quality
 
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
 
DevOps The Cultural revolution
DevOps The Cultural revolutionDevOps The Cultural revolution
DevOps The Cultural revolution
 

Recently uploaded

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 

Recently uploaded (20)

Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 

Code Smells Part 1: Basic Smells

  • 1. ni.com Code Smells Part 1 – Basic Smells Mark Ridgley Owner, Radius Teknologies, LLC
  • 2. About the Session Author Mark Ridgley CLD, CTA, CPI, LabVIEW Champion Owner, Radius Teknologies, LLC
  • 3. What’s in it for me?  What a code smell is  What the most common code smells are  Why code smells happen  The good news about code smells  Why you should be concerned about code smells  What you can do when you encounter a code smell  Tools to help eradicate code smells You’ll learn:
  • 4. What is a code smell? Code Smell – A symptom in the source code that possibly indicates a deeper problem Definition
  • 5. Common Code Smells  Poor naming  Overly complicated  Contrived complexity  Too many modules  Duplicate logic  Disorganization  Breaks dataflow  Outdated practices  Too many parameters  Excessive use of literals  Cyclomatic complexity  Others???
  • 6. Why do code smells happen?  Time constraints  We are pressured to look for the quickest implementation instead of the best implementation  “If it runs, it’s done.”  Start coding without requirements  Cut/Paste/Rename  Easy and fast ‘reuse’  Development team size  No ownership of code
  • 7. There is good news, though… A code smell:  Is not a Bug  Is not technically incorrect  Does not currently prevent the code from functioning If these statements are true, then why should we be concerned?
  • 8. Why be concerned?  Code smells:  Make code less readable  Make code less maintainable  Affect all phases of the software lifecycle  Development  Support  Troubleshooting  Modification  Maintenance  May lead to bugs
  • 9. What can we do?  Be vigilant – Code smells are all around us  We just have to look for them  Can be in any code (LabVIEW VIs, TestStand sequences)  Don’t look the other way when you discover a code smell  Take the initiative and time to refactor the code  If you don’t, who will?
  • 10. Refactoring Refactoring – The process of redesigning software to make it more readable and maintainable so that the cost of change does not increase over time Definition
  • 11. When to Refactor  When you are adding features to or debugging your source code
  • 12. Demonstrations Code From The Real-World (You can’t make this stuff up!)
  • 13. Demonstration Poor Naming  Excessively short identifiers  Excessively long identifiers
  • 15. Demonstration Contrived Complexity  Complexity for complexity’s sake Can you easily determine the functionality of the code in the while loop?
  • 24. Demonstration Cyclomatic Complexity  Function or method has too many branches or loops  Complicates testing and troubleshooting  Indicates that the code should be simplified
  • 25. Tools to Help Eradicate Code Smells  LabVIEW: VI Analyzer  Tools >> VI Analyzer >> Analyze VIs…  TestStand: Sequence Analyzer  Debug >> Sequence Analyzer >> Analyze <Sequence Name>
  • 26. Topics Covered  Poor naming  Overly complicated  Contrived complexity  Too many modules  Duplicate logic  Disorganization  Breaks dataflow  Outdated practices  Too many parameters  Excessive use of literals  Cyclomatic complexity  Tools to help eradicate code smells
  • 27. Next Steps  Learn more about detecting and correcting smelly code  LabVIEW Help  Search “VI Analyzer, analyzing an open VI”  TestStand Help  Search “TestStand Sequence Analyzer”
  • 28. Questions / Comments Mark Ridgley CLD, CTA, CPI, LabVIEW Champion Owner, Radius Teknologies, LLC

Editor's Notes

  1. Presenter Readme and Demo Script: Many slides in this presentation use builds. This means that some slides may contain multiple images that are displayed individually based on a mouse click. To view the presentation properly, you must be in slide show mode or reading view. If a slide has a demonstration that requires the LabVIEW development environment, the slide will feature a LabVIEW icon watermark on the left hand side of the slide as a reminder that demo code is available in the presentation LabVIEW project. The location of the demo files is listed in the slide notes. If a slide is not printed here, there are no notes associated with that slide.
  2. Slide: Common Code Smells Here is a list of common code smells. During the remainder of this presentation, we will look at examples and discuss ways of addressing them.
  3. Slide: Poor Naming Code smells aren’t just limited to LabVIEW. This slide shows variables in a TestStand sequence file. It illustrates both excessively short identifiers and excessively long identifiers. Ask the audience for some ideas for methods to correct the issue. Possible answers: Use names that help make the purpose of the software evident (self-documenting code) Adopt naming conventions Reasons for adopting naming conventions: Reduce the effort needed to read and understand source code Enable code reviews to focus on more important issues than arguing over syntax and naming standards Enable the use of automated refactoring or search and replace tools with minimal potential for error Enhance clarity in cases of potential ambiguity avoid "name collisions" that might occur when the work of different developers is combined Provide better understanding in case of code reuse after a long period of time
  4. Slide: Overly Complicated This slide shows overly complex VIs. Build 1: Shows a calculation implemented using nodes on the block diagram. Ask the audience what they would do to correct the issue. Build 2: Shows the code refactored to use a formula node to achieve the same result. There are demo VIs for the first two images. You can run them to show that the output is the same from the original code and the refactored code. The demos are located in 01 – Overly Complicated\Overly Complicated Demo 1.vi and Overly Complicated Demo 1_Formula Node.vi Build 3: Shows another example that is overly complicated. Ask the audience what they would do to correct the issue. (Possible answers: Create a Sub VI to replace the three case structures on the right side of the diagram, use a formula node to simplify the calculations) If needed, Demo VI is located in 01 – Overly Complicated\Overly Complicated Demo 2.vi.
  5. Slide: Contrived Complexity Build 1: This code was part of a much larger application. Ask the audience if they can easily determine the functionality of the code in the while loop. Open and run the demo VI (Demo is located in 02 - Contrived complexity\Contrived Complexity Demo.vi). If they haven’t already figured it out, tell the audience that the functionality of the loop is to strip the path of the current VI - Which could be greatly simplified by replacing the while loop with the built-in LabVIEW Strip Path function
  6. Slide: Too Many Modules Build 1: The customer was experiencing problems with RS232 communication. This slide shows a partial listing of the serial communication VIs found on the customer’s test system. Ask the audience for their initial thoughts about this directory listing. Does anything smell here? Build 2: Shows that this customer had 34 VIs for performing serial communication. Should we be surprised they were having problems?
  7. Slide: Evolution of a Code Smell Build 1: Shows the evolution of a code smell. It shows the VI name, the number of terminals on the connector pane and the number of connected terminals (Connector Density) for the directory shown in the previous slide. Beginning at the bottom, you can see the evolution by reading the VI name and examining the connector density. The evolution is clear as you progress up the list. For example beginning with the VI at the bottom of the list – We have “RS232 Read_Write_withlog.vi” with 7 of 12 connector terminals used. The next VI is “RS232 Read_Write_count.vi” with 8 of 12 terminals used. Some time after creating the first VI, the customer decided that they needed to output the byte count, so they copied and renamed the original VI and connected another output terminal. As their needs evolved, they followed this copy/rename/change connector development model. This example shows how code smells are innocently propagated and get worse over time. Ask the audience what they would do to improve this situation.
  8. Slide: Duplicate Logic Build 1: Shows a LabVIEW VI with duplicate logic. At least the author did try to be neat…BUT this code illustrates the problems with cut and paste. Point out the that the full block diagram is HUGE because the developer has made a copy of the code for each channel in the system. Mention the LabVIEW Navigation Window shown on the right side of the image in the slide. Demo the Navigation Pane if the audience is not familiar with it (Demo is located in 04 - Duplicate Logic\Navigation Window Demo\Navigation Window Demo.lvproj) (Press Ctrl + shift + N on the block diagram to open the Navigation Window). Ask the audience what they would do to improve this code. (Possible answers: Create a sub VI)
  9. Slide: Disorganization There are two example block diagrams in the slide. Click through to display each example. Build 1: Shows disorganized code. Build 2: Shows another example of disorganized code. Ask the audience what they would do to improve this code.
  10. Slide: Breaks Dataflow Build 1: Shows a portion of LabVIEW code that breaks dataflow by overusing global variables. Ask the audience if anything smells here. Tell the audience that you should use variables only when necessary. Use wires to transfer data whenever possible.
  11. Slide: Outdated Practices The demo VI associated with this slide implements an interactive switch control interface using a polling architecture. (Demo is located in 07 - Outdated Practices\Interactive_Switch_Control.VI). Run the VI to show its functionality, then show the block diagram and note that it uses a polling architecture. Ask the audience what they would do to improve this code (Possible answer: Refactor the code to use an event structure instead of polling.
  12. Slide: Too Many Parameters Build 1: Shows a VI icon / connector pane. Note that this VI is using the connector pane with 28 terminals – 20 of which are connected. Build 2: Shows what it might look like when you wire this VI on your block diagram. Ask the audience if anything smells here. VIs with this many parameters are difficult to wire. VIs with this many parameters indicate that the VI is doing too much work. Ask the audience how they might correct this. (possible answers: create sub VIs, pass parameters as a cluster)
  13. Slide: Excessive use of literals A literal is a value that has been hard-coded directly into your source code whose value is obvious when inspecting the code. Build 1: The image on this slide shows a VI for performing serial write and read to a COM port. Point out that most of the inputs to the VISA Configure Serial Port VI are implemented as literals. Ask the audience they can name some disadvantages to this approach.
  14. Slide: Cyclomatic Complexity Cyclomatic complexity measures the number of linearly independent paths in the block diagram code. It gives an indication on the amount of branching in the code and subsequently the recommended number of tests cases required to validate VI functionality. The demo VI associated with this slide has a cyclomatic complexity of 30. Code with high cyclomatic complexity is difficult to debug and maintain. Move some decision points (case structures, loops, etc.) into sub-VIs so that each module can be tested independently, and easily maintained. (Demo is located in 10 - Cyclomatic Complexity\Cyclomatic Complexity Demo.vi)