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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Anatoli Makarevich
April 23, 2013
Programming
2
270
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
830
Other Decks in Programming
See All in Programming
手戻りゼロ? Spec Driven Developmentとは@KAG AI week
tmhirai
1
190
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
560
nilとは何か 〜interfaceの構造とnil!=nilから理解する〜
kuro_kurorrr
3
1.9k
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
220
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
140
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
810
Fundamentals of Software Engineering In the Age of AI
therealdanvega
1
240
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
710
Windows on Ryzen and I
seosoft
0
240
AIコードレビューの導入・運用と AI駆動開発における「AI4QA」の取り組みについて
hagevvashi
0
400
AI主導でFastAPIのWebサービスを作るときに 人間が構造化すべき境界線
okajun35
0
680
TROCCOで実現するkintone+BigQueryによるオペレーション改善
ssxota
0
170
Featured
See All Featured
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
140
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
390
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
67
37k
Building the Perfect Custom Keyboard
takai
2
710
Practical Orchestrator
shlominoach
191
11k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
The Curse of the Amulet
leimatthew05
1
9.8k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
480
KATA
mclloyd
PRO
35
15k
Navigating Team Friction
lara
192
16k
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