friday 9 may 14 welcome to your new project
play

Friday, 9 May 14 Welcome to your New Project Friday, 9 May 14 - PowerPoint PPT Presentation

Friday, 9 May 14 Welcome to your New Project Friday, 9 May 14 Friday, 9 May 14 Friday, 9 May 14 Things are starting to smell Friday, 9 May 14 Code Smells Symptoms in the source code that indicate there may be trouble ahead: Bugs Reduced


  1. Friday, 9 May 14

  2. Welcome to your New Project Friday, 9 May 14

  3. Friday, 9 May 14

  4. Friday, 9 May 14

  5. Things are starting to smell Friday, 9 May 14

  6. Code Smells Symptoms in the source code that indicate there may be trouble ahead: Bugs Reduced development speed Readability/maintainability problems Heuristics, not hard and fast rules Friday, 9 May 14

  7. Example: Long parameter Lists ¡ ( defn ¡ make-­‑cheese ¡ ¡ ¡[name ¡ ¡ ¡region ¡ ¡ ¡country ¡ ¡ ¡aoc? ¡ ¡ ¡pdo? ¡ ¡ ¡doc? ¡ ¡ ¡milk-­‑origin ¡ ¡ ¡milk-­‑origin-­‑subspecies ¡ ¡ ¡pastuerized? ¡ ¡ ¡aging-­‑time ¡ ¡ ¡mould-­‑type]) Friday, 9 May 14

  8. ( make-­‑cheese Example: Long ¡"Bleu ¡de ¡Gex" ¡ ¡"Jura" ¡ parameter ¡"France" ¡true ¡ Lists ¡false ¡ ¡false ¡ ¡ ¡:cows ¡ ( defn ¡ make-­‑cheese ¡ ¡"Montbéliard" ¡ ¡ ¡[name ¡false ¡ ¡( weeks ¡3) ¡ ¡ ¡ ¡region ¡"Penicillium ¡glaucum") ¡ ¡ ¡country ¡ ¡ ¡ ¡aoc? ( make-­‑cheese ¡ ¡"Stilton" ¡ ¡ ¡ ¡pdo? ¡["Derbyshire" ¡"Leicestershire" ¡ ¡ ¡ ¡doc? "Nottinghamshire"] ¡ ¡ ¡ ¡milk-­‑origin ¡"United ¡Kingdom" ¡ ¡false ¡ ¡ ¡ ¡milk-­‑origin-­‑subspecies ¡true ¡ ¡ ¡ ¡pastuerized? ¡false ¡ ¡ ¡ ¡aging-­‑time ¡:cows ¡ ¡"local" ¡ ¡ ¡ ¡mould-­‑type]) ¡true ¡ ¡( weeks ¡9) ¡ ¡"Penicillium ¡roqueforti") Friday, 9 May 14

  9. What smells? Hard to read Hard to change Error prone (easy to switch around literals) Friday, 9 May 14

  10. What Next steps smells? Obvious refactoring: extract parameter objects, alternative Hard to read functions make-­‑uk-­‑ Hard to change cheese Error prone (easy to But... indicates switch around literals) underlying issues with how we have chosen to model our data - can we address that too? Friday, 9 May 14

  11. “Standard” Code Smells Martin Fowler + Kent Beck in “Refactoring...”: http:// www.amazon.co.uk/Refactoring- Improving-Design-Existing-Technology/ dp/0201485672 Define a standard set of smells focussed on OO and statically typed languages (Java) Friday, 9 May 14

  12. Taxonomy Parallel Inheritance Hierarchies Shotgun Surgery Message Inappropriate Chains Intimacy CHANGE Divergent PREVENTERS Change Middle Man Primitive Feature COUPLERS Large Obsession Envy Class Long Parameter List Long BLOATERS Method Refused Duplicate Bequest Code Temporary Data class Alternative Classes DataClumps Field Dead Code with Different Interfaces DISPENSIBLES Lazy class OO Switch Speculativ ABUSERS Statements e Generality Mäntylä, M. V. and Lassenius, C. "Subjective Evaluation of Software Evolvability Using Code Smells: An Empirical Study" . Journal of Empirical Software Engineering, vol. 11, no. 3, 2006, pp. 395-431. Friday, 9 May 14

  13. What do code smells look like in Clojure? (Or: What do they smell like?) Friday, 9 May 14

  14. ... and why do we care? Friday, 9 May 14

  15. My CV 2000s 2010s Pascal C# C C++ JavaScript Ruby Java Clojure Friday, 9 May 14

  16. My CV 2000s 2010s Pascal C# C C++ JavaScript IMPERATIVE Ruby Java EXPRESSION Clojure ORIENTED Friday, 9 May 14

  17. My CV 2000s 2010s Pascal C# C C++ JavaScript (Mainly) OO Ruby Java Clojure FUNCTIONAL Friday, 9 May 14

  18. Friday, 9 May 14

  19. Building on prior work Parallel Inheritance Hierarchies Shotgun Surgery Message Inappropriate Chains Intimacy CHANGE Divergent PREVENTERS Change Middle Man Primitive Feature COUPLERS Large Obsession Envy Class Long Parameter List Long BLOATERS Method Refused Duplicate Bequest Code Temporary Data class Alternative Classes DataClumps Field Dead Code with Different Interfaces DISPENSIBLES Lazy class OO Switch Speculativ ABUSERS Statements e Generality Friday, 9 May 14

  20. OO-Specific Stuff Parallel Inheritance Hierarchies Shotgun Surgery Message Inappropriate Chains Intimacy CHANGE Divergent PREVENTERS Change Middle Man Primitive Feature COUPLERS Large Obsession Envy Class Long Parameter List Long BLOATERS Method Refused Duplicate Bequest Code Temporary Data class Alternative Classes DataClumps Field Dead Code with Different Interfaces DISPENSIBLES Lazy class OO Switch Speculative ABUSERS Statements Generality Friday, 9 May 14

  21. A few edits... Shotgun Surgery Dead Code Duplicate Speculative Code Generality CHANGE Divergent PREVENTERS Change DISPENSIBLES Lazy Class function Large Class Primitive Obsession namespace Long Parameter Message Inappropriate List Chains Intimacy BLOATERS Middle Man DataClumps Feature COUPLERS Envy Long method function Friday, 9 May 14

  22. A few edits... Shotgun Surgery Dead Code Primitive Obsession Duplicate Speculative Code Generality CHANGE Divergent PREVENTERS “Primitive Obsession is using primitive data types to represent domain Change ideas. For example, we use a String to represent a message, an Integer to DISPENSIBLES Lazy function represent an amount of money, or a Struct/Dictionary/Hash to represent a specific object. ” http://c2.com/cgi/wiki?PrimitiveObsession Primitive Obsession Large namespace Long ... are collections in Clojure that primitive? Parameter Message Inappropriate List Chains Intimacy BLOATERS Middle Man DataClumps Feature COUPLERS Envy Long function Mäntylä, M. V. and Lassenius, C. "Subjective Evaluation of Software Evolvability Using Code Smells: An Empirical Study" . Journal of Empirical Software Engineering, vol. 11, no. 3, 2006, pp. 395-431. Friday, 9 May 14

  23. Clojure-specific Smells ??? ??? ??? DYS-FUNCTIONAL ??? CODE Friday, 9 May 14

  24. AKA: Data structure coupling Over-sharing structure / content of maps/records leading to implicit Magic Keys coupling (clavis magica) Friday, 9 May 14

  25. Example { ¡:name ¡"Stilton" ¡ ¡:milk ¡{:milk-­‑type ¡:cows ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡:origin-­‑subspecies ¡"local" ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡:is-­‑pasteurized? ¡true} ¡ ¡:mould-­‑type ¡"Penicillium ¡roqueforti" ¡ ¡:region ¡ ¡ ¡["Derbyshire" ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡"Leicestershire" ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡"Nottinghamshire"] ¡ ¡:country ¡"United ¡Kingdom" ¡ ¡:aging-­‑time ¡nil} Friday, 9 May 14

  26. Example ( defn ¡ calculate-­‑olfactory-­‑offence ¡ ¡[{:keys ¡[milk ¡mould-­‑type ¡aging-­‑time ¡washing-­‑solution]}] ¡ ¡( let ¡ [pasteurization-­‑factor ¡( if ¡ (:is-­‑pasteurized? ¡milk) ¡0.5 ¡1)] ¡ ¡ ¡ ¡(* ¡aging-­‑time ¡ ¡ ¡ ¡ ¡ ¡ ¡( + ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡( milk-­‑type-­‑>smell ¡(:milk-­‑type ¡milk)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡pasteurization-­‑factor ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡( mould-­‑>smell ¡mould-­‑type) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡( washing-­‑solution-­‑>smell ¡washing-­‑solution-­‑>smell))))) ¡ ( defn ¡ lactose-­‑levels ¡[{:keys ¡[milk ¡quantity]}] ¡ ¡( if ¡ (:is-­‑pasteurized? ¡milk) ¡ ¡ ¡ ¡( calculate-­‑pasteurized-­‑lactose-­‑levels ¡quantity ¡(:milk-­‑type ¡milk)) ¡ ¡ ¡ ¡( calculate-­‑unpasteurized-­‑lactose-­‑levels ¡quantity ¡(:milk-­‑type ¡milk)))) Friday, 9 May 14

  27. Example ( defn ¡ calculate-­‑olfactory-­‑offence ¡ ¡[{:keys ¡[ milk ¡mould-­‑type ¡aging-­‑time ¡washing-­‑solution]}] ¡ ¡( let ¡ [pasteurization-­‑factor ¡( if ¡ (:is-­‑pasteurized? ¡ milk ) ¡0.5 ¡1)] ¡ ¡ ¡ ¡(* ¡aging-­‑time ¡ ¡ ¡ ¡ ¡ ¡ ¡( + ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡( milk-­‑type-­‑>smell ¡(:milk-­‑type ¡ milk )) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡pasteurization-­‑factor ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡( mould-­‑>smell ¡mould-­‑type) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡( washing-­‑solution-­‑>smell ¡washing-­‑solution-­‑>smell))))) ¡ ( defn ¡ lactose-­‑levels ¡[{:keys ¡[ milk ¡quantity]}] ¡ ¡( if ¡ (:is-­‑pastuerized? ¡ milk ) ¡ ¡ ¡ ¡( calculate-­‑pastuerized-­‑lactose-­‑levels ¡quantity ¡(:milk-­‑type ¡ milk )) ¡ ¡ ¡ ¡( calculate-­‑unpasteurized-­‑lactose-­‑levels ¡quantity ¡(:milk-­‑type ¡ milk )))) ¡ Friday, 9 May 14

  28. What smells? Hard to figure out the cost of change of key names, data types etc. Unexpected errors if data is in the wrong shape in production ... too many fns know the intimate details about the structure. Easy mess to get into - tradeoff of modelling data as maps Friday, 9 May 14

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend