Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Fighting Code Smells #FrozenRails
Search
Dennis Ushakov
September 21, 2012
Technology
63
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
77
RubyMine and RubyMotion
denofevil
0
53
Ruby Debugger API
denofevil
0
130
RubyMotion #JetBrainsDay
denofevil
0
45
Get More from RubyMotion with RubyMine
denofevil
0
55
Other Decks in Technology
See All in Technology
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
870
ブラウザとサーバーから考えるAI時代のフロントエンド監視
shogo4131
3
940
Classmethod Company Deck
satoshi7
1
690
サブエージェントと Claude Mods で作る独自 Advisor ツールの話
kenichiodo
2
160
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.4k
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
170
Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
1
580
Temporal 最高!でも改めて「日付」について調べたら人類の負債すぎる件
riyaamemiya
0
150
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
340
20261017福岡devIO 「AIは"良いダッシュボード"を作れるか?
jtakeda
0
150
パスキーの自動テストはどこまでいけるのか
teamlab
PRO
0
250
夫婦で子育てするための育児標準化
codmoninc
PRO
0
340
Featured
See All Featured
Docker and Python
trallard
47
4.2k
The SEO identity crisis: Don't let AI make you average
varn
0
590
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
Building an army of robots
kneath
307
47k
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Done Done
chrislema
187
17k
Google's AI Overviews - The New Search
badams
0
1.6k
What's in a price? How to price your products and services
michaelherold
247
13k
Exploring anti-patterns in Rails
aemeredith
4
540
Un-Boring Meetings
codingconduct
0
460
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
480
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