Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views11 pages

Low Hanging Code Smells

The document discusses five common code problems, referred to as 'Low Hanging Code Smells,' that developers can easily identify and fix to improve their coding skills and project quality. It emphasizes the importance of refactoring code, addressing issues like duplicated code, large classes and methods, inappropriate intimacy, and long parameter lists. The author, Scott Wierschem, offers insights and techniques for managing legacy code and encourages developers to embrace refactoring as a means to enhance their work experience.

Uploaded by

Cristian Pereira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Low Hanging Code Smells

The document discusses five common code problems, referred to as 'Low Hanging Code Smells,' that developers can easily identify and fix to improve their coding skills and project quality. It emphasizes the importance of refactoring code, addressing issues like duplicated code, large classes and methods, inappropriate intimacy, and long parameter lists. The author, Scott Wierschem, offers insights and techniques for managing legacy code and encourages developers to embrace refactoring as a means to enhance their work experience.

Uploaded by

Cristian Pereira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Scott Wierschem

Low Hanging
Code Smells
5 easy to spot code problems that you can x
right away, bring value to your team and become
an awesome developer.

--
Table of Contents
Refactoring code is a developer super power.

Cover Page

Introduction

Scott Wierschem

Comments

Duplicated Code

Large Classes and Methods

Keep calm.

Inappropriate Intimacy

Long Parameter List

Work on Awesome and Fun Projects

/
Introduction
So, you are dealing with some ugly code and
wondering if this can help you improve your developer
skills, and bring value to your project?
Congratulations!
I love working with crazy legacy projects. They give us
insights on the minds of the great (or not so
great ) developers that came before us.
Let us dive together in nding quality issues with the
project that you have at hand.
Keep calm. And refactor.

Scott

Low Hanging Code Smells are code problems that can cause
big problems and future headaches to your project. But are
actually easy to spot and x.
Being able to identify 5 of the most damaging Low Hanging
Code Smells will allow you to x them quickly.
Bring immediate results to your project, learn to navigate the
code base, and become a productive developer in no time.
This e-book is part of the "Low Hanging" series. Easy things
you can do that will give you amazing results.

/
Scott Wierschem

Scott helps Java developers to manage


their unruly code, so they can work on fun
and rewarding projects.

Legacy Code Whisperer


With over 30 years of software development, Scott has a number
of tools and techniques at his disposal for putting the fun back
into software development.

International Speaker
Scott has presented for Oracle Code One, and various Java User
Groups around the world.

Thoughtful Mentor
As founder of the Keep Calm and Refactor project, Scott shows
developers powerful techniques to manage existing code bases.
To nd out more, visit the KeepCalmAndRefactor project.

--
Comments
We start with some controversy: how to
comment code. Most comments we
find in existing code are, at best,
unnecessary, and at most, misleading.
Unnecessary comments are those that don’t help
the developer to better understand the code. These
would be things like the legal disclaimers at the top
of a source file or useless comment that is easier
described in the code.
Misleading comments are those that have not been
updated with the code. The code has changed and
does something different, but the comments have
not. So now the developer gets confused.
Because of that, most developers have taught
themselves to ignore comments, just as they ignore
banner ads on Websites.
To notice bad or useless comments, you first need
to read them. Usually they can all be removed.
A good place to start is code that has been
commented out. Remove it! If you need to get it
back, it will be there in your Git history.

/
Duplicated Code
One of the easiest ways to write a new
function is to copy an existing one and
make a few changes to it. It’s easy to
fall into this bad habit.
Duplicated code clutters the code with similar code.
(Did you notice how duplication makes even this
simple phrase harder to read?)
Worst sitll, bugs that get copied over and over.
Many IDEs will highlight duplicated code, or have
plugins to facilitate it.
One trick for finding duplicated code is to just
quickly scroll through the code without focusing on
it.
If you see sections that have the same “shape”, this
is often an indication that the code is duplicated -
even if the variables are renamed.

--
Large Classes and Methods
Industry leaders suggest a hard metric
for how many lines a class file or
method should be. For example, a
class should be under 1000 lines and a
method should fit on one screen.
While those can be quick metrics that don’t require
much thought, they shouldn’t be treated as law.
Sometimes a class or method needs to be longer.
The problem is deciding when it needs to be long,
and when it should be broken up.
For a method, if the code is at different levels of
abstraction in one method, it needs to be broken
up.
For instance, if there are primitive operations
alongside function calls, that is a signal for breaking
up the method.
If a class has a large number of member variables,
and these variables are accessed in subsets of
methods, that is an indication that the class should
be broken up.

--
When things look bad...
Keep Calm.
And Refactor.
Scott Wierschem

--
Inappropriate Intimacy
It sounds nasty, and it is!
If a class has public member variables
or methods, it is open to be accessed
in dangerous ways.
Class state can be changed at any time making it
hard to track down how this change was made.
Also, code will tend to become a series of calls deep
into various classes.
These problems are indicated by function calls or
data accesses with multiple periods in the name.
If a method has to dig deeply into another class or
set of classes to get to data or a desired function, it’s
time to end the cycle of inappropriate access.
Limit accessibility as much as possible unless it’s
absolutely necessary to open up.
Reducing class intimacy keeps code simple and
clean.

/
Long Parameter List
Having more than two or three
parameters in a function call is usually
an indicator that it does too much and
needs to be broken up.
You’ll generally find this in a large method
combined with inappropriate intimacy.
These are pretty easy to spot as the parameters tend
to wrap around in a hard-to-read way, or run off the
edge of the screen in an even harder-to-read way...
Fortunately, they are fairly easy to fix, too.
If the method can’t be broken up, or you really need
all of those parameters, sticking most (or even all) of
them into a parameter object would make the code
more readable and easier to use.
And code that is easier to read will be less likely to
be hiding bugs!

/
Struggling to work on cool
projects? Feeling stuck to
endless legacy code projects?
The Keep Calm and Refactor Project give developers the
tools and techniques they need to approach any existing
code base with con dence.
Even the nastiest ball of mud can be tamed using a few
powerful techniques with a healthy dose of patience and
persistence.
In a free 1-1 conversation, Scott will help you plan your
software developer career, and how you can work on the
most amazing projects.
Keep calm. And Refactor. We've got this

"When I rst met Scott he said he loved


legacy code. I thought he was either crazy or
joking. Scott helped me respect the work
done by other developers, and with his help I
developed this special super-power of
understanding code-bases fast."
- Bruno Souza

Schedule a FREE 1-1 Dev Career Session

You might also like