Subscribe to PHP Freaks RSS

Jason McCreary: Writing Clean Code (Part 2)

syndicated from www.phpdeveloper.org on October 19, 2017

Jason McCreary has continued his series looking at writing "clean code", providing a few helpful hints you can integrate into your daily development work. In part two he goes a bit "deeper" and talks about grouping and encapsulation.

In Part 1 of Writing Clean Code I outlined three simple practices of formatting, naming, and avoiding nested code. All in an effort to improve code readability.

In Part 2, I want to go a little deeper and cover grouping. When I say grouping, I’m really talking about the Object Oriented Programming paradigm of encapsulation. Whether we group the code into a function or a class is often not important. What is important is did we improve the readability of the code.

He starts off by describing the goal of this grouping and lists three motivations for using it as a part of your application's architecture:

  • Improving communication
  • Couple data
  • Organizing code

For each, he includes a brief summary of the topic and some code examples illustrating it in action where appropriate.