Live data from Hacker News

PHP Annotations Are a Horrible Idea

theunraveler.com

1–10 of 127 posts

Re: PHP Annotations Are a Horrible Idea

#2
> the PHP community is now officially so desperate for better metaprogramming capabilities that it is attempting to do so using code comments

This says it all ... and to be honest, from an ease point of view I like using annotations but as with most parts of PHP it's the implementation that sucks (or the lack of implementation)

Over 2 years ago a RFC has been filed for native php annotations and I must say that I like the idea of annotations being part of the actual language and not relying on Inflection on comments (wtf?) to attach metadata to classes, propeties or methods. Just too bad nobody can get their act together and get it implemented in the core. https://wiki.php.net/rfc/annotations

Re: PHP Annotations Are a Horrible Idea

#3
I completely agree with you, but I would use something like this - http://pastebin.com/embed_iframe.php?i=U4Fmm0t6

I don't think that just an array quite make it as a real alternative but a definition builder called from a method seems more appropriate. Also I would seperate model definition from model repository.

Re: PHP Annotations Are a Horrible Idea

#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 that you can even parse out comments with the reflection API lends, to me, that meta-programming is a-ok.

Also, his alternatives are kind of weak. Here's an annotation:

    /**
     * @Column(type="string", length=32, unique=true, nullable=false)
     */    
    protected $username;
And here's his proposed alternative:

    class User
    {
        public static $mapping = array(
            'username' => array(
                'type' => 'string',
                'length' => 32,
                'unique' => true,
                'nullable' => function() {
                    // Some logic to determine value.  
                }
            )
        );  
    }
I'll take the first one because I have other shit I need to do.

Re: PHP Annotations Are a Horrible Idea

#6
Agreed. A comment is an explanation about some part of the program. Not the program itself. Its meant to be ignored by the computer. Putting logic in the comments is just downright stupid. Its one of those overly "clever" things "smart" people do to make their code be cutting edge. Nope. As good as Symfony is, my main issue comes down to design decisions as this one. Its just dumb. Having logic in comments its like putting beer in baby formula, just in case I run out of beer. Shit doesnt make sense.

Re: PHP Annotations Are a Horrible Idea

#7
Annotations are not required to use either of those libraries. Doctrine allows mapping information to be defined in XML or YAML files. For Symfony, the @Template annotation is not part of the core at all: it is part of the SensioFrameworkExtraBundle, which can be turned off easily. The normal way to render a template is:

    return $this->render("MyBundle:Controller:template.html.php", array(...));
That said, it would be easy enough to add the static variable-based mapping information to Doctrine as a metadata driver, and create a version of SensioFrameworkExtraBundle that does the same for its annotations.

Re: PHP Annotations Are a Horrible Idea

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

the official RFC for annotations is actually a little cleaner in syntax, easier to read and implemented in the language itself which is a way beter system than comment annotations. On a level I do agree that docblock comments are no place for annotations, it's the best we can have for now though, just until annotations become a native PHP feature.

Judging from the RCF and discussions on internals we still have a long way to go before we get annotations in PHP core.

http://marc.info/?r=1&w=2&q=b&l=php-internals&#3... https://wiki.php.net/rfc/annotations

Post reply on HN