SlideShare a Scribd company logo
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 (20)

PPT
Comparing the code quality of ECMs
Nuxeo
 
PPTX
Tdd com Java
Rafael Miceli
 
PPT
Test Driven Development Part 1
Gamal Shaban
 
ODP
Agile analysis development
setitesuk
 
PPTX
Testing the untestable
RoyKlein
 
PDF
TDD CrashCourse Part2: TDD
David Rodenas
 
PDF
Code Review
Tu Hoang
 
PPT
Code Review
rantav
 
PDF
Test driven development - Zombie proof your code
Pascal Larocque
 
PDF
Code-Review-Principles-Process-and-Tools (1)
Aditya Bhuyan
 
PPTX
Seeding a Tree in a Gherkin
Paul Rohorzka
 
PDF
Tdd practices
axykim00
 
PPTX
Refactoring, 2nd Edition
jexp
 
ODP
TDD - Test Driven Development
Lim Chanmann
 
PPTX
Ensuring Software Quality in the cloud
Ricardo Martinelli de Oliveira
 
PPTX
Importance of the quality of code
Shwe Yee
 
PDF
Code Review: How and When
Paul Gower
 
PDF
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
VincitOy
 
PPT
Code Quality
François Camus
 
Comparing the code quality of ECMs
Nuxeo
 
Tdd com Java
Rafael Miceli
 
Test Driven Development Part 1
Gamal Shaban
 
Agile analysis development
setitesuk
 
Testing the untestable
RoyKlein
 
TDD CrashCourse Part2: TDD
David Rodenas
 
Code Review
Tu Hoang
 
Code Review
rantav
 
Test driven development - Zombie proof your code
Pascal Larocque
 
Code-Review-Principles-Process-and-Tools (1)
Aditya Bhuyan
 
Seeding a Tree in a Gherkin
Paul Rohorzka
 
Tdd practices
axykim00
 
Refactoring, 2nd Edition
jexp
 
TDD - Test Driven Development
Lim Chanmann
 
Ensuring Software Quality in the cloud
Ricardo Martinelli de Oliveira
 
Importance of the quality of code
Shwe Yee
 
Code Review: How and When
Paul Gower
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
VincitOy
 
Code Quality
François Camus
 

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

PDF
Waste Driven Development - Agile Coaching Serbia Meetup
Lemi Orhan Ergin
 
PDF
How To Tidy Up Your Test Code
Rock Interview
 
PDF
Put to the Test
Kevlin Henney
 
PPTX
Stop fearing legacy code
Yaki Koren
 
PPTX
Code smell overview
Pham Manh Lan
 
PPT
Revisiting refactoring
Nick Harrison
 
PPT
Revisiting Refactoring
Nick Harrison
 
PPTX
Unit Testing Full@
Alex Borsuk
 
PPTX
Code smells quality of code
Hasan Al Mamun
 
PPTX
Selenium Design Patterns
Liraz Shay
 
PDF
Test Drive Development
satya sudheer
 
PDF
Testing and symfony2
The Software House
 
PPT
Unit Testing, TDD and the Walking Skeleton
Seb Rose
 
PDF
Mine Your Own Code
Peter Norrhall
 
PDF
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay Da Nang
 
PPTX
Dev Ops for systems of record - Talk at Agile Australia 2015
Mirco Hering
 
PPT
Test Driven Development - Overview and Adoption
Pyxis Technologies
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
Code quality
Sunil Prasad
 
PDF
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Abdelkrim Boujraf
 
Waste Driven Development - Agile Coaching Serbia Meetup
Lemi Orhan Ergin
 
How To Tidy Up Your Test Code
Rock Interview
 
Put to the Test
Kevlin Henney
 
Stop fearing legacy code
Yaki Koren
 
Code smell overview
Pham Manh Lan
 
Revisiting refactoring
Nick Harrison
 
Revisiting Refactoring
Nick Harrison
 
Unit Testing Full@
Alex Borsuk
 
Code smells quality of code
Hasan Al Mamun
 
Selenium Design Patterns
Liraz Shay
 
Test Drive Development
satya sudheer
 
Testing and symfony2
The Software House
 
Unit Testing, TDD and the Walking Skeleton
Seb Rose
 
Mine Your Own Code
Peter Norrhall
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay Da Nang
 
Dev Ops for systems of record - Talk at Agile Australia 2015
Mirco Hering
 
Test Driven Development - Overview and Adoption
Pyxis Technologies
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Code quality
Sunil Prasad
 
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Abdelkrim Boujraf
 
Ad

Recently uploaded (20)

PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PDF
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Ad

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

  • #2: 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.
  • #6: 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.
  • #14: 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
  • #15: 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.
  • #16: 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
  • #17: 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?
  • #18: 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.
  • #19: 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)
  • #20: 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.
  • #21: 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.
  • #22: 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.
  • #23: 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)
  • #24: 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.
  • #25: 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)