Why turn absolutely everything into Classes in PHP?

Asked

Viewed 102 times

2

My systems both in ASP, Delphi and PHP maintains a kind of old standard (procedural) in the programming mode, because I find it boring to program as it is today, I see many or otherwise all using Classes, Objects and the like in such simple routines and make maintenance a burden at least for me, I know it’s best to follow the market not to be left behind, and I’m doing this by trying to understand better about classes and their allies, rs, today I make use of Templates in PHP and Inheritances in Delphi and try to separate common routines and functions in Units, leaving the code as readable as possible.

Of course I use some classes including third parties that facilitate life, I confess that I do not seek to understand what the user wanted to do but if it works, because my time is very scarce.

But going deeper into classes on the web, I saw that some like me are reluctant to make 100% use of classes, leaving it only to cases where the code gets huge in a routine.

Netbeans for example suggests that a function is no more than 20 lines long, I am far from reaching any degree of a Netbeans programmer, but I keep thinking, if I dismember my functions every 20 lines my files will get very fragmented, and the reading of those will be horrible.

I will try not to take sides on whether it is good or not, I have read that classes are slower than procedural (I found it strange), in turn I have seen that class is widely used, by itself already shows that it can be better.

Making my comparisons could not see real advantage of using classes in systems not so complex, I have seen that many programmers use class for example in a simple Insert, Select, Delete making a simple execution in a tangle of codes, where a simple function would solve the problem.

I’ll take PHP as an example, I know that many internal functions make use of classes, but to use them I really need to make use of them too?

The use of classes would not be to organize the code, it would not be better to leave the use of classes to create objects, for example connection, or some complex calculation, just as they are made with various Dlls and Components in Delphi and others?

I sincerely and honestly am wanting to be convinced that I must make constant use of classes just as I have seen in the PHP codes that I have picked up.

Look I’m only studying classes and I hope to understand and make good use of them, do not understand this post as critical but as a discussion that can yield good fruits to both me and those who read.

  • 2

    And why would you do that? It’s the opposite of what you should do. Do right and be happy, don’t go after fools who don’t know what they’re doing. People’s time is scarce because they spend a lot of time trying to fix the mistakes they make because they don’t qualify properly, because they use inappropriate tools and then need to do a lot of extra work to make it work instead of using the simple and correct. Not knowing very well what it is and how to use OOP right, it is better not to use (and almost everyone uses wrong).

  • 2

    Suggestions like the Netbeans IDE don’t make any sense and are only meant to please laymen. 1 line can be too big, and 200 may not be. In general, I don’t know where this idea comes from, which class is slower. It must be another of the myths that are out there. Slower than what? It is possible in some comparison, but if you want speed do not use PHP. Your vision seems to be above average, except for hearing myths. Most of the use of classes does not need to, especially in PHP. Organize codes in a language of script? I’ve been using OOP for 30 years and I haven’t learned everything I should.

  • 2

    Do you think it’s easy? It’s only for those who decided to do it the way it was in some book and don’t mind doing it wrong. Most people use classes to satisfy their ego and say they’re on the crest of the wave.

  • 'Cause it’s Maniero, I’ve never liked going on the wave of mass, I’ve always stuck to the simple and functional and that way I’m going through life, but you know that moment when you stop and say, I need to get up to speed, and then self-criticism starts all over again, I’m not an auto-level programmer, but at least everything I’ve been asked to do so far I’ve been able to solve with what I already know, but sometimes I take some "foreign" codes and I get a little lost, so the need to know at least a little bit.

  • As to say which class is slower, in theory I even agree, if the processor needs to take more steps to perform a task, technically it will be slower, imagine the processor creating N objects, setting values for later useslas, some code in class that I see is as if the programmer wants to go in the neighbor to the right around the block to the left, I think that at this point that enters his vision, the guy is doing wrong so it slows down, agree, so to use classes you have to have a very but very thorough analysis.

  • That. I talk about it a lot: https://answall.com/search?tab=votes&q=user%3a101%20%5borienta%C3%A7%C3%a3o-a-objetos%5d OOP is hard to do right.

  • The link is not working

  • 1

    I think the biggest mistake/mistake to think that OO is solution/better, in languages where you can simplify things create class for any little thing is a huge exaggeration, I just follow the rule "this will be useful to me or easier so, then I do it". There are codes that simply proceed of a 5 lines in a php file solve a whole problem, have code that depending on the business rules separate in layers will be better, there is no way to define each case is a case, it is all relative.

  • 2

    No matter how much they tell you O is overrated, you will feel the need to be on the crest of the wave, this will consume you, undermine you and end your ability to design solutions, you will no longer know what is right and wrong and will sink into a sea of hype, methodologies and good practices! Release me! Release! Not injection! .... But seriously, if you are studying OOP try to study law, avoid applying inheritance unnecessarily, give preference to composition and others cositas but.

  • I think I am mature to avoid the issue "wave crest", my age is no longer favorable to face the job market tooth and nail, my ideas consist of presenting simple solutions and that of the necessary return to the customer without fuss, like "this solution will solve your life!!!" , I think that sobriety will bring less stress to me and the client, even if it costs me some job losses, I’m giving priority to life, so much that I moved to the interior, my stress was slowly killing me, so I want to apply classes where it’s really necessary.

  • 1

    @Marcelo that good, I am 48 years old and have difficulty (but resist :) ) It is not easy to adopt or reject something. And it is easy to decide wrong. Usually you only realize after you’ve decided wrong, and this is lucky, most don’t realize.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.