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
280
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Refactoring Ruby
Short talk about refactoring and Ruby code complexity analysis.
Anatoli Makarevich
April 23, 2013
More Decks by Anatoli Makarevich
See All by Anatoli Makarevich
gem 'sandi_meter' lightning talk at BaRuCo 2013
makaroni4
1
520
Refactoring in Ruby
makaroni4
4
860
Other Decks in Programming
See All in Programming
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
710
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.1k
Oxlintはいいぞ(続)
yug1224
1
400
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
400
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
100
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
460
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
350
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
280
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
170
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
190
Flow は今どうなっているか
mizdra
PRO
0
680
How I Won Prize Money at a Hackathon Using Codex and Symphony Alpha
yasei_no_otoko
0
120
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
250
4 Signs Your Business is Dying
shpigford
187
23k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
480
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Building the Perfect Custom Keyboard
takai
2
850
The agentic SEO stack - context over prompts
schlessera
0
870
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
180
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
470
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
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