Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Are you happy with your code quality?

Are you happy with your code quality?

Presentation done at Geneva.rb and SoftShake with @rsempe

Vincent Pochet

October 25, 2013
Tweet

More Decks by Vincent Pochet

Other Decks in Programming

Transcript

  1. ARE YOU HAPPY WITH YOUR CODE QUALITY? Track Ruby/Rails, October

    25th 2013. Presentation by and Vincent Pochet Romain Sempé
  2. CO-FOUNDERS OF We provide our expertise in web technologies with

    Rails. Located in Archamps, near Geneva.
  3. WRITE ELOQUENT RUBY CODE "Remember, good code is like a

    good joke: It needs no explanation."
  4. Measure: LINE COUNT $ r a k e s t

    a t s + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - + - - - - - - - + - - - - - - - - - + - - - - - - - - - + - - - - - + - - - - - - - + | N a m e | L i n e s | L O C | C l a s s e s | M e t h o d s | M / C | L O C / M | + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - + - - - - - - - + - - - - - - - - - + - - - - - - - - - + - - - - - + - - - - - - - + | C o n t r o l l e r s | 1 1 8 8 | 7 6 4 | 1 9 | 1 5 0 | 7 | 3 | | H e l p e r s | 1 5 1 | 1 0 1 | 0 | 1 8 | 0 | 3 | | M o d e l s | 1 3 4 6 | 7 7 5 | 1 5 | 1 3 4 | 8 | 3 | | L i b r a r i e s | 6 4 | 2 9 | 2 | 5 | 2 | 3 | | I n t e g r a t i o n t e s t s | 0 | 0 | 0 | 0 | 0 | 0 | | F u n c t i o n a l t e s t s | 1 4 0 0 | 1 1 5 3 | 2 1 | 1 6 5 | 7 | 4 | | U n i t t e s t s | 1 5 8 1 | 1 2 4 1 | 4 3 | 1 7 6 | 4 | 5 | + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - + - - - - - - - + - - - - - - - - - + - - - - - - - - - + - - - - - + - - - - - - - + | T o t a l | 5 7 3 0 | 4 0 6 3 | 1 0 0 | 6 4 8 | 6 | 4 | + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - + - - - - - - - + - - - - - - - - - + - - - - - - - - - + - - - - - + - - - - - - - + C o d e L O C : 1 6 6 9 T e s t L O C : 2 3 9 4 C o d e t o T e s t R a t i o : 1 : 1 . 4
  5. Measure: COMPLEXITY FLOG $ f l o g a p

    p / m o d e l s 1 1 8 2 . 2 : f l o g t o t a l 7 . 8 : f l o g / m e t h o d a v e r a g e 4 1 . 6 : S t o r y : : S t e p # c h a n g e _ p o s i t i o n a p p / m o d e l s / s t o r y / s t e p . r b : 1 3 3 2 7 . 7 : S t o r y : : S t e p # u p d a t e _ t r i g g e r _ i t e m s ! a p p / m o d e l s / s t o r y / s t e p . r b : 8 3 2 5 . 8 : S e r v i c e A c c o u n t : : G o o g l e O a u t h 2 : : f r o m _ o m n i a u t h a p p / m o d e l s / s e r v i c e _ a c c o u n t / g o o g l e _ o a u 2 5 . 8 : S e r v i c e A c c o u n t : : F a c e b o o k : : f r o m _ o m n i a u t h a p p / m o d e l s / s e r v i c e _ a c c o u n t / f a c e b o o k . r b : 2 0 2 2 . 3 : P r o g r a m # s c h e d u l e _ r u n a p p / m o d e l s / p r o g r a m . r b : 1 0 9 2 1 . 4 : S t o r y : : S t e p # v a l i d a t e _ a c t i o n a p p / m o d e l s / s t o r y / s t e p . r b : 2 3 2 2 1 . 4 : R o l e S t e p # v a l i d a t e _ a c t i o n a p p / m o d e l s / r o l e _ s t e p . r b : 6 4 1 7 . 6 : S t o r y : : S t e p # i n c r e m e n t _ a l l _ p o s i t i o n s a p p / m o d e l s / s t o r y / s t e p . r b : 1 7 8
  6. Measure: DUPLICATION KEEP IN MIND : DRY principle is: Every

    piece of knowledge must have a single, unambiguous, authoritative representation within a system. And not: Don’t type the same characters into the keyboard multiple times.
  7. Measure: DUPLICATION FLAY $ f l a y a p

    p / m o d e l s T o t a l s c o r e ( l o w e r i s b e t t e r ) = 4 0 6 1 ) I D E N T I C A L c o d e f o u n d i n : d e f s ( m a s s * 2 = 2 2 0 ) a p p / m o d e l s / s e r v i c e _ a c c o u n t / f a c e b o o k . r b : 2 0 a p p / m o d e l s / s e r v i c e _ a c c o u n t / g o o g l e _ o a u t h 2 . r b : 8 2 ) S i m i l a r c o d e f o u n d i n : d e f n ( m a s s = 7 0 ) a p p / m o d e l s / r o l e _ s t e p . r b : 6 4 a p p / m o d e l s / s t o r y / s t e p . r b : 2 3 2 3 ) S i m i l a r c o d e f o u n d i n : d e f n ( m a s s = 4 0 ) a p p / m o d e l s / s t o r y / s t e p . r b : 1 1 2 a p p / m o d e l s / s t o r y / s t e p . r b : 1 1 6
  8. Measure: CHURN The change of your source files over time

    $ c h u r n * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * P r o j e c t C h u r n * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * F i l e s : + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - + | f i l e _ p a t h | t i m e s _ c h a n g e d | + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - + | c o n f i g / l o c a l e s / e n . y m l | 2 8 1 | | d b / s t r u c t u r e . s q l | 1 0 8 | | a p p / v i e w s / p l a y e r / s h o w . h t m l . e r b | 9 2 | | a p p / v i e w s / s t o r i e s / s h o w . h t m l . e r b | 8 8 | | G e m f i l e . l o c k | 8 7 |
  9. (For Ruby < 1.9) : Measure: TEST COVERAGE RCov SimpleCov

    $ C O V E R A G E = t r u e r a k e t e s t # R u n n i n g t e s t s : F i n i s h e d t e s t s i n 1 4 . 5 5 6 9 4 3 s , 1 1 . 8 8 4 4 t e s t s / s , 2 4 . 7 9 9 2 a s s e r t i o n s / s . 1 7 3 t e s t s , 3 6 1 a s s e r t i o n s , 0 f a i l u r e s , 0 e r r o r s , 0 s k i p s r u b y - v : r u b y 2 . 0 . 0 p 2 4 7 ( 2 0 1 3 - 0 6 - 2 7 r e v i s i o n 4 1 6 7 4 ) 1 0 7 1 / 1 1 8 7 L O C ( 9 0 . 2 3 % ) c o v e r e d . R u n o p t i o n s : # R u n n i n g t e s t s : F i n i s h e d t e s t s i n 1 8 . 5 8 0 0 9 9 s , 8 . 7 7 2 8 t e s t s / s , 2 4 . 5 9 6 2 a s s e r t i o n s / s . 1 6 3 t e s t s , 4 5 7 a s s e r t i o n s , 0 f a i l u r e s , 0 e r r o r s , 0 s k i p s r u b y - v : r u b y 2 . 0 . 0 p 2 4 7 ( 2 0 1 3 - 0 6 - 2 7 r e v i s i o n 4 1 6 7 4 ) 1 1 5 9 / 1 1 6 0 L O C ( 9 9 . 9 1 % ) c o v e r e d .
  10. "Good software meets the present objective at an acceptable cost

    without incurring an unacceptable amount of future risk" Brandon Keepers - Github