‘Stupid’ Question 16: What are some common code smells?
I’m very sorry for being late with this question with half a day, I’ve had a crazy day – and I got so much good news! Wow, it has been a crazy-good week and there has been so many things happing, and I’ve had so many great conversations. I’m buzzing! I’ll have to wait a few more days before I share all the good news, so stayed tuned!
And let’s get back to the questions! So Last question was what a code smell is, and of course the following question has to be what the common code smells are. I remember very well that already on the third day of school my dear teacher, mentor and very good friend Mikael Freidlitzstarted talking about code smells. We couldn’t even create a class and he was talking about how to think. I reckon that was a very good idea, as it became the norm, to avoid code smells – even before we knew how to program.
This image is one made and posted on the class group page on facebook to illustrate the warning we had gotten from our teacher.
This image is one made and posted on the class group page on facebook to illustrate the warning we had gotten from our teacher. Mikael Freidlitz jokingly told us he would deduct 5 points on our exams if he ever saw one of these in our code. And with time the list grew, not very big – but it grew. And it forced us to think, and find, better solutions.
My notes from Clean Code
When I read the clean coder a few months in, I understood why he has said so. Here are all the notes I made while reading the Clean Code. I actually read the whole book in two hours or so, loving it so much I couldn’t put it down.
Meeting Robert C. Martin and talking geek with him was def. one of the high points for me when I got to go to NDC earlier this year
So, I was going to present a pretty list with all the common code smells. But once I started looking I realized that there are a few blog posts that have quite nicely presented one. So instead I’ll justcheekily sum up the list that Jeff Atwood has on his blog, and recommend that you read more about the different code smells there, as I believe he sums them up pretty well : ) And Jeff, hope it’s ok I share this list : )
Common code smells:
Code Smells Within Classes
Comments
Long Method
Long Parameter List
Duplicated code
Conditional Complexity
Combinitorial Explosion
Large Class
Type Embedded in Name
Uncommunicative Name
Inconsistent Names
Dead Code
Speculative Generality
Oddball Solution
Temporary Field
Code Smells Between Classes
Alternative Classes with Different Interfaces
Primitive Obsession
Data Class
Data clumps
Refused bequest
Inappropriate Intimacy
Indecent Exposure
Feature Envy
Lazy Class
Message Chains
Middle man
Divergent Change
Shotgun surgery
Parallel inheritance hirearchies
Incomplete library class
Solution sprawl
Comments
The "Code Smells Within Classes" list sounds good. However, the second list is a mess. There's nothing really wrong with it -- all those things listed there are bad. But, a "code smell" should be an obvious indicator of a deeper problem. That's just a list of deeper problems. We need a simple sign for each of those that shows that it is lurking...
Last modified on 2012-08-06