Live data from Hacker News

PHP Annotations Are a Horrible Idea

theunraveler.com

61–70 of 127 posts

Re: PHP Annotations Are a Horrible Idea

#61

Earlier quoted context omitted.

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.

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

Agreed. Although the problem is more that PHP in general (not just its OO features) is really broken.

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

I have no idea what you mean here. AFAIK, there is nothing about C that prevents PHP from properly implementing OO principles. In fact, Ruby is written mostly in C and is completely OO.

> is best used only in front-end

What?

> and languages that were designed with it in mind

Sure, I guess...

Re: PHP Annotations Are a Horrible Idea

#62

Earlier quoted context omitted.

3) In this specific case we're reliant on Doctrine to read Doctrine annotations because we're already reliant on Doctrine to be Doctrine. Possibly relevant if the annotation reader was purely collecting metadata it did not use itself.

Not necessarily. Several Symfony components rely on doctrine/common simply for parsing annotations, even if you are not using Doctrine for anything else.

Witch clearly proves that is a bad idea because it injects a dependency on some other lib

Re: PHP Annotations Are a Horrible Idea

#63
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?

> It violates the "I don't need to look inside comments for sources of bugs" rule I'm quite fond of.

I second that. A practical explanation of why this is dumb idea.

I get it, PHP is about getting stuff done. But why insisting on bad ideas, when PHP already has lots of them.

Re: PHP Annotations Are a Horrible Idea

#64
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…

It's really bad practice. We all want to get stuff done, but don't complain when you end up in spagethi code hell. Some people are going to see that and think that's an ingenious use of comments, and then start to do the same in everything they write soon after. If you ever seen Preprocessor abuse in C++ you know what I mean.

Re: PHP Annotations Are a Horrible Idea

#65
post #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 prope…

> 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.

Correct. But if you want use the form where you just return an array of variables to use inside your template, and have Symfony smartly located the template for you, you have to use an annotation. See http://stackoverflow.com/questions/12922827/symfony-2-php-te... for an example.

> and you state the same with with Doctrine2 which you point out there are other ways to do it.

Yes, there are other BETTER ways to do it. Making comment-based annotations available as one of the ways pretty much guarantees that people will use it, and that seems like a bad idea to me. Just remove them so no one is able to choose the bad practice.

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

Uhh, OK? How about comment folding in text editors? Would you, as a developer, be happy if you encountered some code that made heavy use of annotations for critical application logic? I wouldn't--this is what I mean by DX.

> What do I gain to hope by using var_dump() on an annotation?

The same thing you gain by var_dump()ing any variable--an understand of what's happening under the hood.

Re: PHP Annotations Are a Horrible Idea

#66
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…

> ...because I have other shit I need to do.

Ironically, that's often also the attitude of programmers who don't use comments in their code (in any language).

Re: PHP Annotations Are a Horrible Idea

#67
post #11

Closures inside property initializations inside the class body don't work. Not even in an array. So this code throws up a "Parse error: syntax error, unexpected 'function' (T_FUNCTION)" class User { public static $mapping = array( 'username' => array( 'type' => 'string', 'length' => 32, 'unique' => true, 'nullable' => function() { // Some logic to determine value. } ) ); }

Don't need to inline the function, it could instead just be a reference to static member of the same class: ... 'nullable' => self::getNullable, ...

Re: PHP Annotations Are a Horrible Idea

#68

Earlier quoted context omitted.

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.

Well, OOP in PHP seems to work rather well for thousands of large projects out in the wild - making your argument invalid.

Re: PHP Annotations Are a Horrible Idea

#69
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…

If annotations are in comments, how are you going to leave actual comments containing annotations that you don't want to actually affect the code?

Re: PHP Annotations Are a Horrible Idea

#70
post #69
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…

If annotations are in comments, how are you going to leave actual comments containing annotations that you don't want to actually affect the code?

by escaping them?

Some annotations are meant to affect the code, some aren't. Those who do and need to be given as pure comments need to be escaped.

Post reply on HN