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.