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

Clean Code Developer Orange Grade

Clean Code Developer Orange Grade

Learn the principles and practices of Clean Code Development. This is the second session in the Clean Code Development track. Go on with the next level and dig into Clean Code.

Mark Paluch

August 02, 2013
Tweet

More Decks by Mark Paluch

Other Decks in Programming

Transcript

  1. Clean Code Developer
    A way to better code
    Session 02
    https://github.com/mp911de/CCD
    Freitag, 2. August 13

    View full-size slide

  2. Agenda
    • Orange Grade
    Freitag, 2. August 13

    View full-size slide

  3. Orange Grade
    Freitag, 2. August 13

    View full-size slide

  4. Orange Grade
    • Principles
    • Single Level of
    Abstraction (SLA)
    • Single Responsibility
    Principle (SRP)
    • Separation of Concerns
    (SoC)
    • Source Code
    Conventions
    • Practices
    • Issue tracking
    • Automated integration
    tests
    • Read, read, read
    • Reviews
    Freitag, 2. August 13

    View full-size slide

  5. Single Level of Abstraction
    • A line of code has an abstraction-level
    • if/switch/for
    • getProperty()
    • publish()
    • Keep one method on one level
    • Improves readability and understandability
    Freitag, 2. August 13

    View full-size slide

  6. Violation of Single
    Level of Abstraction
    Freitag, 2. August 13

    View full-size slide

  7. Single Level of Abstraction
    after Refactoring
    Freitag, 2. August 13

    View full-size slide

  8. Single Level of Abstraction wrap-up
    • Top-Down-Design
    • Main control routine
    • Subroutines
    • That guys which do something
    • Look at the newspaper: Headline, Sub-Header, Content
    Freitag, 2. August 13

    View full-size slide

  9. Single Responsibility Principle
    • There is no more than one reason to change a class
    • Responsibility is
    • Parsing HTML/XML
    • Generating a data transfer object
    • Wrapping external libraries
    • Bad Example: Building HTML, pushing it via FTP and sending a mail in
    one class
    • Design and divide your code by domains (what a unit is responsible for)
    Freitag, 2. August 13

    View full-size slide

  10. SRP Violation
    Freitag, 2. August 13

    View full-size slide

  11. SRP after
    Refactoring
    Freitag, 2. August 13

    View full-size slide

  12. Separation of Concerns
    • Concerns encapsulate multiple responsibilities
    • A responsibility belongs to one concern
    • Encapsulation
    • Demands a definition what exactly a code unit/module is
    responsible for
    Freitag, 2. August 13

    View full-size slide

  13. Concerns are
    • Logging
    • Transaction Management
    • Security
    • Caching
    Freitag, 2. August 13

    View full-size slide

  14. Concerns wrap-up
    • Business logic has no
    infrastructure/resource
    accessors
    • Business logic may
    produce logging but
    does not care about
    log pattern processing/
    logfiles
    Freitag, 2. August 13

    View full-size slide

  15. Source Code Conventions
    • Everybody is individual – else we are Borg
    • Commit on naming and comments
    • Process of max. 5 minutes
    int length;
    int len;
    int l;
    int lengthMM;
    int laenge;
    function Price()
    function getPrice()
    Function getGrossPrice()
    Freitag, 2. August 13

    View full-size slide

  16. Issue Tracking
    • Master of chaos – everything is random
    • Enclose your work within a context
    • Trace what you‘ve done and use issue/ticket no. in your
    SCM commit message
    • SCM history tells hints at a context
    Freitag, 2. August 13

    View full-size slide

  17. SCM Horror
    512545 2012-01-02 13:37:00 Derp. Fix missing constant post rename
    512545 2012-01-02 13:37:00 lots of changes after a lot of time
    512545 2012-01-02 13:37:00 Committing fixes in the dark, seriously, who killed my
    power!?
    9533 2012-05-23 16:45:51 That last commit message about silly mistakes pales in
    comparision to this one
    9363 2012-05-15 15:11:51 Minor updates
    9131 2012-05-09 16:01:53 totally more readable
    9131 2012-05-09 16:01:53 QuickFix.
    Freitag, 2. August 13

    View full-size slide

  18. Automated Integration Tests
    • Test first: Life insurance
    • Unit Tests: Test your production Code
    • Integration Test: Test with partial/full integration of
    databases, remote systems
    • Depend on environment
    • Be careful on QA/production systems
    • Repetitive task: Why doing it manually, automate it!
    Freitag, 2. August 13

    View full-size slide

  19. Read, Read, Read
    • Read Code
    • Read Books
    • Read Blogs
    • Read about techniques to improve yourself and your code
    Freitag, 2. August 13

    View full-size slide

  20. Reviews
    • Two see more than one
    • Increase quality, not being inspected
    • Prevent bugs
    • Cross check: Does your peer share the same opinion
    • Pass/Gather knowledge
    • Code-/Condept-Reviews
    • Pair Programming
    Freitag, 2. August 13

    View full-size slide

  21. Image Credits
    Table of Contents: © by Michael Kappel http://michaelkappel.com
    Bands: © by Alexander Herzog
    Freitag, 2. August 13

    View full-size slide