This document discusses code smells in programming. It defines code smells as surface indications that usually correspond to deeper problems in a system. Common code smells include duplicate code, long methods, large classes, and long parameter lists. The document provides examples of each code smell and recommends solutions such as extracting duplicate code into new methods, breaking long methods into smaller subroutines, breaking large classes into separate components, and removing unnecessary parameters. It also recommends tools programmers can use to detect code smells like Flog, Flay, Reek, and Brakeman in Ruby code.
4. • S O F T WA R E
E N G I N E E R
• W E B A N D M O B I L E
• R U B Y / P H P /
O B J E C T I V E C /
S W I F T
• 1 1 Y E A R S O F
E X P E R I E N C E
• Q U I M B I K , I N C /
U S A
G U S TA V O C U N H A
4
5. •I N F R A S T R U C T U R E ?
•S U P P O RT ?
•W O R K S ?
•P R O G R A M M I N G ?
5
6. P R O C E S S
W R I T I N G
T E S T I N G
M A I N T E N A N I N G
[ W I K I P E D I A ]
D E F I N E : P R O G R A M ?
6
7. • ~ 300 Programming Languages - Wikipedia
• Learn all of them? NO!
• Make mistakes is common and acceptable
• Which language should I learn?
Does the language really matters?!?!?!?!
F* NO!!!!!!
7
8. P R O G R A M M I N G I S E A S Y
8
I D O T H I S O N A D A I LY B A S I S
I N E V E R M A K E M I S TA K E S !
R E A L LY ?
9. H T T P : / / I . I M G U R . C O M / B T J Z E D W. J P G9
10. 10
H T T P : / / I . I M G U R . C O M / L Z B I E . J P G
11. 11
H T T P : / / PA S T E B I N . C O M / P T RY 5 G 2 A
Construtor
+ 40 parâmetros
12. PA S T I E . O R G / PA S T E S / 8 2 7 2 3 8 6
H T T P S : / / G I S T. G I T H U B . C O M /
A N O N Y M O U S /
A A 4 6 E 8 D B 0 9 8 D C B D 3 B 4 2 8
12
15. C O D E S M E L L
( … ) I S A S U R FA C E I N D I C A T I O N T H A T U S U A L LY
C O R R E S P O N D S T O A D E E P E R P R O B L E M I N T H E
S Y S T E M ( … )
K E N T B E C K
15
16. C O D E S M E L L
• Duplicate Code
• Long Method
• Large Class
• Long Parameter List
• + 10 more symptoms
16
17. D U P L I C AT E C O D E
C O D E S M E L L
17
Most common problem
Solution
• Same class, different methods
• Extract code to new method
• Different classes
• Sibling classes
• Move code to parent class
• If code is similar, but not equal, break into methods that has
same code and methods with different information
• Unrelated classes
• Check design
18. L O N G M E T H O D
C O D E S M E L L
18
Hard to understand, easy to solve
Solution
• Break the methods into smaller methods (subroutines)
• Big method will become a method caller
• Easier to maintain
Problems
• Hard to read
• Usually loses it’s main purpose
19. L A R G E C L A S S
C O D E S M E L L
19
Also known as Ninja Class
Solution
• Break the attributes into components (like address)
• Usually, attributes with same prefix/suffix is likely to become a
component
• Reduces duplicate code
Problems
• Loses it’s purpose
• Does more then one thing
• Duplicate code (often)
• Has many object-cadidates inside it
20. L O N G PA R A M E T E R L I S T
C O D E S M E L L
20
Change one of them and you will be in trouble
Solution
• Remove any parameters that can be retrieved from objects already
sent
Problems
• On Procedural Programming, you had to send every detail a function
needed
• On Object Oriented Programming, you can send enough to get what
the method needs
21. H T T P : / / W W W. A M A Z O N . C O M / G P / P R O D U C T / 0 2 0 1 4 8 5 6 7 2
21
F O R F U R T H E R I N F O R M AT I O N
22. I N R U B Y…
Gems
• flog - Flog shows you the most torturous code you wrote. The
more painful the code, the higher the score.
• flay - Flay analyzes ruby code for structural similarities.
Differences in literal values, names, whitespace, and
programming style are all ignored.
• reek - is a tool that examines Ruby classes, modules and methods
and reports any Code Smells it finds
• brakeman - is a static analysis tool which checks Ruby on Rails
applications for security vulnerabilities.
22
23. H T T P : / / W W W. S L I D E S H A R E . N E T / M A R T I N T S C H / R E FA C T O R I N G - C O D E - S M E L L
23
24. T W O M O R E T H I N G S …T W O M O R E T H I N G S …
24