r/PHP • • Dec 29 '24

What is PHP lacking in comparison to Nodejs / Golang / Java?

[deleted] — view deleted post

87 Upvotes

213 comments sorted by

View all comments

Show parent comment

0

u/viktorprogger Dec 29 '24

With static analysis tools like Psalm generics are kind of present in PHP.

4

u/okawei Dec 29 '24

What? How?

Static analysis and generics are two entirely separate things

12

u/viktorprogger Dec 29 '24

You can define generic types in PhpDoc annotations, and since you have static analysis in your CI process and corresponding syntax support in your IDE, you have generics in your project.

E.g., see Psalm docs: https://psalm.dev/docs/annotating_code/templated_annotations/

-1

u/manicleek Dec 29 '24

The fact this comment is getting upvotes is another con of PHP

“We don’t need actual proper functionality, because we can inconsistent bloat to our applications and pretend we do!”

2

u/spin81 Dec 29 '24

There's no bloat anywhere. It's just static analysis.

“We don’t need actual proper functionality, because we can inconsistent bloat to our applications and pretend we do!”

...said in a discussion where it's being discussed that PHP folks do in fact want generics in the language. FYI I'm pretty sure the internals people also want this but it's prohibitively complex to implement or it would have been present already years ago.

-1

u/manicleek Dec 29 '24

It’s not bloat?

So there is absolutely no extra packages to install to perform static analysis?

Extra packages that may or may not make things less productive because of their inconsistency?

Behave.

And no, it’s probably never going to be introduced in PHP, hence it being a con in terms of the usefulness of PHP.

3

u/spin81 Dec 29 '24

Behave.

I beg your pardon? I don't think I'm the one not behaving here.

Anyway, no, there "is" extra packages to install. But it depends what you mean by "packages": they aren't part of your application - you don't deploy them.

If you do it right, anyway.

Is it ideal? No. Is it bloat? Also no.

1

u/manicleek Dec 29 '24

It’s bloat relative to having the actual functionality, and in terms of your development process.

Install these extra packages, and add all this configuration, and this extra stage to your CI just so you can pretend you have the functionality. Whoop de doo.

Oh, and by the way, it still won’t work properly, because it can’t actually follow your logic, so you’ll have to add a load of fluff just so your pretend functionality pretends to function.

What a bonus!!!

0

u/skcortex Dec 29 '24

So something like a poor man’s generics.. and if you delete those “comments” this functionality is gone from your code. I get your point and code with annotations is much better to work with but there is a big BUT..

8

u/viktorprogger Dec 29 '24

if you delete those “comments” this functionality is gone from your code

This is the truth about any code: if you delete it, it is gone... But if it is tested, you'll be notified.

BTW, as for now native generics are impossible in PHP. That's why there are three types of PHP developers:

  • Those who don't know anything about generics
  • Those who dislike the current implementation of generics through static analysis tools
  • Those who utilize generics within the constraints of the existing PHP ecosystem.

4

u/tasqyn Dec 29 '24

This is the truth about any code: if you delete it, it is gone.

code should not in the "comments"!

1

u/viktorprogger Dec 29 '24

I think of it as metacode.

2

u/skcortex Dec 29 '24

Yes and a non-standardized one.

2

u/viktorprogger Dec 29 '24

Agreed, a standard like PSR/PER would be much better here.

1

u/skcortex Dec 29 '24

My main issues is that some of us are acting like “you can almost achieve generics with annotations as phpdoc”. Comments are not code. I know generics are currently almost impossible to achieve in php, and as I wrote that’s not the issue here. Static analysis is just a bandage although a helpful one.