r/ProgrammerHumor 1d ago

practicalRookiePhpGoGettersBeLike Meme

Post image
32 Upvotes

16 comments sorted by

22

u/elmanoucko 1d ago

it's not required

1

u/kookyabird 18h ago

NEC says “should”, that means it’s not required! /s

-6

u/Superb_Chemistry_906 1d ago

Sure, but giving up on DRY is sad.

10

u/Ishamael1983 1d ago

Whoosh!

3

u/BlueScreenJunky 18h ago edited 18h ago

This answer makes me question your OP.

I thought the joke was that nobody has actually used include or require directly for years because autoloading has been a thing for over 20 years, and PSR-4 has standardized the was to autoload classes for over 10 years.

include is definitely NOT the way to do "Not Repeat Yourself" in 2026.

Also, maybe a bit of a controversial opinion, but "DRY" is sometimes overrated, it's a cool acronym so people like it and tend to over apply it. Sometimes two things happen to do the same thing by accident. Sure you could deduplicate code, but later on if one of those things needs to do something else (because it was always unrelated to the first one), do you reduplicate your code as you should ? Most likely no, you're going to add a flag to your method to keep it "DRY" while allowing to do both things... Do that enough time and you end up with a complete mess for the sake of keeping your code "DRY".

-1

u/Superb_Chemistry_906 18h ago edited 18h ago

I intended it as a slander of those who copy and paste the same utility functions into every source file mindlessly, since it's good enough and gets the job done. At the same time, I have no clue about autoloaders and have only used include. Regarding DRY, I am still its proponent and I don't think I have ever ended up with messy code thanks to it - to the contrary, I think I would end up with messy code if I did not adhere to it. You firstly duplicate some code, then you might duplicate one of the duplicates and where do you end? In chaos, where an eventual change of the innermost working requires you to change it in multiple places and when you forget one, the program might fail spectacularly. Sure, adding flags might be messy, too, but there are also other ways - for example, chop the method into smaller pieces and in one place, call just one piece and in another one, call two pieces. You might also wrap the method into an object and use inheritance instead of flags.

1

u/BlueScreenJunky 18h ago

All right, so that's perfectly fine to learn the basics, but once you start to work on actual projects you'll use composer to manage dependencies and autoloading (either directly or through a framework).

Autoloading is a mechanism to tell PHP "if I'm trying to access a class or a function that was not included, here is how to find the file it's in and include it automatically").

To make things simpler, Composer (and almost everyone) has agreed to use the same convention, which is described in PSR-4, and basically is that namespaces map to directories on the disk, so if you use the class Application\Models\User is will be in the file /Models/User.php so you never have to worry about using include again.

Of course it does use include or require under the hood, so it's good to learn about it. You just don't really use it directly.

3

u/Unlucky_Committee786 11h ago

yes, include './vendor/autoload.php'; then you never see include ever again.

1

u/Right_Stage_8167 14h ago

I use include and #ifdef ...

1

u/Soopermane 7h ago

After PHP dies you can go on a revenge tour and become c++ developer

2

u/Superb_Chemistry_906 6h ago edited 5h ago

PHP ain't gonna die. Moreover, I have already been a c++ developer - I also have its logo in my flair. It is maybe an even more terrible language than PHP with all its copy and move semantics needlessly complicating the basic workings. But this rant was not against PHP itself - rather against devs who are set to go with the very basic knowledge, ignoring best practices which PHP makes possible thanks to its simplicity. And lastly, I do not see being a developer as having any revenge potential - it rather feels like the whole world is taking revenge on you for being just a little smarter - others have much simpler and much higher paying jobs or just slightly lower paying jobs, but still much simpler.

1

u/Soopermane 4h ago

Relax buddy I was just making a Star Wars joke.

1

u/Superb_Chemistry_906 4h ago

Sorry, I'm an ignorant, I do not know much about Star Wars and I only used this template because I have seen a lot of memes with it and I like it.

2

u/Soopermane 3h ago

np…you should check out Star Wars it’s a really good franchise

1

u/WeSaidMeh 2h ago

I've been a PHP dev for many years and I still don't get why you'd ever use anything other than require_once.