Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Refactoring Ruby
Search
Anatoli Makarevich
April 23, 2013
Programming
2
260
Refactoring Ruby
Short talk about refactoring and Ruby code complexity analysis.
Anatoli Makarevich
April 23, 2013
Tweet
Share
More Decks by Anatoli Makarevich
See All by Anatoli Makarevich
gem 'sandi_meter' lightning talk at BaRuCo 2013
makaroni4
1
500
Refactoring in Ruby
makaroni4
4
800
Other Decks in Programming
See All in Programming
datadog dash 2025 LLM observability for reliability and stability
ivry_presentationmaterials
0
190
WebViewの現在地 - SwiftUI時代のWebKit - / The Current State Of WebView
marcy731
0
100
都市をデータで見るってこういうこと PLATEAU属性情報入門
nokonoko1203
1
580
関数型まつりレポート for JuliaTokai #22
antimon2
0
160
VS Code Update for GitHub Copilot
74th
1
480
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
380
A2A プロトコルを試してみる
azukiazusa1
2
1.2k
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
130
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
130
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
20
3.7k
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
150
Java on Azure で LangGraph!
kohei3110
0
170
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Optimizing for Happiness
mojombo
379
70k
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
Done Done
chrislema
184
16k
The Language of Interfaces
destraynor
158
25k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.4k
Adopting Sorbet at Scale
ufuk
77
9.4k
Making Projects Easy
brettharned
116
6.3k
We Have a Design System, Now What?
morganepeng
53
7.7k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Transcript
Refactoring. Ruby edition. Anatoli Makarevich @makaroni4
Who am I?
Our projects look like
In next 15 minutes we will • spice up our
knowledge about refactoring • look at some common smells • get acquainted with automated code analysis • become ready to refactor
Refactoring is but NOT writing tests changing code reducing complexity
adding new features
Refactoring != Moving backwards
To grow fast you need to grow right.
What refactoring does? Complexity Readability Maintainability Extensibility
This is scientific! Martin Fowler, 1999
Your desk books are:
Code Smell Any symptom in the source code of a
program that possibly indicates a deeper problem Kent Beck
Let’s smell it!
Code smells Long method Duplications Heavy class Stupid name Too
many params Feature envy Ubercallback Complex conditions
Refactoring cycle Check test coverage Write tests if needed Change
code Ensure that tests pass Check overall complexity
Find code smells Check test coverage Write tests if needed
Change code Ensure that tests pass Check overall complexity
Check test coverage Check test coverage Write tests if needed
Change code Ensure that tests pass Check overall complexity
Write new tests if needed Check test coverage Write tests
if needed Change code Ensure that tests pass Check overall complexity
reFACTOR Check test coverage Write tests if needed Change code
Ensure that tests pass Check overall complexity
Ensure that tests pass Check test coverage Write tests if
needed Change code Ensure that tests pass Check overall complexity
Automate tests! Check test coverage Write tests if needed Change
code Ensure that tests pass Check overall complexity Travis CI Jenkins CI Gitlab CI
Automate complexity analysis? Check test coverage Write tests if needed
Change code Ensure that tests pass Check overall complexity
Could complexity analysis be automated?
? How can we process code?
s(:class, :Sexp, s(:const, :Array), s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),
s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1)))) S-expressions
s(:class, :Sexp, s(:const, :Array), s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),
s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1)))) Sexp operator
s(:class, :Sexp, s(:const, :Array), s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),
s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1)))) Sexp body
Automated analysis • Long methods • Complex class • Stupid
variable name
Long method s(:class, :Sexp, s(:const, :Array), s(:defn, :sexp_type, s(:args), s(:call,
nil, :first)), s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1)))) Find method Sexp :defn
Long method s(:class, :Sexp, s(:const, :Array), s(:defn, :sexp_type, s(:args), s(:call,
nil, :first)), s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1)))) Find method Sexp :defn Count sexp operators
Complex class s(:class, :Sexp, s(:const, :Array), s(:defn, :sexp_type, s(:args), s(:call,
nil, :first)), s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1)))) Find method Sexp :class
Complex class s(:class, :Sexp, s(:const, :Array), s(:defn, :sexp_type, s(:args), s(:call,
nil, :first)), s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1)))) Find method Sexp :class Cound weights of Sexp operators
Stupid variable name s(:class, :HomerSimpson, s(:const, :BlahBlahBlah), s(:defn, :donuts, s(:args),
s(:call, nil, :fist)), s(:defn, :beersnstuff, s(:args), s(:call, nil, :[], s(:lit, 1..-1))))
Automated analysis
Refactoring != Rehacktoring @katrinyx
It is about perception We READ code, NOT COMPILE it.
After this talk do: • gem install flog • gem
install flay • gem install reek • flog PROJECT_PATH • flay PROJECT_PATH • reek PROJECT_PATH
Let’s refactor! Anatoli Makarevich @makaroni4