There is this one thing that I saw as of late and that worries me: PHP devs don’t utilize capacities.
Presently, that was excessively broad, so let me clear up: PHP engineers who have achieved a specific level of advancement essentially quit utilizing plain capacities?—?rather everything goes all classes and techniques. In any event that is the perception I made when taking a gander at different open-source libraries and structures. The main sort of capacity you’ll discover in any of the “superb” libs are unknown capacities. In any case, that is practically it.
In the event that you take a gander at different dialects, the scene is extraordinary. For instance Python code will to a substantial part be class definitions, however there will dependably be ordinary capacities in the middle.
So in PHP capacities are fundamentally utilized in two cases: If the software engineer doesn’t yet utilize OOP or if the content does not merit utilizing OOP for. The idea of “aide capacity” or something to that effect does not appear to exist.
This to some degree concerns me since I surmise that staying everything into classes isn’t generally the best activity. This sort of conduct ordinarily prompts Class-Oriented Programming, where you are essentially simply utilizing classes for utilizing them. (Update: Using classes does not mean your code is question situated!)
I additionally feel that the hesitance to characterize partner capacities is the thing that prompts the push for an ever increasing number of capacities in the PHP center. E.g. I as of late have seen a couple of individuals requesting some sort of array_rand_value work. This capacity would essentially be the same as array_rand, however it would restore an incentive rather than a key. So it could be characterized in userland code in two lines:
function array_rand_value(array $array) {
if (empty($array)) return null;
return $array[array_rand($array)];
}
This is a little capacity that you can without much of a stretch characterize yourself. Be that as it may, at that point emerges what I believe is the primary issue: Where would it be advisable for you to put it? How would I consolidate it with the autoloader?
PHP to huge parts acquired the Java OOP model and one thing that accompanied it is having a balanced mapping among classes and records. PHP does not implement this, but rather it is an extremely regular tradition. PHP’s autoloading help and the PSR-0 standard are stressing this further.
Different dialects like PHP don’t have this tradition. For instance in Python it is extremely typical to characterize various related classes and capacities in a single document. In Python a record is somewhat a module, i.e. a gathering of related segments. In such a setup it is clearly considerably less demanding to characterize little capacities in the middle.
For the most part I surmise that the balanced record mapping so regular in PHP is hazardous. Aside from making it difficult to utilize capacities it likewise adds an extra expense to making little classes:
Protest situated programming done right for the most part prompts countless classes. This is incredible for code reuse, viability and testing.
In any case, in PHP you need to make another record for each one of those classes. What’s more, this is truly getting in my direction. I’d have no issue cluster characterizing ten small classes in a single document. Be that as it may, I have a craving for making ten unmistakable records for them is counterproductive (and hampers viability).
Another extraneously related “standard” practice I feel seriously about is the exorbitant utilization of doccomments. Much of the time phpdoc remarks simply remark the self-evident?—?at the same expanding the code estimate by a factor of a few. I have no issue with doccomments where vital, however as a rule (in any event with all around outlined code) the conduct ought to be clear from the technique and parameter names.
Thus, essentially, what I’m pondering here is as a rule more “minimal”: Instead of characterizing a record for each class, put related (littler) classes into one document. Rather than characterizing a class for everything, simply utilize a capacity. Rather than jumbling the code with bunches of futile doccomments, simply forget them except if extremely important.
Be that as it may, it’s only an idea ;) Maybe I failed to understand the situation.