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
510
Refactoring in Ruby
makaroni4
4
850
Other Decks in Programming
See All in Programming
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
170
net-httpのHTTP/2対応について
naruse
0
450
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.1k
CSC307 Lecture 17
javiergs
PRO
0
320
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
770
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
300
AIエージェントと協働するCLI開発 — BunとOpenClawで学んだこと
yoshikouki
1
240
Agentic UI
manfredsteyer
PRO
0
110
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
190
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
170
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
310
TypeSpec で繋ぐ複数プロダクトの型安全
maroon8021
1
420
Featured
See All Featured
My Coaching Mixtape
mlcsv
0
140
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
240
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
What's in a price? How to price your products and services
michaelherold
247
13k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Evolving SEO for Evolving Search Engines
ryanjones
0
210
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
250
sira's awesome portfolio website redesign presentation
elsirapls
0
270
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
The Invisible Side of Design
smashingmag
302
52k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
360
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