r/ProgrammerHumor 2d ago

Meme ancientTools

Post image
5.8k Upvotes

387 comments sorted by

View all comments

Show parent comments

24

u/Hottage 2d ago

PHP before 7 was a disgusting mess..

Around 7 they started trying to mature the language with features like compiler enforced type safety and bringing other tools previously relegated to PHPdoc into the language.

PHP 8 is a decent system and features like Generators, Attributes, Fibers and first class callables have bought it near parity with other server ecosystems like .NET.

The biggest thing PHP still lacks is first-class generics for proper, type safe repository patterns.

I've been a PHP developer for over 15 years. I fucking hated 4 and 5, tolerated 7 and actually quite enjoy 8.

The biggest issue nowadays is that, for backward compatibility, a lot of the good features like type hinting are just recommended instead of enforced, so you can get situations like in Typescript where lazy developers just have everything return mixed or any.

2

u/IOFrame 2d ago

Nah, this is what makes PHP great.

You get to choose your battles - some sections of the code get to have verbose documentation (I consider types a sort of documentation). On the other hand, meaningless utility function #2421354 can remain typeless.

PHP doesn't have to be a bloated mess like Java.

1

u/Hottage 2d ago

I will not allow my juniors to read this. All function arguments and return values must be type hinted.

1

u/IOFrame 2d ago

I do this with 80% of the functions, and skipping that waste of focus on those last 20% - the meaningless crap that is allowed to remain meaningless crap - is what keeps my productivity from plummeting into the abyss.

You only have so much focus - wasting it on things that don't matter is far worse than some might think.

1

u/Hottage 2d ago

And properly documented functions reduce the chance of difficult to trace bugs which plummet productivity when you spent two days tracking them down because someone accidentally returned a JSON string instead of the deserialzed result.

1

u/IOFrame 2d ago

And that makes sense... in a large, dysfunctional company.

A small team where everyone talks to each other, and everyone actually tests their shit, and an accidental JSON string gets caught the moment whoever implemented it runs their test (manual or autoamted).

1

u/ArjixGamer 2d ago

Be realistic, have you seen many teams where people talked in detail about the code do they didn't need strict type checking?

1

u/Hottage 2d ago edited 2d ago

Or any medium size business which has a code base more than a few hundred files.

It's a completely unnecessary burden to have your team remember the inner workings of a project when there are perfectly serviceable tools to automate that process.

Coming back to a sub component of a large project after six months to add a feature is far less daunting (and easier to delegate) if the code is unambiguous about what it expects and what it produces.

The only reason to forego such simple code documentation standards is if you're gunning for job security by way of noone else being able to understand what anything does.

1

u/IOFrame 2d ago

I totally agree.

As I said, not having overly verbose documentation doesn't mean having no documentation at all. If you have a module, its intent should be documented to begin with, as should any functions which aren't trivial / self-documenting.

When you're missing is that you don't need to document every sortArray function in order to have meaningful documentation.

0

u/ClamPaste 2d ago

PHP would be great if it wasn't for all the legacy code and echo "<div></div>" in views.

1

u/ArjixGamer 2d ago

I hate PHP from the bottom of my soul, but what you said is just user-choice.

I always do ob_start and ob_flush_clean or whatever the function names were.

That allows me to use normal html w/o it being in strings.

Edit: e.g.

```php <?php

function renderEmail(): string { ob_start(); ?> <html> <body> <h1>Hello!</h1> <p>This is your email.</p> </body> </html> <?php return ob_get_clean(); } ```

1

u/ClamPaste 2d ago

Like I said, legacy code. We have a huge codebase and I'm converting it when I get time. User-choice encapsulates choices made 10 years ago.

2

u/ArjixGamer 2d ago

True dat

1

u/ClamPaste 2d ago

I guess they didn't really have coding standards. I took over and I'm enforcing some things now. I should probably write them down at some point...

0

u/Hottage 2d ago

If you're gonna raw dog the HTML, just extract it into purpose built template files and return the result of file_get_contents().

1

u/ArjixGamer 2d ago

That only works if the html is static and I don't need to render content using for loops and stuff.

The alternative is using a templating language, but like, PHP is a templating language in the first place.

I always used to say "PHP is a glorified string builder"

0

u/Hottage 2d ago

If you need to render dynamic content, use a templating engine, or at least phtml files.

😭

2

u/ArjixGamer 2d ago

Yeah, let me add an entire fucking library for my WordPress plugin that only needs to render content in 3 places on the admin dashboard.

Such a dumb take to assume there is no nuance and that there is an absolute objectively better way of doing smth.

1

u/Hottage 2d ago

Doesn't WordPress already come with a massive templating engine built in, like thats it's primary purpose?

At the end of the day, if you're building a little tool for yourself that noone else has to maintain, go ham it's your code.

If you submitted that as a pull request to my clients webshop code base, it would be receiving some... feedback.

1

u/ArjixGamer 2d ago

No? WordPress' primary purpose is extensibility via hooks.

Also, WordPress was just one example.

1

u/ClamPaste 2d ago

PHP is the templating engine. Why load a separate library for that?