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

Improving Code Quality

Improving Code Quality

PHP Reboot meetup slides, presented on 24th June, 2017 at Ansh Systems Pvt. Ltd.

Avatar for Kapil Sharma

Kapil Sharma

June 24, 2017
Tweet

More Decks by Kapil Sharma

Other Decks in Programming

Transcript

  1. About me • Name: Kapil Sharma • Technical Architect at

    Eastern Enterprise B.V. • Working in Web development since 12+ years, mainly in PHP. • Twitter: @kapilsharmainfo • Facebook: /kapilsharmainfo • LinkedIn: kapilsharmainfo • Web: kapilsharma.info • Slides: speakerdeck.com/ kapilsharma 2
  2. About PHP Reboot • PHP developers community in Pune, India.

    • Conduct regular meet ups • meetup.com/phpreboot • phpreboot.com • Twitter: @phpreboot • Facebook: /PHReboot • Slack: phpreboot.signup.team 3 • Virtual team developing open source. • PHPreboot.com is open source website • github.com/phpreboot/website • Issues: waffle.io/phpreboot/ website • Contributions welcome. • Online webinars
  3. PHPReboot.com Kapil Sharma What is code quality? • External 5

    • Mainly functional -> Minimal bugs • Can be identified by QA and client. • Internal • Structure of code. • Can be identified in code review.
  4. PHPReboot.com Kapil Sharma Defining good code 6 • Easy to

    understand. • Easy to maintain. • For humans (not computer). • Current and future requirements.
  5. PHPReboot.com Kapil Sharma – Martin Fowler. Anyone can write code

    that computer can understand. Easy to understand Good developers write code that Humans can understand.
  6. PHPReboot.com Kapil Sharma 1. Follow style guide 14 PSR-2 Coding

    Style Guide Pear Coding Standards Zend Coding Standards JS Standard PEP PHP Code Sniffer PHP QA Tools gist https://gist.github.com/kapilsharma/db0f3754146899ec7948c826139cb97c
  7. PHPReboot.com Kapil Sharma 2 - Create descriptive names • Method/function

    • Reader should not need to see the code. • Variable • Should tell what it stores. • Class • Must tell what exactly it do. • Namespace/package/library • Should have complete functionality. 15 Don't write whole story as name
  8. PHPReboot.com Kapil Sharma 3 - Comment and Document • Doc-block

    for every class/method • For important functionality/complex code. 16 Refactoring: Extract method for comment.
  9. PHPReboot.com Kapil Sharma 5 - Split code into short, focused

    units • Method name suggest exactly what it do. • Method must fit in one screen. (<30 lines) • No much dependency. • Testable. • Simple. 18
  10. PHPReboot.com Kapil Sharma 7 - Use inbuilt functions and 3rd

    party lib. • Do not rediscover wheel. • Learn the basics and details of your language. • Keep watching top open source libraries. 20 Invest in yourself.
  11. PHPReboot.com Kapil Sharma 8 - Don’t over-design. • Keep design

    focused on today’s need. • It doesn’t mean do not follow Open-close principle. • Design for future requirements, only if they do not complicate design. • Don’t make parameterised class, method, factory, deep inheritance etc to solve problem that do not exist. 21
  12. PHPReboot.com Kapil Sharma 9 - Unit test • Learn about

    Unit test or Test Driven Development. 22 TDD Workshop https://github.com/kapilsharma/tddworkshop