On Tue, 16 Nov 2010 07:06:27 -0000, Zeev Suraski <z...@zend.com> wrote:

From: Pierre Joye [mailto:pierre....@gmail.com]
Sent: Tuesday, November 16, 2010 1:45 AM
To: Zeev Suraski
Cc: guilhermebla...@gmail.com; PHP internals
Subject: Re: [PHP-DEV] PHP 5.4 - Meta attribute (aka. Annotations) support discussion

On Tue, Nov 16, 2010 at 12:39 AM, Zeev Suraski <z...@zend.com> wrote:
> Suggesting phpdoc is used for the purposes mentioned does not mean we
don't understand what we're talking about.

I feel like you never used annotations in other languages, did you?

You got me... But as an intelligent human being I'd like to think I can evaluate the merits of a feature without having to actually use it.

I'm not saying that annotations don't give you any value. Sure they do. I'm saying that they come at a great price of adding an obscure branch of syntax into a language that's already grown significantly in complexity, and the bang for the buck isn't worth it. Those advanced developers needing that feature can make do with phpdoc.


I would have no trouble accepting a rejection of annotations on the actual merits, but the interminable sequence of comparisons to phpdoc make it clear to me that people just don't realize the potential of annotations.

First, can docblock comments substitute the current proposal of annotations?

YES, they can. Leave everything the same in the current annotations implementation and just tweak the grammar so that docblock comments are parsed for annotations.

Of course, no one is actually proposing this, because at this point people usually realize it would be crazy to do such a thing. So the "alternative" they actually propose is a watered-down-to-nothing version of annotations, put as "add an API to parse docblock comments". This homeopathic version of annotations solves only a small subset of what you can actually do with annotations, as I've explained in the past (see http://news.php.net/php.internals/49674 ).

Yes, it is new syntax and by itself that is undesirable. However, I see annotations has actually saving us from having to had new syntax for new functionality in the future. The ability of using annotations to sort-of extend a language is one thing that has actually mitigated the lack of new language features in Java in the last few years.

Want to add support for AOP? We can use annotations to define joint points, pointcuts and advice.

Define properties as non-null, having a certain type or being read-only? We can use annotations instead of adding new keywords.

More general forms of design by contract?

Etc etc.

It must be said at this point that annotations are not perfect. Too many annotations can make the code unreadable and they can make the program flow non-obvious. Despite their versatility, they still have a relatively rigid structure. A more interesting option would be to allow either extensions or scripts to extend the grammar to better reflect the domain of the application (this could then also be used to implemented annotations). However, I think that, at this point, adding annotations directly to the language would be a fair trade-off.

--
Gustavo Lopes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to