TeraTech

The ColdFusion Experts: Develop | Secure | Optimize

  • Services
  • About
  • CF Alive
  • Blog
  • Podcast
  • Contact

  • Services
  • About
  • CF Alive
  • Blog
  • Podcast
  • Contact

Does your ColdFusion Code Smell Bad? (16 certified checks)

October 5, 2016 By Michaela Light Leave a Comment

I am not talking about literal bad smell from your computer! I mean is there something “off” about it. Not a bug, but poor design or architecture weakness that will make maintenance a bear?

Blond Man Bad Smell Sign

Holding you nose when maintaining your code?

Defn: Code smell is any symptom in your source code that may indicate a deeper problem in your system. Just like if you open your fridge door and the smell is bad that is a sign that some of your food is rotting.

“[Code] smells are certain structures in the code that indicate violation of fundamental design principles and negatively impact design quality” – Martin Fowler, author of the book “Refactoring.”

Code smells are (usually) not bugs — they are not broken code and don’t stop the program from run correctly. They are weaknesses in design that may slow down maintenance. Or may up your risk of future bugs and system failures.  Bad code smell is a sign that you have serious technical debt!

What to do? Start refactoring in small steps to eliminate obvious bad smells; checking that the code still functions correctly at each stage. This will often uncover other worse smells deeper in the design.

Think of it like updating an old house – you rip off some bad drywall only to uncover decrepit electrical wiring underneath.

For example, You might start refactoring out duplicate code only to discover that the database design is bad too.

Code smells indicate when to refactor, and what to do to fix it.

Where bad code smells come from

Some surprising results in an IEEE software study of 500,000 code commits in 200 open source software projects found that:

  • The majority of bad smells start at project creation, not during maintenance.
  • Although regular maintenance is responsible for most bad smells added after creation, poor refactoring can add them too.
  • Not all bad smells come from newbies on the code. Long time developers who are overworked and stressed are more likely to make new bad smells in code.

 

What do to have better smelling maintenance? Increased code review when the project is stressed!

 

The code smell zoo

Zoo-24931_960_720

Application-level smells:

  • Duplicate code in different places.
  • Contrived complexity: using over-complicated design patterns where simpler design would get the job done well.

 

Class-level smells:

  • Hard coding of constants
    • Instead use named constants to both improve readability and to avoid programming errors in future maintenance. Put the constants in a CFinclude file so they are easy to find and change.
  • Orphan variable or constant class: a class that typically has a collection of constants that should be owned by another member classes.
  • Large class: it is too big to read or fix easily. A “God object”.
  • Feature envy: it uses the methods of another class too much.
  • Inappropriate intimacy: it depends on the internal coding of another class.
  • Refused bequest: it overrides a method of a base class but does not honor the original contract.
  • Lazy class/freeloader: it does too little!
  • Cyclomatic complexity: too many branches or loops. Break it up into smaller functions or write it in a simpler way.
  • Downcasting: a type cast which breaks the abstraction model → refactor/eliminate the abstraction.

 

Method-level smells:

  • Too many f*cking parameters: a long list of parameters is hard to read, and makes calling and testing the function complicated. Refactor so that responsibility is assigned in a more clean-cut way.
  • Long method: a method, function, or procedure that has grown too large.
  • Identifiers too long: eg using naming conventions to provide disambiguation rather making that clear in the software architecture.
  • Identifiers too short: the name of a variable should reflect its function. Except if it is obvious.
  • Too much return data: a function or method that returns more data than is needed to call it from all places it is used.

 

Action

Have your lead developer pick a “smell of the week” Then ask all developers to look for it during their regular work this week. They may fix the issue themselves or bring it back to you. As you go through the above smell list will gradually teach your team to be better developers.

 

PS What was the ‘worst' smell in your ColdFusion code last year? Leave a comment bellow.

Related Posts

  • State Of The Coldfusion Union 2017 Survey Amazing ResultsState of the ColdFusion Union 2017 Survey Amazing Results
  • State Of The Coldfusion Union 2017 Survey Amazing ResultsState of the ColdFusion Union 2017 Survey Amazing Results
  • Alex Skinner019 A Whirlwind Tour of Preside Application Framework in the Wild, with Alex Skinner
  • 017 Managing An International Team, Git, Cfml, Node, Joomla, With Scott Coldwell017 Managing an international team, Git, CFML, Node, Joomla, with Scott Coldwell
  • 011 Portable Cfml Cloud Deployments, Microservices And Rest With Jon Clausen011 Portable CFML Cloud deployments, Microservices and REST with Jon Clausen
  • 010 All Things Contentbox (New Api,Contentstore,Themes) With Gavin Pickin010 All things ContentBox (new API,ContentStore,Themes) with Gavin Pickin
  • Facebook
  • Twitter
  • LinkedIn

Filed Under: CFML, ColdFusion Maintenance, ColdFusion Training, Learn CFML, Learn ColdFusion, Legacy Code Tagged With: ColdFusion, ColdFusion code, Development Approach

← Previous Post State of the CF Union survey 2016 (powerful partial results)
Next Post → First 3 things to ask when hiring your next CFML developer

Popular podcast episodes

  • Revealing ColdFusion 2021 – Rakshith Naresh
  • CF and Angular – Nolan Erck
  • Migrating legacy CFML – Nolan Erck
  • Adobe API manager – Brian Sappey
  • Improve your CFML code – Kai Koenig

CF Alive Best Practices Checklist

Modern ColdFusion development best practices that reduce stress, inefficiency, project lifecycle costs while simultaneously increasing project velocity and innovation.

Get your checklist

Top articles

  • CF Hosting (independent guide)
  • What is Adobe ColdFusion
  • Is Lucee CFML now better than ACF?
  • Is CF dead?
  • Learn CF (comprehensive list of resources)

Recent Posts

  • 113 ACF and Lucee Roundtable, with Charlie Arehart, Gert Franz, Mark Drew and Ben Nadel
  • 112 4 Cool ColdFusion Books with author Luis Majano
  • State of the CF Union 2022 Survey Results- 2. Your Environment
  • Adobe ColdFusion Advanced Workshop
  • 111 CFCasts Behind the Scenes with Eric Peterson

Categories

  • Adobe ColdFusion 11 and older
  • Adobe ColdFusion 2018
  • Adobe ColdFusion 2020 Beta
  • Adobe ColdFusion 2021
  • Adobe ColdFusion Developer week
  • Adobe ColdFusion Project Stratus
  • Adobe ColdFusion Projects
  • Adobe ColdFusion Security
  • Adobe ColdFusion Summit
  • Auto Security Lockdown
  • AWS
  • CF Alive
  • CF Alive Podcast
  • CF Camp
  • CF Tags
  • CF Vs. Other Languages
  • CFEclipse
  • CFML
  • CFML Open- Source
  • CFUnited
  • ColdBox
  • ColdFusion and Cold Depression
  • ColdFusion and other news
  • ColdFusion community
  • ColdFusion Conference
  • ColdFusion Consulting
  • ColdFusion Developer
  • ColdFusion Development
  • ColdFusion Hosting
  • ColdFusion Maintenance
  • ColdFusion Roadmap
  • ColdFusion Security
  • ColdFusion Training
  • ColdFusion Webinar
  • CommandBox
  • Docker
  • Fixinator
  • Frameworks
  • Fusebox
  • FusionReactor
  • IntoTheBox Conference
  • Java
  • JavaScript
  • JVM
  • Learn CFML
  • Learn ColdFusion
  • Legacy Code
  • Load Testing
  • Lucee
  • Microsoft Azure
  • Mindmapping
  • MockBox
  • Modernize ColdFusion
  • Open- Source
  • Ortus Developer Week
  • Ortus Roadshow
  • Performance Tuning
  • Programming Languages
  • Server Crash
  • Server Software
  • Server Tuning
  • SQL
  • Survey
  • Survey results
  • TestBox
  • Transcript
  • Uncategorized
  • Webinar
  • Women in Tech
  • Home
  • Services
    • ColdFusion Consulting
    • ColdFusion Development
    • ColdFusion Maintenance
    • ColdFusion Security
  • About Us
  • CF Alive
    • CF Alive Book
    • CF Alive Inner Circle
    • CF Alive full resources cheatsheet
  • Blog
  • Podcast
    • Podcast Guest schedule
  • Contact
  • Sitemap

The ColdFusion Experts:
Develop, Secure, Optimize

TeraTech Inc
451 Hungerford Drive Suite 119
Rockville, MD 20850

Tel : +1 (301) 424 3903
Fax: +1 (301) 762 8185

Follow us on Facebook Follow us on LinkedIn Follow us on Twitter Follow us on Pinterest Follow us on YouTube

Copyright © 1998–2022 TeraTech Inc. All rights Reserved.