Live data from Hacker News

PHP Annotations Are a Horrible Idea

theunraveler.com

51–60 of 127 posts

Re: PHP Annotations Are a Horrible Idea

#51
post #13

What's in the annotation is configuration, not application logic. As such there's no real difference between putting configuration into YML, XML and annotation comments. In response to your 4 specific criticisms: 1. (DX regressions) - in theory yes, in practice the frameworks are good at this. The annotations compile down to PHP which you can look at directly, and you get exceptions if there is something wrong with t…

I would argue that it's better for configuration and application logic should be separate though. You can run the same appliation with a different XML configuration without modification of the source. You couldn't do the same with in-comment configuration.

Wherever this is likely to happen, I wouldn't use annotations. For example, I use YML for environment specific variables.

But I don't need routes or fieldnames to be different only in one environment, so annotations work great there.

Re: PHP Annotations Are a Horrible Idea

#52
post #13

What's in the annotation is configuration, not application logic. As such there's no real difference between putting configuration into YML, XML and annotation comments. In response to your 4 specific criticisms: 1. (DX regressions) - in theory yes, in practice the frameworks are good at this. The annotations compile down to PHP which you can look at directly, and you get exceptions if there is something wrong with t…

It violates the "I don't need to look inside comments for sources of bugs" rule I'm quite fond of. I've defended PHP for some time now, but this is getting ridiculous. Isn't PHP embedded inside markup? Wouldn't it be simpler to do something like: ?> and not violate any expectations?

no that's bad really.

The best way to write PHP for the web is like any language: php echos or prints shit, that's it.

The way you're showing is that of the total noob trying to implement some php inside their evil dreamweaver website.

Besides, if you're handling markup (in the web context) on the server side, you've already failed, as most markup should only be generated client-side, diminishing server-load and bandwidth consumed while greatly improving cacheability.

Re: PHP Annotations Are a Horrible Idea

#53
post #5

This is pure horse pucky. First of all PHP isn't about elegance and I find it a teeth grinding experience when people complain about it not being so. PHP is about getting stuff done. He doesn't offer one good valid technical reason why not to use comments for meta-programming PHP other than "it just feels wrong" and an "icky feeling" which is entirely subjective. "Reliance on Yet Another Library"? C'mon. The fact tha…

[deleted]

Re: PHP Annotations Are a Horrible Idea

#54
"Without the special @Template comment, Symfony does not know where to find the template file."

First off, this is completely false. With symfony2 the action needs to return a Response object. This annotation isn't required and the team I work with, we rarely use this.

It's very useful for when you are just adding a page that contains no real business logic.

"Doctrine 2 does the same thing when declaring object properties based on database table columns1:"

Oh look, there's a footnote.

"Fortunately, Doctrine also allows you to declare property metadata using PHP, YAML, or XML"

What?

"Because code comments should never be necessary for a script to function properly"

So your points are that we need @Template annotation to be able to render a template, which is FALSE, and you state the same with with Doctrine2 which you point out there are other ways to do it.

All your points for "DX Regressions" are completely wrong.

Unless I am using a special plugin with my IDE it's not going to link "AcmeBlogBundle:Post" to src/Acme/BlogBundle/Entity/Post.php. Most of what you point out is complete bullshit. What do I gain to hope by using var_dump() on an annotation? I know that in a Doctrine Entity that the column type is a string.

Articles and posts like this drive me banana's with the complete lack of understanding what you're writing about.

Re: PHP Annotations Are a Horrible Idea

#55
post #49

Seriously, what sort of argument is this... (Allow me to paraphrase) "PHP doesn't have annotations, so instead it has hacked up comments that stand in for annotations. I find these ugly because it's abusing comments/etc therefore the idea of having a non-ugly real implementation that removes most of my objections is a bad idea" --EDIT I may have slightly not realised it was just comment annotations that were the prob…

I added an update to the article. I wasn't aware of the RFC to make annotations a language feature when I wrote the article. The article is specifically referring to annotations implemented as code comments.

Sorry for the confusion, and thanks for your comment.

Re: PHP Annotations Are a Horrible Idea

#56

That article misses the point: PHP OO is a HORRIBLE IDEA. if you're doing OO PHP, shoot your other foot right now and go learn PHP before using it java-style. Why is it that every time somebody on HN explains that a technology is not suitable for a use case, it gets downvoted by fans of said technology ?

Why is PHP OO a horrible idea?

Re: PHP Annotations Are a Horrible Idea

#57

Comments should be comments only, but your code in "alternative" is very dirty. Static(!) public(!) property is violation of encapsulation.

I don't understand how. It's a static property because it applies to all object of the class, not an individual object (i.e. an individual object shouldn't be able to change it). And how is making the property public a bad idea? The configuration system that parses it will need to read the property, no? And a method like getUsername() should be reserved for actually getting the value of that field, not its config.

"It's a static property because it applies to all object of the class, not an individual object"

Why? if you will have 3 databases, each will have same password?

"And how is making the property public a bad idea?"

Because it's breaks encapsulation.

Also, there is two kind of "class" usages in PHP: as Object and as Structure. If your class is just Structure (contain no methods at all), then, of course, public properties is what we need. But when your class is an Object, which should have instances, API, then keep all properties encapsulated.

Re: PHP Annotations Are a Horrible Idea

#58

That article misses the point: PHP OO is a HORRIBLE IDEA. if you're doing OO PHP, shoot your other foot right now and go learn PHP before using it java-style. Why is it that every time somebody on HN explains that a technology is not suitable for a use case, it gets downvoted by fans of said technology ?

Why is PHP OO a horrible idea?

PHP OO is broken in many ways (of which you can find a list in the blog post "php a fractal of bad design"

PHP is naturally (due to it's C libs) non-OO and will thus only implement OO "that" far.

Lastly, OO is not a silver bullet and is best used only in front-end, and languages that were designed with it in mind.

Re: PHP Annotations Are a Horrible Idea

#60

That article misses the point: PHP OO is a HORRIBLE IDEA. if you're doing OO PHP, shoot your other foot right now and go learn PHP before using it java-style. Why is it that every time somebody on HN explains that a technology is not suitable for a use case, it gets downvoted by fans of said technology ?

Why is PHP OO a horrible idea?

[deleted]
Post reply on HN