Your code is your labor, so keep it SOLID
Autor: Nikola Poša |
Datum:
  • # PHP Science

PHP is probably the most popular programming language nowadays, but let’s face it, PHP has somewhat of a bad reputation. This is partly attributed to its procedural roots, but also to novice "developers" producing the huge amounts of bad code. Most of the credit for PHP’s popularity goes to its low learning curve. It is super-easy to get started, but one can very easily get going in the wrong way. Unfortunately, this is very common case, because there are so many resources for getting started with PHP, whereas quality ones are lacking. But it does not have to be so. If you are a newbie, start learning it the right way, and throw out that outdated PHP 4 books, or some lame “Hello world” and PHP/MySQL online tutorials. Move to the essence, to the real deal. Pick some framework, but do not fall in love with only one of them, try several.

What can not be seen at first glance is that PHP is a full-fledged object-oriented programming language, just like Java, C#, C++, Python. Thus same OOP terms and principles apply in case of a PHP, like for example design patterns, software architecture, best practices and similar. What distinguishes good from the average developer is how well they are dealing with these principles.

OOP is certainly not wrapping stuff in classes, but the creation and design of the building blocks of a software system, so that it is modular, cohesive and easy to maintain. This may be hard to achieve, but luckily, some smart people have already invented and came up with principles and solutions that developers can apply. The most important well established principle, basis for more advanced concepts is a set of principles called SOLID. Originally introduced by Robert C. Martin, these principles provide a solution for moving from tightly coupled code with poor cohesion to the preferred loosely coupled, cohesive and maintainable code. SOLID is actually an acronym, whereas each letter represents one principle:

  • Single responsibility principle
  • Open/closed principle
  • Liskov substitution principle
  • Interface segregation principle
  • Dependency inversion principle

 

Very professional and profound explanation of SOLID as well as some other OOP concepts can be found in this article: S.O.L.I.D. Software Development, One Step at a Time. It is also useful to know that SOLID has its opponent – STUPID. So don't be STUPID: grasp SOLID!

If you haven’t stumbled upon SOLID before, you have probably heard of design patterns. Don’t confuse SOLID with design patterns. SOLID is not a design pattern, but rather a groundwork principle of object-oriented programming. Design patterns suggest solutions for common programming problems. There are plenty of quality resources regarding design patterns in general, but many of them are suitable only for advanced developers. Brandon Savage’s Practical Design Patterns in PHP book and PHP: The Right Way - Design patterns chapter are some recommendations for good reading material.

Intrigued by this text? Well, you should be, because PHP Serbia will be organizing a big event on May 30, 2015 – SOLIDay conference. Nicely coined name, huh? It will be one of the major events in the region, where you will have opportunity to attend presentations of prominent international PHP experts and professionals, on the topic of OOP principles, design patterns, software architecture, frameworks and similar. Whether you are a novice, intermediate or advanced developer, join us on this conference and expand, improve or simply refresh your knowledge of this important topic. In addition to the conference itself, another big event will take place the day before - workshop led by Mathias Verraes! Don't miss this unique opportunity to learn something that you won't learn or didn't learn at college.

Visit the official website of the SOLIDay conference