smells @muc_rubyshift 06/2013

Post on 25-May-2015

85 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

6/4/13

Fighting Code That Smells

Anna BulenkovaJetBrains Software Developer

What’s that smell?

WARNINGKEEP CHILDREN AWAYFROM THIS CONTENT

Why?

Experience

Interruptions

Tiredness

Who cares...

Other Issues

What happens?

• undefined local variable or method `call_me' for main:Object (NameError)

warning: Object#id will be deprecated; use Object#object_id

• warning: Object#id will be deprecated; use Object#object_id

•Dead code

•Copy/Paste

•Complexity

•code_styleAnd_FWpatternViolations

• undefined local variable or method `call_me' for main:Object (NameError)

warning: Object#id will be deprecated; use Object#object_id

• warning: Object#id will be deprecated; use Object#object_id

•Dead code

•Copy/Paste

•Complexity

•code_styleAnd_FWpatternViolations

• undefined local variable or method `call_me' for main:Object (NameError)

warning: Object#id will be deprecated; use Object#object_id

• warning: Object#id will be deprecated; use Object#object_id

•Dead code

•Copy/Paste

•Complexity

•code_styleAnd_FWpatternViolations

• undefined local variable or method `call_me' for main:Object (NameError)

warning: Object#id will be deprecated; use Object#object_id

• warning: Object#id will be deprecated; use Object#object_id

•Dead code

•Copy/Paste

•Complexity

•code_styleAnd_FWpatternViolations

• undefined local variable or method `call_me' for main:Object (NameError)

warning: Object#id will be deprecated; use Object#object_id

• warning: Object#id will be deprecated; use Object#object_id

•Dead code

•Copy/Paste

•Complexity

•code_styleAnd_FWpatternViolations

• undefined local variable or method `call_me' for main:Object (NameError)

warning: Object#id will be deprecated; use Object#object_id

• warning: Object#id will be deprecated; use Object#object_id

•Dead code

•Copy/Paste

•Complexity

•code_styleAnd_FWpatternViolations

How to fight?

•Learn

•Re-read

•Ask for review

•Pair programming

•Use tools

Code quality tools

•Static

•Runtime

•No code run

•But tool runs

•No side effects

•But no on-the-fly change

Static tools

false positevebad alalyzing meta-programming

false positevebad alalyzing meta-programming

Reek

•Control Couple

•Data Clump

•Feature Envy

•Large Class/Method

•Long Parameters List

•Simulated Polymorphism

Control Couple

Data Clump

Feature Envy

Large Class/Method

OneThird

Long Parameter List

QuickTime™ and aH.264 decompressor

are needed to see this picture.

Simulated Polymorphism

•instance_of?

•kind_of?

•is_a?

•===

•Especially with case

Flog

•ABC Metric

•|ABC| = sqrt((A*A)+(B*B)+(C*C))

ABC Guide Lines0-10 = Awesome

•11-20 = Good enough

•21-40 = Might need refactoring

•41-60 = Possible to justify

•61-100 = Danger

•100-200 = Whoop, whoop, whoop

•200 + = Someone please think of the children

ABC = 8.5

Flay

•Duplicates

•Ignores names / literals / values

•Ignores code style

Roodi•Assignment in conditionals•Case missing else

•Line count

•Names check

•Cyclomatic сomplexity

•Empty rescue body

•For to foreach

•Parameters number

подровнятьподровнять

metrics_fu/metrical• Flay

• Flog

• Rails Best Practices

• Reek

• Roodi

• Dynamic tools

• Fancy HTML report

Where to get?

Who’s gonna clean everything for me?

RubyMine

•Inspections

•Duplicates

RubyMine Inspections

•Static

•On-the-fly analysis

Static analysis

QuickTime™ and aH.264 decompressor

are needed to see this picture.

QuickTime™ and aH.264 decompressor

are needed to see this picture.

On-The-Fly Analysis

Duplicates

There’s no cure-all

6/4/13

Thanks for watching!

top related