PHP Classes

Wrong best practices

Recommend this page to a friend!

      PHP Classes blog  >  PHP Current State and...  >  All threads  >  Wrong best practices  >  (Un) Subscribe thread alerts  
Subject:Wrong best practices
Summary:Newby programmers are being taught the wrong best practices
Messages:3
Author:Anthony J Marston
Date:2023-06-15 10:41:21
Update:2023-06-15 14:21:45
 

  1. Wrong best practices   Reply   Report abuse  
Picture of Anthony J Marston Anthony J Marston - 2023-06-15 13:40:50
I built enterprise applications for 20 years before I switched to PHP in 2002 in order to build the same applications for the web. I did not follow what are now taught as "best practices" as I did not know that they existed, so I simply adapted the practices that had proved themselves in the past.

I started with PHP 4 which supported encapsulation, inheritance and polymorphism but none of these later additions such as interfaces and exceptions. When I eventually discoverd what interfaces were I looked into them and discarded them as a waste of time. I do not need to define an interface before I can define a method in a class. I had also learned the benefit of inheriting from an abstract class, and I found this to be a far superior technique.

The biggest problem is the SOLID principles which have been seriously mis-interpretted and mis-applied over the years, with the biggest culprit being SRP. It should be noted that even the author of this principle had to correct his definition from "reason for change" to "Keeping these concerns [GUI, business rules, database] separate is good design". As far as I am concerned this second description is a 100% match to the 3 Tier Architecture which I had encountered in a previous language and which I had carried forward into my PHP development.

However, far too many of today's programmers are taught that SRP is based on the ability to count, not the ability to think. Instead of single large classes which exhibit strong cohesion they prefer to blindly follow the pseudo-rule which says "no class can have more than N methods" and "no method can have more than N lines of code". The end result is a code base filled with tiny fragments where each method contains only a few lines of code (sometimes just one!). Even worse is where each method exists in its own class.

I find such code difficult to follow, impossible to debug and slow to run as the language has to spend far too much time in finding code to execute before it can actually execute it.

I don't make such mistakes as I was never taught to make those mistakes.

  2. Re: Wrong best practices   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2023-06-15 14:16:51 - In reply to message 1 from Anthony J Marston
Great points, Anthony. Congratulations on the maturity. Your future will be bright.

Software development should not be like a religion based on beliefs on which developers believe that certain practices are good because other developers said so.

The practices are good because they give good results that you can prove they work with evidence based on test results.

That is the difference between theory and practice. The theory is often based on beliefs. Practice is based on evidence, just like in science. Programming is also known as computer science.

Keep posting your comments because more developers need to learn from you.

  3. Re: Wrong best practices   Reply   Report abuse  
Picture of David Tamas David Tamas - 2023-06-15 14:21:45 - In reply to message 1 from Anthony J Marston
I completely agree with you. I also switched from "traditional" application development to the web and PHP. The two worlds are completely different, just as their best practices are also different.

Strictly following the SRP principle will quickly make your code unreadable and unnecessarily complicated.