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
Fighting Code Smells #FrozenRails
Search
Dennis Ushakov
September 21, 2012
Technology
62
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Fighting Code Smells #FrozenRails
Ruby code quality tool overview
Dennis Ushakov
September 21, 2012
More Decks by Dennis Ushakov
See All by Dennis Ushakov
Ruby Debugger Internals
denofevil
1
76
RubyMine and RubyMotion
denofevil
0
52
Ruby Debugger API
denofevil
0
130
RubyMotion #JetBrainsDay
denofevil
0
44
Get More from RubyMotion with RubyMine
denofevil
0
52
Other Decks in Technology
See All in Technology
Digitization部 紹介資料
sansan33
PRO
2
7.7k
会社紹介資料 / Sansan Company Profile
sansan33
PRO
24
430k
Bits AI を制するものは Datadog を制す / The player that controls Bits AI, controls Datadog
kaminashi
0
140
FPGAが実現する遠方宇宙の高空間分解能天体撮影 -大型地上望遠鏡の視力を補正する「補償光学」とは?-
komei_mt
0
560
Go 1.27 の標準パッケージに uuid が入った!のでいろいろ喋る / go_127_std_go_uuid
convto
2
520
ガバメント AI 源内を地方自治体は活用できるのか可能性と課題、期待について
takeda_h
2
460
モダンフロントエンド 開発研修
recruitengineers
PRO
4
820
20260807_第6回_関東kaggler会LT_claw系bot xangiと始める、"寂しくない" kaggle
sugupoko
0
370
トークンマネジメントでAIにとって働きやすい環境を実現する
hikaruegashira
0
120
LLM・AIエージェントシステムベストプラクティス
shibuiwilliam
6
1.5k
自宅NWにISR4331を導入してみた話
okaits
0
110
Agent 時代の Kaggle 展望 / kaggle-in-the-agentic-era
upura
1
840
Featured
See All Featured
Exploring anti-patterns in Rails
aemeredith
3
470
Code Reviewing Like a Champion
maltzj
528
40k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Become a Pro
speakerdeck
PRO
31
6.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
260
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
780
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.4k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
210
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
A better future with KSS
kneath
240
18k
Transcript
Fighting Code Smells ! ruby code analysis tools Dennis Ushakov
Pareto Principle • 20% Write new code •80% Modify existing
code
Does This Smell? a = something.valid?! ! if (a.to_s ==
"true")! # code here! end!
Does This Smell? def has_currency_rate?! val = false! if currency.id
== company.currency.id or rate.blank?! else! val = true! end! val! end!
Does This Smell? class FinancialEventObserver < ActiveRecord::Observer! observe Payment, Invoice!
def before_save(model)! event = nil ! if model.class == Payment! if model.new_record? ! event = FinancialEvent.new(:event => FinancialEvent::Event::PAYMENT_INVOICE,! :arguments => {:client_name => model.invoice.client.short_name, :invoice_number => model.invoice.invoice_number},! :company_id=>model.invoice.client.company.id)! end! elsif model.class == Invoice! i = Invoice.find_by_id model.id ! if model.new_record? or i.status != model.status ! if model.status == Invoice::Status::ESTIMATE! event = FinancialEvent.new(:event => FinancialEvent::Event::ESTIMATE_SEND,! :arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},! :company_id=>model.client.company.id)! elsif model.status == Invoice::Status::APPROVED! event = FinancialEvent.new(:event => FinancialEvent::Event::ESTIMATE_APPROVED,! :arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},! :company_id=>model.client.company.id)! elsif model.status == Invoice::Status::REJECTED! event = FinancialEvent.new(:event => FinancialEvent::Event::ESTIMATE_REJECTED,! :arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},! :company_id=>model.client.company.id)! elsif model.status == Invoice::Status::SEND! event = FinancialEvent.new(:event => FinancialEvent::Event::INVOICE_SEND,! :arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},! :company_id=>model.client.company.id) ! end! elsif !model.new_record? and i.state != model.state! if model.state == Invoice::State::DELETED! event = FinancialEvent.new(:event => FinancialEvent::Event::INVOICE_DELETED,! :arguments => {:invoice_number => model.invoice_number},! :company_id=>model.client.company.id)! end! end ! end! event.eventable = model.requester unless event.blank? ! event.save unless event.blank? !
Code That Smells • Runtime errors • Runtime warnings •
Dead code • Copy/paste • Complex method bodies • Code style violations • Framework pattern violations
Code Quality Tools autotest cucumber rspec simplecov rcov reek flay
dust pelusa roodi flog metrics_fu heckle Static Runtime
Static Tools • Inspect your code without launching it •
100% side effects free • Challenging to implement • Rails DSL magic kills ‘em
Reek • Class, module, method, identifier names • Using is_a?,
kind_of? instead of duck typing • Code duplicates • Large classes and methods • Nested iterators
Flog • Uses ABC metrics system • Assignment • Branches
• Conditions • |ABC| = √(A²+B²+C²) • Consider revising most painful methods
Flay • Analyzes code duplicates • Ignores identifier/ constants names
• Consider refactoring code that’s reported
Roodi • Assignments in conditions • Case blocks without else
• Large classes, modules and methods • Naming conventions • Cyclomatic complexity
metrics_fu/metrical Provides aggregate results for • Flay • Flog •
Reek • Roodi
Runtime Tools • Inspect your code by launching it •
100% follow the way Ruby works • Cope well with DSL magic • May have side effects • Works until the very first failure
Runtime Tools • Code testing • Test::Unit/MiniTest • RSpec/Cucumber •
Autotest/CI • Code coverage • RCov/SimpleCov • Heckle
Heckle • Changes code • if → unless • Calls
are changed • Numbers are changed • Runs tests • At least one test should fail after change
RubyMine • Static analysis • On-the-fly inspections with quickfixes •
Understands Rails DSLs • Code duplication • Dynamic analysis tools integration • Graphical representation • Autotest simulation • Stacktrace navigation
Refactorings • Rename • Extract • Method • Class/Module •
Variable/Parameter
Morale • Use static analysis tools • Don’t forget to
test • Try RubyMine http://jetbrains.com/ ruby
en_Dal
[email protected]
denofevil