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

Dotting your i's and crossing your t's - how to make good code great

Dotting your i's and crossing your t's - how to make good code great

Presented on October 3rd 2015 at the PHP North West, Manchester, United Kingdom.
http://conference.phpnw.org.uk/phpnw15/
---------------------------------------------------------------
Ever had to go back to code you did over a year ago? And, did you like it? We all love well documented, testable, easily readable and understandable code. But how do you write it, and what tools are available to help you? What can you do now to make your life and the life of your successor(s) and users easier?

Learn how to avoid a build up of technical debt and make your good code awesome!
---------------------------------------------------------------

If you download the slides, the links should be clickable. Unfortunately they don't seem to be in the online deck, so here's a list of the links:

Slide 10
Technical debt in PHP projects: http://blog.insight.sensiolabs.com/2014/11/04/technical-debt-relevant-projects.html

Slide 11
Types of Technical Debt: http://www.martinfowler.com/bliki/TechnicalDebtQuadrant.html

Slide 12
How Quality affects software costs: http://www.sqgne.org/presentations/2010-11/Jones-Nov-2010.pdf

Slide 14
PHPUnderControl: http://phpundercontrol.org/
Sonar: http://www.sonarsource.com/

Slide 19
PSRs: http://www.php-fig.org/

Slide 20 - Debugging tools:
XDEBUG: http://xdebug.org/
PHP lint: http://www.icosaedro.it/phplint/
JS lint + hint: http://www.jslint.com/ , http://www.javascriptlint.com/ , http://www.jshint.com/
Firebug: http://getfirebug.com/
Profile: https://github.com/joehoyle/Time-Stack

Slide 21 - Educate yourself:
PHP manual: http://php.net/manual
PHP The Right Way: http://phptherightway.com/
ClearPHP: https://github.com/dseguy/clearPHP/blob/master/rules/README.md
phpcheatsheets.com: http://phpcheatsheets.com/
OWASP top 10: http://owasp.org/

Slide 28
PHP Code Sniffer: http://pear.php.net/package/PHP_CodeSniffer/
PHP CS-Fixer: http://cs.sensiolabs.org/

Slide 30
PHP cross-version compatibility ruleset for PHPCS: https://github.com/wimg/PHPCompatibility

Slide 38
PHPDocumentor: http://www.phpdoc.org/
PHPDox: http://phpdox.de/
ApiGen: http://www.apigen.org/

Slide 43
PHPUnit: http://phpunit.de/

Slide 45
Codeception: http://codeception.com/
Behat: http://behat.org/
Selenium: http://docs.seleniumhq.org/

Slide 48
pDepend: http://pdepend.org/
PHPLOC: https://github.com/sebastianbergmann/phploc

Slide 49
PHP Mess Detector: http://phpmd.org/

Slide 50
PHP Copy Paste Detector: https://github.com/sebastianbergmann/phpcpd

Slide 51
PHP Dead Code Detector: https://github.com/sebastianbergmann/phpdcd

Slide 56
Git hooks: http://git-scm.com/docs/githooks.html and http://git-scm.com/book/en/Customizing-Git-Git-Hooks
Phing: http://www.phing.info/
Robo: http://robo.li/
Grunt: http://gruntjs.com/
Capistrano: http://capistranorb.com/
Gulp: http://gulpjs.com/

Slide 57:
Sonar: http://www.sonarsource.com/
Jenkins: http://jenkins-ci.org/
Travis: https://travis-ci.org/
Scrutinizer CI: http://scrutinizer-ci.com/
Circle CI: https://circleci.com/
PHP-CI: https://github.com/block8/phpci
Atlassian Bamboo: https://www.atlassian.com/software/bamboo
Exakat: http://www.exakat.io/online-demo/

Slide 62
Geek and Poke: http://geek-and-poke.com/
OSNews: http://osnews.com/comics

Slide 63:
Slides - well, you found them already ;-)
Feedback: https://joind.in/15432
Contact me: https://twitter.com/jrf_nl

Juliette Reinders Folmer

October 03, 2015
Tweet

More Decks by Juliette Reinders Folmer

Other Decks in Programming

Transcript

  1. Dotting Your I's and Crossing Your T's
    How to Make Good Code GREAT
    Juliette Reinders Folmer
    @jrf_nl

    View Slide

  2. #phpnw15
    Who Am I?
    Self-employed,
    Independent
    Consultant
    Creator
    PHPCheatsheets
    phpcheatsheets.com
    Contributor to
    many open
    source projects

    View Slide

  3. #phpnw15

    View Slide

  4. #phpnw15

    View Slide

  5. #phpnw15

    View Slide

  6. #phpnw15
    Properties of Quality Code
    Maintainable Extensible Re-usable

    View Slide

  7. #phpnw15

    View Slide

  8. #phpnw15
    Potential
    defects
    Coding style Documentation
    Code coverage
    Code
    duplication
    Code
    complexity
    Unshared
    knowledge or
    code
    Unstable
    deployment
    process
    Outdated third
    party
    dependencies
    Technical Debt

    View Slide

  9. #phpnw15

    View Slide

  10. #phpnw15

    View Slide

  11. #phpnw15
    Types of Technical Debt
    Martin Fowler's Quadrant - © Martin Fowler

    View Slide

  12. #phpnw15
    Why Bother ?
    ©2010 Capers Jones & Associates LLC

    View Slide

  13. #phpnw15
    Technical debt
    accumulates interest.
    Just like financial debt...

    View Slide

  14. #phpnw15
    Estimating & Prioritizing
     PHPUnderControl
     Sonar

    View Slide

  15. Mitigating Technical Debt

    View Slide

  16. #phpnw15
    Mitigating
     Inventarize
    & managing
     Prioritize
     Budget

    View Slide

  17. #phpnw15

    View Slide

  18. Prevent Bugs

    View Slide

  19. #phpnw15
    Prevent Bugs
     Apply best practices
    • APIs
    • Security
    • Avoid conflict
    • Lean & mean
    • Optimize
    • Apply PSR's

    View Slide

  20. #phpnw15
    Prevent Bugs
     Apply best practices
     Use debugging tools • error_reporting()
    • XDEBUG
    • PHP lint
    • JS lint + hint
    • Firebug + extensions
    • Profile

    View Slide

  21. #phpnw15
    Prevent Bugs
     Apply best practices
     Use debugging tools
     Educate yourself
    • PHP manual
    • PHP The Right Way
    • Clear PHP
    • phpcheatsheets.com
    • OWASP top 10
    • Conferences !

    View Slide

  22. Version

    View Slide

  23. #phpnw15
     CVS
     SVN
     GIT

    View Slide

  24. #phpnw15

    View Slide

  25. Style

    View Slide

  26. #phpnw15

    View Slide

  27. #phpnw15
    PHP Coding Standards
    PSR-1 PSR-2 PEAR
    Squiz
    Zend
    Framework
    Symphony
    Drupal WordPress TYPO3 Magento CakePHP
    FuelPHP ....

    View Slide

  28. #phpnw15
    PHPCS
    (PHP Code Sniffer)
    PHP-CS-Fixer

    View Slide

  29. #phpnw15

    View Slide

  30. #phpnw15
    https://github.com/wimg/PHPCompatibility

    View Slide

  31. #phpnw15

    View Slide

  32. Document

    View Slide

  33. #phpnw15

    View Slide

  34. #phpnw15

    View Slide

  35. #phpnw15
    Documenting Your Code
    /**
    * Retrieve the (cached) file list for path.
    *
    * @param string $path
    * @param bool|null $recursive
    * @param string|array $allowed_extensions
    *
    * @return array|false File list array or false if an invalid path was provided
    */
    public static function get_file_list( $path, $recursive = false, $allowed_extensions = null ) { }

    View Slide

  36. #phpnw15
    Documenting Your Code
    /**
    * Retrieve the (cached) file list for path.
    *
    * @todo Check how optimized scandir() is and whether it would be useful to get a list
    * of all files first and only later filter for allowed extensions / subdirs.
    *
    * @since 0.5
    *
    * @uses DirectoryWalker::$cache
    * @uses DirectoryWalker::validate_exts()
    * @uses DirectoryWalker::traverse_directory()
    *
    * @static
    *
    * @param string $path Path to directory.
    * @param bool|null $recursive Whether or not to walk subdirectories.
    * @param string|array $allowed_extensions Array of extensions to filter the files on.
    *
    * @return array|false File list array or false if an invalid path was provided
    */
    public static function get_file_list( $path, $recursive = false, $allowed_extensions = null ) { }

    View Slide

  37. #phpnw15

    View Slide

  38. #phpnw15
    PHPDocumentor
    PHPDox
    ApiGen

    View Slide

  39. #phpnw15

    View Slide

  40. #phpnw15

    View Slide

  41. Test

    View Slide

  42. #phpnw15

    View Slide

  43. #phpnw15
    http://phpunit.de/

    View Slide

  44. #phpnw15

    View Slide

  45. #phpnw15
    Codeception
    Behat
    Selenium

    View Slide

  46. Analyse & Refactor

    View Slide

  47. #phpnw15
    Metrics
    Code
    smells
    Cyclomatic
    complexity
    Npath
    complexity
    CRAP index

    View Slide

  48. #phpnw15
    pDepend
    PHPLOC

    View Slide

  49. #phpnw15
    PHPMD

    View Slide

  50. #phpnw15
    PHPCPD
    (PHP
    Copy
    Paste
    Detector)

    View Slide

  51. #phpnw15
    PHPDCD
    (PHP
    Dead
    Code
    Detector)

    View Slide

  52. #phpnw15
    --verbose

    View Slide

  53. #phpnw15

    View Slide

  54. Automate

    View Slide

  55. #phpnw15

    View Slide

  56. #phpnw15
     Git hooks
     Phing
     Robo
     Grunt
     Capistrano
     Gulp
    ... etc...

    View Slide

  57. #phpnw15
     Sonar
     Jenkins
     Travis
     Scrutinizer CI
     Circle CI
     PHP-CI
     Atlassian Bamboo
     Exakat
    ... etc...

    View Slide

  58. Team

    View Slide

  59. #phpnw15

    View Slide

  60. #phpnw15

    View Slide

  61. #phpnw15
    Always code as if the guy
    who ends up maintaining
    your code will be a violent
    psychopath who knows
    where you live.
    - Martin Golding
    O’Reilly


    View Slide

  62. #phpnw15
    Liked the Cartoons ?
    Also: the WTF Quality cartoon
    by Thom Holwerda – OSNews.com
    Geek and Poke is a creation of
    Oliver Widder
    Cartoons used with gracious CC permission
    Visit geek-and-poke.com for more !

    View Slide

  63. Thank You!
    Slides: http://speakerdeck.com/jrf
    Feedback: https://joind.in/15432
    Contact me: @jrf_nl

    View Slide