Size metrics

Designing and Maintaining Software (DAMS)
 Louis Rose

Habitable Software Leaner

Avoids Duplication

Less Complex

Clearer

Loosely Coupled

More Extensible

More Cohesive

???

Lines of Code (LOC) LOC:
 Total number of (source) lines in a program

Excluding
 whitespace
 comments
 dependencies
 tests, build scripts, etc.

Lines of Code (LOC) 100,000,000 10,000,000 1,000,000 100,000 10,000 1,000 100 10 wc

Sinatra

Simile Virus

Photoshop v1.0

Chrome

Linux Kernel (2014)

Problem: golfing? %w.rack tilt date INT TERM..map{|l|trap(l){$r.stop}rescue require l}; $u=Date;$z=($u.new.year + 145).abs;puts "== Almost Sinatra/No Version has taken the stage on #$z for development with backup from Webrick" $n=Module.new{extend Rack;a,D,S,q=Rack::Builder.new,Object.method(:define_method),/@@ *([^\n]+) \n((([email protected]@)[^\n]*\n)*)/m %w[get post put delete].map{|m|D.(m){|u,&b|a.map(u){run->(e){[200, {"Content-Type"=>"text/html"},[a.instance_eval(&b)]]}}}} Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h=$u._jisx0301("hash, please");File.read(caller[0][/^[^:]+/]).scan(S){|a,b| h[a]=b};h);v[0].new(*o){n=="#{n}"?n:$t[n.to_s]}.render(a,o[0].try(: [],:locals)||{})}} %w[set enable disable configure helpers use register].map{|m|D.(m){|*_,&b| b.try :[]}};END{Rack::Handler.get("webrick").run(a,Port:$z){|s|$r=s}} %w[params session].map{|m|D.(m){q.send m}};a.use Rack::Session::Cookie;a.use Rack::Lock;D.(:before){|&b|a.use Rack::Config,&b};before{|e|q=Rack::Request.new e;q.params.dup.map{|k,v| params[k.to_sym]=v}}}

https://github.com/rkh/almost-sinatra

Problem: waffling? “One of my biggest irritations are studies of productivity based on lines of code… Any good developer knows that they can code the same stuff with huge variations in lines of code. ” - Martin Fowler
 http://martinfowler.com/bliki/CannotMeasureProductivity.html

Solution

Treat metrics as a tool for developers,
 not as an instrument for managers.

Intra-Class Metrics Which are the largest files in our program? Which classes have the most attributes / methods? Which classes have unusual attribute:method ratios?

God Class What is it?
 A very large class (relatively speaking) Why is it problematic?
 Often indicates missing abstractions When does it arise?
 👎 “Junk drawer” mentality
 👎 Enforced / encouraged by framework
 👍 Temporary home

Lazy Class What is it?
 A very small class (relatively speaking) Why is it problematic?
 Every class (strictly, abstraction) incurs overhead When does it arise?
 👎 Speculative abstraction 
 👎 Downsized during refactoring
 👍 Domain objects

Inter-Class Metrics

Which are the longest methods in a class? Which are the methods with the most parameters?

God Method What is it?
 A very large method (relatively speaking) Why is it problematic?
 Inhibits OO benefits: explanation, sharing, choosing When does it arise?
 👎 Poor grasp of OO programming
 👍?

Kitchen Sink Method What is it?
 A method that takes a lot of parameters
 (relatively speaking) Why is it problematic?
 Increases complexity of using a method
 Likely to change often When does it arise?
 👎 Poor separation of concerns
 👎 Coddling (doing the method’s work for it)
 👍 Unpacking objects to break dependency chains

Summary Use LOCs only to gauge rough size of project Use (size) metrics as a design tool,
 not as management instrument Size metrics can act as an indicator
 for many common issues

Designing and Maintaining Software (DAMS) - GitHub

%w.rack tilt date INT TERM..map{|l|trap(l){$r.stop}rescue require l};. $u=Date;$z=($u.new.year + 145).abs;puts "== Almost Sinatra/No Version has taken the stage on #$z for development with backup from Webrick". $n=Module.new{extend. Rack;a,D,S,q=Rack::Builder.new,Object.method(:define_method),/@@ *([^\n]+).

194KB Sizes 0 Downloads 104 Views

Recommend Documents

Designing and Maintaining Software (DAMS) - GitHub
ASTs are tree data structures that can be analysed for meaning (following JLJ in SYAC 2014/15) ... More Cohesive. Avoids Duplication. Clearer. More Extensible.

Designing and Maintaining Software (DAMS) - GitHub
Clear Documentation. Designing and Maintaining Software (DAMS). Louis Rose. Page 2. Bad documentation. Misleading or contradictory find_customer(id). CustomerGateway. Used to look up a customer by their customer number. Page 3. Bad documentation. Red

Designing and Maintaining Software (DAMS) - GitHub
R&D: sketch habitable solutions on paper, using UML. 4. Evaluate solutions and implement the best, using TDD. Probably start again at 3. 5. Give to the product owner to validate. Probably start again at 1. 6. Put into production for customers to eval

Designing and Maintaining Software (DAMS) - GitHub
Observers. Designing and Maintaining Software (DAMS). Louis Rose. Page 2. Page 3. Delivery people need to know when pizzas are ready class Pizza def initialize(delivery_person). @delivery_person = delivery_person end def bake cook # blocking call. @d

Designing and Maintaining Software (DAMS) - GitHub
When we are testing the way that a unit behaves when a condition is met, use a stub to setup the condition. Solution: use stubs for queries class Subscription ... def bill(amount) unless payments.exists(subscription_id: id) payments.charge(subscripti