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
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
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
440
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
120
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
680
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
200
Patterns of Patterns
denyspoltorak
0
1.4k
Implementation Patterns
denyspoltorak
0
280
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
160
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
440
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
510
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
290
Fragmented Architectures
denyspoltorak
0
140
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
300
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
RailsConf 2023
tenderlove
30
1.3k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
130
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
110
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
430
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
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