At 17:51 13/09/2010, Gustavo Lopes wrote:
At 16:39 13/09/2010, Pierre Joye wrote:
You are not serioulsy suggesting to use phpdoc for runtime annotation
support? Are you?I actually am (either that or get what you want done in some other
way). It's a rare enough use case that I think it's a very reasonable
compromise. The disadvantages of adding a whole new branch of syntax,
for this rare use case, far outweigh its advantages - IMHO.Rare use case? Have you seen any recent Java framework? Or Java EE 6? Or
design by contract in C#? A declarative programming style can be very
handy.Framework code (as in code that actually goes into a framework, not code
that uses a framework) represents a tiny percentage of the PHP codebase
at large. Most of it is application code.You misunderstood me. When I say the frameworks use annotation I don't
mean they use annotations in their own implementation (that's not
particularly relevant for the reason you present).What I mean is that the frameworks recognize annotations the application
code has so that the framework user can do stuff like injecting objects,
run methods in transactions or check post-conditions in a declarative
fashion, by adding annotations.By the way, you ignored the rest of the e-mail.
How do you evaluate the complexity/return of features such as annotations
with that of e.g. LSB? Why are they not adequate for PHP, but may be for
other languages?
I do not understand this.
I see no one other than Symfony / Doctrine people pushing for this annotations patch.
How can this special-purpose feature (which would add entirely new language semantics in the form of an embedded micro-language) even be open for discussion, when other, more generally-useful RFCs like http://wiki.php.net/rfc/shortsyntaxforarrays were shot down on the basis that they were hard to read and confusing for new developers?
Sorry, but I don't see how this is even remotely close to being appropriate for PHP. Maybe I'm missing something. :-)
Thanks,
- Nate
Sorry, but I don't see how this is even remotely close to being
appropriate for PHP. Maybe I'm missing something. :-)
I agree, the use cases are just not there
Though maybe some form of "annotations" could be useful in php as a
"pluggable type":
http://bartoszmilewski.wordpress.com/2009/01/18/java-pluggable-types/
But this isn't an annotation as just plain metadata, the parser could do
something with the annotation.
i.e.
class Phone {
@ReadOnly
public $id;
@PhoneNumber
public $number;
}
class PhoneNumber implements TypeAnnotation {
static function getTypeValue($val)
{
return preg_replace('~[^0-9]~', '', $val);
}
}
Instead of ~
class Phone {
protected $_number;
function __get($prop) {
if($prop === 'number')
return $this->_number;
}
function __set($prop, $val) {
if($prop === 'number')
$this->_number = preg_replace('~[^0-9]~', '', $val);
}
}
hi,
Sorry, but I don't see how this is even remotely close to being
appropriate for PHP. Maybe I'm missing something. :-)I agree, the use cases are just not there
There are plenty of use cases for that. The main problem I see is that
nobody seems to have actually used them in other languages, and then
totally miss why it is a good thing (while not being deadly critical).
Only the syntax is discussed is somehow disturbing too.
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi!
There are plenty of use cases for that. The main problem I see is that
nobody seems to have actually used them in other languages, and then
Of course not. It couldn't be that your opponents know what they are
talking about, otherwise they'd agree with you :) Come on. Usefullness
of annotations in Java (where they are very different, as the language
is) or C# (which again very different from PHP) or Python (where they
again work totally different from what is proposed) has nothing to do
with acceptability of current implementations.
Is ability to add metadata useful? Of course. But that doesn't mean that
any proposal implementing metadata automatically gets a pass. We'd be
better not having it for now than having it wrong - not having can be
fixed once a good proposal arrives, having it wrong will haunt as forever.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
hi Stas,
Of course not. It couldn't be that your opponents know what they are talking
about, otherwise they'd agree with you :) Come on. Usefullness of
annotations in Java (where they are very different, as the language is) or
C# (which again very different from PHP) or Python (where they again work
totally different from what is proposed) has nothing to do with
acceptability of current implementations.
Is ability to add metadata useful? Of course. But that doesn't mean that any
proposal implementing metadata automatically gets a pass.
It is an over interpretation of my reply, which was to a specific mail.
The additional comment about nobody having used annotations in other
languages (meaning having annotations experiences, not related to clue
or lack of clue) was about the proposal like using phpdoc, arguing
about the syntax endlessly or even worst, one line reply.
That being said, I'm not proposing it and I'm relatively neutral in
here. However I am sure that PHP will gain a lot of new nice tools and
php based services if we support annotations. If this implementation
is not good enough then let us try to improve it, in the most
constructive way (that means to leave the other totally unrelated
topics behind us :).
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi,
Last year, I attended to a conference where you (Stas) told that the best
way to do a feature request/proposal was by writing a RFC and a patch even
if the patch is not perfect. The current implementation may not be perfect
but it was never said it was a final one. This is a proposal of a first
implementation which is a start to take people's attention and feedback.
So the first question that we have to agree is regardless the syntax, and
the entire implementation do we want to add the ability to add code metadata
(like annotations) or not into PHP. My opinion is yes. If everybody finds
this idea stupid then the discussion stops.
If we agree that Annotations are useful, then I want people who disagree on
the current implementation to say why they disagree regardless of the
current syntax (%Annotation !Annotation [Annotation] or whatever it's IMHO a
detail) and how this implementation could be improved to make it more
relevant for the PHP needs.
I can continue working on this patch if people are interested in the main
idea to improve it (I already plan to improve the patch to include Dmitry's
feedback). But I expect to get constructive feedback on how it could be
improved instead of just a discussion on why this feature is accepted and
others are not (we are not childs), or I don't like the current
implementation without any valid reason but the syntax etc.
Regards,
Pierrick
2010/9/14 Stas Malyshev smalyshev@sugarcrm.com
Hi!
There are plenty of use cases for that. The main problem I see is that
nobody seems to have actually used them in other languages, and then
Of course not. It couldn't be that your opponents know what they are
talking about, otherwise they'd agree with you :) Come on. Usefullness of
annotations in Java (where they are very different, as the language is) or
C# (which again very different from PHP) or Python (where they again work
totally different from what is proposed) has nothing to do with
acceptability of current implementations.
Is ability to add metadata useful? Of course. But that doesn't mean that
any proposal implementing metadata automatically gets a pass. We'd be better
not having it for now than having it wrong - not having can be fixed once a
good proposal arrives, having it wrong will haunt as forever.--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi!
Last year, I attended to a conference where you (Stas) told that the
best way to do a feature request/proposal was by writing a RFC and a
patch even if the patch is not perfect. The current implementation may
not be perfect but it was never said it was a final one. This is a
proposal of a first implementation which is a start to take people's
attention and feedback.
Of course, writing an RFC and a patch is a good way to start the process
and I think it is great you did it. However it doesn't mean any
RFC/patch will be accepted. That's why we discuss it - and there's no
guarantee that the result would be acceptance. Rodin said he makes
sculpture by chopping off extra pieces from the block of marble. We need
to chop off stuff too sometimes if we want the language to stay easy to
learn, read and use.
So the first question that we have to agree is regardless the syntax,
and the entire implementation do we want to add the ability to add code
metadata (like annotations) or not into PHP. My opinion is yes. If
everybody finds this idea stupid then the discussion stops.
I think we already have metadata in PHP, albeit done through phpdocs.
So the question is kind of moot :) We should see if it's enough for us
or we want to add/change/extend it and if so, how.
I however have some doubts about usefullness of "code" metadata - i.e.
code being run as part of metadata processing in the language. Having
purely declarative metadata you can always have user code run on it and
do any logic you want, but having "active" metadata seems to me to have
high potential for complications.
Speaking of syntax, I think it is important too, because syntax defines
readability and usability of the language. And unobvious syntax rules
for different parts of the language hurts that.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
hi,
I think we already have metadata in PHP, albeit done through phpdocs. So
the question is kind of moot :) We should see if it's enough for us or we
want to add/change/extend it and if so, how.
I think we have the main issue here, it has absolutely nothing to do
with users documentation, as phpdoc does. Yes, they both somehow
'document' something but still totally unrelated for the goals and
usages. To understand that would help to move forward.
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi!
I think we have the main issue here, it has absolutely nothing to do
with users documentation, as phpdoc does. Yes, they both somehow
'document' something but still totally unrelated for the goals and
usages. To understand that would help to move forward.
Phpdocs aren't "user documentation" only, not for a long time (I mean
the concept, not the particular application called phpDocumentor, of
course). They are being used as metadata in many places. You could argue
that's misguided but you can't ignore the fact that's what people do.
The "goals and usages" of those tags are exactly metadata - and
regardless of the annotations, I'd be happy if Reflection recognized it
finally (by integrating some kind of phpdoc tag parser).
In general, I don't see why metadata written as /** @data */ is that
much worse than metadata written as [data()]. Can you explain?
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
At 08:09 15/09/2010, Stas Malyshev wrote:
Phpdocs aren't "user documentation" only, not for a long time (I
mean the concept, not the particular application called
phpDocumentor, of course). They are being used as metadata in many
places. You could argue that's misguided but you can't ignore the
fact that's what people do. The "goals and usages" of those tags are
exactly metadata - and regardless of the annotations, I'd be happy
if Reflection recognized it finally (by integrating some kind of
phpdoc tag parser).
I second that word for word. FWIW, I don't see it as misguided at all.
Zeev
Hi Zeev and Stas,
I wouldnt mind extending doc block metadata support instead of adding a
new syntax.
I agree with you that PHP Docs allow metadata and they can be used for
that (and some people do, including me), however what the annotation patch
- rfc tries to achieve is something going beyong $refl->getDocComment()
returning a string only. The string only return leads to hunderets of
different approaches for annotating metadata in all the different
frameworks and libraries. A single unified syntax would be benefitial.
That is why I don't know if it will even be possible to extend the doc
blocks in a generic way that does not break half the applications out
there.
When extending doc-blocks there is probably new method required
$refl->getParsedDocComment() which then returns an array of metadata for
that particular refl instance. Now here the syntax would be a problem, can
we find something that does not break for all the different usages of
docblocks out there? Since the method/parsing would be nested, on request
only it wouldnt break any application that does not use parsed doc
comments. However for applications that do, a syntax needs to be found
that:
- does not break for various type hinting doc syntaxes
- does not break for various commenting styles
Can someone come up with additional pitfalls?
greetings,
Benjamin
At 08:09 15/09/2010, Stas Malyshev wrote:
Phpdocs aren't "user documentation" only, not for a long time (I
mean the concept, not the particular application called phpDocumentor, of
course). They are being used as metadata in many places. You could argue
that's misguided but you can't ignore the fact that's what people do. The
"goals and usages" of those tags are exactly metadata - and regardless of
the annotations, I'd be happy if Reflection recognized it finally (by
integrating some kind of phpdoc tag parser).
I second that word for word. FWIW, I don't see it as misguided at all.
Zeev
listen to this man;) I think he's on to something. I don't see any
problem with that aproach and both parties would be satisfied, no?
Am 15.09.2010 10:45, schrieb Benjamin Eberlei:
Hi Zeev and Stas,
I wouldnt mind extending doc block metadata support instead of adding a
new syntax.
I agree with you that PHP Docs allow metadata and they can be used for
that (and some people do, including me), however what the annotation patch
- rfc tries to achieve is something going beyong $refl->getDocComment()
returning a string only. The string only return leads to hunderets of
different approaches for annotating metadata in all the different
frameworks and libraries. A single unified syntax would be benefitial.
That is why I don't know if it will even be possible to extend the doc
blocks in a generic way that does not break half the applications out
there.
When extending doc-blocks there is probably new method required
$refl->getParsedDocComment() which then returns an array of metadata for
that particular refl instance. Now here the syntax would be a problem, can
we find something that does not break for all the different usages of
docblocks out there? Since the method/parsing would be nested, on request
only it wouldnt break any application that does not use parsed doc
comments. However for applications that do, a syntax needs to be found
that:
does not break for various type hinting doc syntaxes
does not break for various commenting styles
Can someone come up with additional pitfalls?
greetings,
Benjamin
At 08:09 15/09/2010, Stas Malyshev wrote: Phpdocs aren't "user documentation" only, not for a long time (I
mean the concept, not the particular application called phpDocumentor, of
course). They are being used as metadata in many places. You could argue
that's misguided but you can't ignore the fact that's what people do. The
"goals and usages" of those tags are exactly metadata - and regardless of
the annotations, I'd be happy if Reflection recognized it finally (by
integrating some kind of phpdoc tag parser).
I second that word for word. FWIW, I don't see it as misguided at all.
Zeev
It's curious that you keep complaining about new syntax and propose a
new one at the same time.
[Foo] introduces new concept, use /** @Foo / or /* [Foo] */ instead.
What's the point then?
I think meta programming is not and would never be part of comment.
As previously said, docblock means documentation, without any meaning
to parser, entirely human readable and totally removable without
affecting overall execution.
Something that HAS a meaning to execution means something out of the
userland comments. Point made.
Cheers,
listen to this man;) I think he's on to something. I don't see any problem
with that aproach and both parties would be satisfied, no?Am 15.09.2010 10:45, schrieb Benjamin Eberlei:
Hi Zeev and Stas,
I wouldnt mind extending doc block metadata support instead of adding a
new syntax.
I agree with you that PHP Docs allow metadata and they can be used for
that (and some people do, including me), however what the annotation patch
- rfc tries to achieve is something going beyong $refl->getDocComment()
returning a string only. The string only return leads to hunderets of
different approaches for annotating metadata in all the different
frameworks and libraries. A single unified syntax would be benefitial.
That is why I don't know if it will even be possible to extend the doc
blocks in a generic way that does not break half the applications out
there.
When extending doc-blocks there is probably new method required
$refl->getParsedDocComment() which then returns an array of metadata for
that particular refl instance. Now here the syntax would be a problem, can
we find something that does not break for all the different usages of
docblocks out there? Since the method/parsing would be nested, on request
only it wouldnt break any application that does not use parsed doc
comments. However for applications that do, a syntax needs to be found
that:
does not break for various type hinting doc syntaxes
does not break for various commenting styles
Can someone come up with additional pitfalls?
greetings,
Benjamin
On Wed, 15 Sep 2010 08:55:55 +0200, Zeev Suraskizeev@zend.com wrote:
At 08:09 15/09/2010, Stas Malyshev wrote:
Phpdocs aren't "user documentation" only, not for a long time (I
mean the concept, not the particular application called phpDocumentor, of
course). They are being used as metadata in many places. You could argue
that's misguided but you can't ignore the fact that's what people do. The
"goals and usages" of those tags are exactly metadata - and regardless of
the annotations, I'd be happy if Reflection recognized it finally (by
integrating some kind of phpdoc tag parser).
I second that word for word. FWIW, I don't see it as misguided at all.
Zeev
--
--
Guilherme Blanco
Mobile: +55 (16) 9215-8480
MSN: guilhermeblanco@hotmail.com
São Paulo - SP/Brazil
I think meta programming is not and would never be part of comment.
As previously said, docblock means documentation, without any meaning
to parser, entirely human readable and totally removable without
affecting overall execution.
I have to agree here, there's lots of php tools that 'strip comments'.
If you strip comments, you'd be effectively removing 'annotations' which changes how that code would run in a given framework or tool. It kind of defeats the purpose.
But my opinion as an end user and framework developer:
the rfc really needs to elaborate on the use cases specific to php
java has some here:
http://jcp.org/en/jsr/detail?id=250
Does php need to be become this complicated?
I worry about how php can grow complicated to a point where you won't be able to use it without using tool or framework X.
I'll use .NET, thank you very much.
Hi all.
As a user land developer and active reader (and some times poster) for
a few years now this is the first time I trully don't understand what
the hell are you talking about and what are annotations at all and
what will be the usage of them in the PHP. And for what? Building 2-3
frameworks and that's all (as I understand from reading this
discussion)?
I'm sure pretty much user land developers read this thread and ask
themselves the same question.
P.S. Personally I would take the energy boiling in this thread and
throw it at solving the windows biuld and PECL problem. Right now you
can't install PHP 5.2 and apache on a Windows 7 - it just crashes
totally. Only 5.3 works, not to mention much of the PECL libs just
don't have dll's (lucky if you find one in the Google). The same goes
for the PECL dll's for 5.3 - all of them, excluding the standard once,
mostly are missing and can't be found at all.
On Wed, Sep 15, 2010 at 10:27 PM, Arvids Godjuks
arvids.godjuks@gmail.comwrote:
Hi all.
As a user land developer and active reader (and some times poster) for
a few years now this is the first time I trully don't understand what
the hell are you talking about and what are annotations at all and
what will be the usage of them in the PHP. And for what? Building 2-3
frameworks and that's all (as I understand from reading this
discussion)?
Did you read the quoted references in this thread?
It's a new feature proposal as for example closures or traits, if you don't
know what are they, you have to do some work to understand them, but thats
all.
You should understand the discussion, before choosing your side.
I'm sure pretty much user land developers read this thread and ask
themselves the same question.
dunno, I'm a user land developer, and I don't ask the same question, so it's
1:1 for now.
P.S. Personally I would take the energy boiling in this thread and
throw it at solving the windows biuld and PECL problem. Right now you
can't install PHP 5.2 and apache on a Windows 7 - it just crashes
totally. Only 5.3 works, not to mention much of the PECL libs just
don't have dll's (lucky if you find one in the Google). The same goes
for the PECL dll's for 5.3 - all of them, excluding the standard once,
mostly are missing and can't be found at all.
party agree here, feel free to open a new thread or issue, but one problem
doesn't mean, that we can't discuss other ideas, until that problem is
fixed.
Tyrael
On Wed, Sep 15, 2010 at 10:27 PM, Arvids Godjuks
arvids.godjuks@gmail.com wrote:
P.S. Personally I would take the energy boiling in this thread and
throw it at solving the windows biuld and PECL problem. Right now you
can't install PHP 5.2 and apache on a Windows 7 - it just crashes
totally.
Where are the bugs report?
Only 5.3 works, not to mention much of the PECL libs just
don't have dll's (lucky if you find one in the Google). The same goes
for the PECL dll's for 5.3 - all of them, excluding the standard once,
mostly are missing and can't be found at all.
What are you talking about? Not a real question, use bugs.php.net for
php extensions, if something is broken or missing.
Thanks to focus on the topic and not hi jack this thread with random rants.
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hello all,
Only today see that here is very intersting discussion.
I have a question: why was choosed exactly this format (seems like c#-like,
not java-like)?
Simply [] is used for arrays. Why not use @ at annotation name?
2010/9/16 Pierre Joye pierre.php@gmail.com
On Wed, Sep 15, 2010 at 10:27 PM, Arvids Godjuks
arvids.godjuks@gmail.com wrote:P.S. Personally I would take the energy boiling in this thread and
throw it at solving the windows biuld and PECL problem. Right now you
can't install PHP 5.2 and apache on a Windows 7 - it just crashes
totally.Where are the bugs report?
Only 5.3 works, not to mention much of the PECL libs just
don't have dll's (lucky if you find one in the Google). The same goes
for the PECL dll's for 5.3 - all of them, excluding the standard once,
mostly are missing and can't be found at all.What are you talking about? Not a real question, use bugs.php.net for
php extensions, if something is broken or missing.Thanks to focus on the topic and not hi jack this thread with random rants.
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi,
it's reserved for the error control
operator(http://www.php.net/manual/en/language.operators.errorcontrol.php).
Greetings,
Christian
On Thu, 16 Sep 2010 11:26:51 +0300, Aleksei Sapunov saprizo@gmail.com
wrote:
Hello all,
Only today see that here is very intersting discussion.
I have a question: why was choosed exactly this format (seems like c#-like,
not java-like)?
Simply [] is used for arrays. Why not use @ at annotation name?2010/9/16 Pierre Joye pierre.php@gmail.com
On Wed, Sep 15, 2010 at 10:27 PM, Arvids Godjuks
arvids.godjuks@gmail.com wrote:P.S. Personally I would take the energy boiling in this thread and
throw it at solving the windows biuld and PECL problem. Right now you
can't install PHP 5.2 and apache on a Windows 7 - it just crashes
totally.Where are the bugs report?
Only 5.3 works, not to mention much of the PECL libs just
don't have dll's (lucky if you find one in the Google). The same goes
for the PECL dll's for 5.3 - all of them, excluding the standard once,
mostly are missing and can't be found at all.What are you talking about? Not a real question, use bugs.php.net for
php extensions, if something is broken or missing.Thanks to focus on the topic and not hi jack this thread with random rants.
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi,
Yes, you right. But [] are used in arrays definition. If take in to account
that format with @ is more readable?
Is it a problem to implement it using @ symbol?
2010/9/16 Christian Kaps christian.kaps@mohiva.com
Hi,
it's reserved for the error control
operator(http://www.php.net/manual/en/language.operators.errorcontrol.php
).Greetings,
ChristianOn Thu, 16 Sep 2010 11:26:51 +0300, Aleksei Sapunov saprizo@gmail.com
wrote:Hello all,
Only today see that here is very intersting discussion.
I have a question: why was choosed exactly this format (seems like
c#-like,
not java-like)?
Simply [] is used for arrays. Why not use @ at annotation name?2010/9/16 Pierre Joye pierre.php@gmail.com
On Wed, Sep 15, 2010 at 10:27 PM, Arvids Godjuks
arvids.godjuks@gmail.com wrote:P.S. Personally I would take the energy boiling in this thread and
throw it at solving the windows biuld and PECL problem. Right now you
can't install PHP 5.2 and apache on a Windows 7 - it just crashes
totally.Where are the bugs report?
Only 5.3 works, not to mention much of the PECL libs just
don't have dll's (lucky if you find one in the Google). The same goes
for the PECL dll's for 5.3 - all of them, excluding the standard once,
mostly are missing and can't be found at all.What are you talking about? Not a real question, use bugs.php.net for
php extensions, if something is broken or missing.Thanks to focus on the topic and not hi jack this thread with random
rants.Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi,
Yes, you right. But [] are used in arrays definition. If take in to account
that format with @ is more readable?Is it a problem to implement it using @ symbol?
If we're down to bickering about the finer points of the syntax, can
we just have a vote already? Please?
Adam
Tangent:
Could PHP as a language be kept "pure" by first implementing python
decorators*, then implement annotations using a purpose-built
decorator?
@annotate(PHP-code-goes-here)
function framework_call(request) { ... }
On Wed, Sep 15, 2010 at 5:27 PM, Arvids Godjuks
arvids.godjuks@gmail.com wrote:
Hi all.
As a user land developer and active reader (and some times poster) for
a few years now this is the first time I trully don't understand what
the hell are you talking about and what are annotations at all and
what will be the usage of them in the PHP. And for what? Building 2-3
frameworks and that's all (as I understand from reading this
discussion)?
As a userland user also, its about much more then this, and still, if
its just for these frameworks, i'm a user of these frameworks,
anything that makes it easier for me to use them or make them faster,
i'm in for it. Like the doctrine example, adding a ORM layer on top of
my objects just by adding annotations an not extending objects and
such is a huge gain in my applications.
I'm sure pretty much user land developers read this thread and ask
themselves the same question.
I'm also NOT asking myself this question, so its looks like 2:1 as
mentioned above by Tyrael
Also, discussing one interest does not stop work on all of the other
features/bugs the amount of people reading and discussing here is a
small percentage of the team that works on PHP.
--
Rafael Dohms
PHP Evangelist and Community Leader
http://www.rafaeldohms.com.br
http://www.phpsp.org.br
At 08:09 15/09/2010, Stas Malyshev wrote:
Phpdocs aren't "user documentation" only, not for a long time (I mean
the concept, not the particular application called phpDocumentor, of
course). They are being used as metadata in many places. You could
argue that's misguided but you can't ignore the fact that's what people
do. The "goals and usages" of those tags are exactly metadata - and
regardless of the annotations, I'd be happy if Reflection recognized it
finally (by integrating some kind of phpdoc tag parser).I second that word for word. FWIW, I don't see it as misguided at all.
OK, here's why "doc comments" are insufficient:
- You have to manually parse them (which is not easy; writing parsers is
quite error prone). You would also probably need to implement some form of
annotation inheritance. - There's no standardized way to express annotations, so the user will
have to learn a new syntax for each implementation. - Performance issues -- you to have to parse and validate the annotations
on each request, unless you implement your own caching mechanism. With
native annotations, you could use opcode caches to do parsing and
validation only on the first request. - Finally, and this is the most significant to me -- since PHP doesn't
know annotations (it only knows there's a blob a text), you cannot give to
certain annotations a meaning that would be recognized at an engine. With
annotations, we could, in the future, implement a special meaning for
@ReadOnly and @WriteOnly for properties and have stuff like:
@RunBefore("Log::writeMessage")
public LogAnnotation extends ReflectionAnnotation {
public $value;
}
...
@Log("Enterting method Foo::bar")
@RequiredRole("moderator")
public function bar() { }
without having to run the method through a framework that would recognize
those annotations in doc blocks. However, the only thing close to this in
the current implementation is @Inherited.
Finally, a separate issue is the syntactic one. Could we use the current
implementation but define the annotations in doc blocks instead?
If it comes to that, it'd be better than nothing. However, It would almost
certainly break BC (and subjectively, it feels wrong to mix annotations,
which have real impact on the application, with mere comments).
If the annotations were parsed only on request, it would not break BC in
the sense that whole old applications would stop working; however, when
upgrading PHP and the framework to a new version that would support
annotations, it could misinterpret old doc comments that look like
annotations (or most likely, malformed annotations). More importantly, it
would break a compelling reason to have annotations (point 4.).
--
Gustavo Lopes
Am 14.09.2010 22:12, schrieb Stas Malyshev:
I think we already have metadata in PHP, albeit done through
phpdocs. So the question is kind of moot :) We should see if it's
enough for us or we want to add/change/extend it and if so, how.
Hi,
in my mind there is a big mistake when using annotations in PHPDoc comments.
As example let as use a JSR 303 - Bean Validator like Hibernate
Validator for PHP.
namespace my\project\models\dto;
class User {
/**
* @com\jsr303\validator\constraints\NotNull
* @com\jsr303\validator\constraints\Integer
*/
public $id;
/**
* @com\jsr303\validator\constraints\NotNull
* @com\jsr303\validator\constraints\Regexp('/[a-z]*/i')
* @com\jsr303\validator\constraints\MinLength(2)
* @com\jsr303\validator\constraints\MaxLength(255)
*/
public $name;
/**
* @com\jsr303\validator\constraints\NotNull
* @my\project\validator\constraints\Zipcode
*/
public $zipcode;
}
It is possible to use this type of annotations but it is impracticable.
An other problem is that every framework use its one annotation syntax.
So it makes the framework end user more confusing as using a clear
unique syntax.
I think the PHP way should be as in the next example.
namespace my\project\models\dto;
use com\jsr303\validator\constraints\NotNull;
use com\jsr303\validator\constraints\Integer;
use com\jsr303\validator\constraints\Regexp;
use com\jsr303\validator\constraints\MinLength;
use com\jsr303\validator\constraints\MaxLength;
use my\project\validator\constraints\Zipcode;
class User {
[NotNull]
[Integer]
public $id;
[NotNull]
[Regexp('/[a-z]*/i')]
[MinLength(2)]
[MaxLength(255)]
public $name;
[NotNull]
[Zipcode]
public $zipcode;
}
With this out of the box PHP annotations it makes it possible to create
powerful frameworks which can used by a great range of developers
without learning a new syntax for it. Pleas do not argue about thy
syntax of the annotation because this isn't final.
Greetings,
Christian
Hi!
class User {
[NotNull] [Integer] public $id; [NotNull] [Regexp('/[a-z]*/i')] [MinLength(2)] [MaxLength(255)] public $name; [NotNull] [Zipcode] public $zipcode;
}
I'm not sure I understand - why can't you use normal data structure to
keep this information? Why it has to be in weird syntax with []s that
has to be accessed through reflection?
powerful frameworks which can used by a great range of developers
without learning a new syntax for it. Pleas do not argue about thy
syntax of the annotation because this isn't final.
Whatever syntax it is, it is definitely new.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Am 14.09.2010 22:12, schrieb Stas Malyshev:
I think we already have metadata in PHP, albeit done through
phpdocs. So the question is kind of moot :) We should see if it's
enough for us or we want to add/change/extend it and if so, how.in my mind there is a big mistake when using annotations in PHPDoc comments.
What is the mistake? You don't explain that anywhere in your reply -- you simply
give code examples of how you feel they should work.
<snip>As example let as use a JSR 303 - Bean Validator like Hibernate
Validator for PHP.namespace my\project\models\dto;
class User {
/** * @com\jsr303\validator\constraints\NotNull * @com\jsr303\validator\constraints\Integer */ public $id;
It is possible to use this type of annotations but it is impracticable.
How is it impractical? What exactly is impractical about it? To be honest, what
you show above (and also in your more "ideal" examples below) leaves me
scratching my head -- if the classnames don't have the word "validator" in them,
I have zero idea what the intent of the annotation is.
An other problem is that every framework use its one annotation syntax.
So it makes the framework end user more confusing as using a clear
unique syntax.
Actually, I see this as a benefit or feature of such an approach -- it
allows developers to define their own annotations, which allows them to create
new approaches. We see this already in docblock annotations -- PHPUnit makes use
of them (@expectedException, @group, etc.). Groups like the Framework Interop
Group can tackle standard use cases.
I think the PHP way should be as in the next example.
namespace my\project\models\dto;
use com\jsr303\validator\constraints\NotNull;
use com\jsr303\validator\constraints\Integer;
use com\jsr303\validator\constraints\Regexp;
use com\jsr303\validator\constraints\MinLength;
use com\jsr303\validator\constraints\MaxLength;
use my\project\validator\constraints\Zipcode;class User {
[NotNull] [Integer] public $id;
This is entirely unclear to me. Will it type-cast to integers? will it throw an
exception for null values? I actually don't know what this code will do -- which
brings me to my chief issue so far with this debate: annotations, since they are
meant to be "machine-readable" (that's what all the proponents are saying,
anyways), introduce a huge WTF factor when debugging -- is it the code that
caused an exception? If not, was it an annotation? Which one? what input did it
get? etc.
With this out of the box PHP annotations it makes it possible to create
powerful frameworks which can used by a great range of developers
without learning a new syntax for it. Pleas do not argue about thy
syntax of the annotation because this isn't final.
Um, you're being contradictory here -- you're actually suggesting a brand new
syntax, which leads to the exact opposite of what you assert. Using existing
docblocks and adding an annotations parser to it would be using existing syntax.
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Am 16.09.2010 18:02, schrieb Matthew Weier O'Phinney:
in my mind there is a big mistake when using annotations in PHPDoc comments.
What is the mistake? You don't explain that anywhere in your reply -- you simply
give code examples of how you feel they should work.
For me the mistake is that annotation classes must be defined with their
FQN or you must create an alias for the namespace. This alias must be
registered before using this annotations. Every framework I use uses its
own rules for defining annotatations, registering annotation namespaces
and so on. For me this is impractical. Registering the namespace with
the out of the box PHP use statement is for me the better way.
I thought this was clear from my comparison.
An other problem is that every framework use its one annotation syntax.
So it makes the framework end user more confusing as using a clear
unique syntax.
Actually, I see this as a benefit or feature of such an approach -- itwer ist den dir auf den schlips getreten
allows developers to define their own annotations, which allows them to create
new approaches. We see this already in docblock annotations -- PHPUnit makes use
of them (@expectedException, @group, etc.). Groups like the Framework Interop
Group can tackle standard use cases.
This isn't what I meant with different syntax. Different syntax for me is:
[Annotation([1, 2, 3])]
@Annotation({1, 2, 3})
%Annotation(array(1, 2, 3))
Have fun, using annotations from different frameworks for one and the
same method, property or class.
I think the PHP way should be as in the next example.
namespace my\project\models\dto;
use com\jsr303\validator\constraints\NotNull;
use com\jsr303\validator\constraints\Integer;
use com\jsr303\validator\constraints\Regexp;
use com\jsr303\validator\constraints\MinLength;
use com\jsr303\validator\constraints\MaxLength;
use my\project\validator\constraints\Zipcode;class User {
[NotNull] [Integer] public $id;
This is entirely unclear to me. Will it type-cast to integers? will it throw an
exception for null values? I actually don't know what this code will do -- which
brings me to my chief issue so far with this debate: annotations, since they are
meant to be "machine-readable" (that's what all the proponents are saying,
anyways), introduce a huge WTF factor when debugging -- is it the code that
caused an exception? If not, was it an annotation? Which one? what input did it
get? etc.
If an annotation throws an exception because of syntax errors you get an
stack trace. So it should not be a problem to localize this error.
In this example the annotations doesn't throw any exceptions.
$user = new User;
$user->id = 'only integers are allowed';
$validator = new Validator();
$results = $validator->validate($user);
The result contains a constraint violation message. For more you can
look at the Hibernate Validator page.
http://www.hibernate.org/subprojects/validator.html
With this out of the box PHP annotations it makes it possible to create
powerful frameworks which can used by a great range of developers
without learning a new syntax for it. Pleas do not argue about thy
syntax of the annotation because this isn't final.
Um, you're being contradictory here -- you're actually suggesting a brand new
syntax, which leads to the exact opposite of what you assert.
I meant that this developers who using this frameworks must not learn
different syntaxes but rather one.
Using existing
docblocks and adding an annotations parser to it would be using existing syntax.
- How would you comment out an annotation in a doc block?
- How would you define annotations with namespaces?
- Parsing of annotations is slow. When using caching every framework
that I use implements other caching rules for its annotations.
There are many more reasons mentioned in all the mails.
You may excuse me because I am not an native English speaker so it can
be be the case the one or the other formulation isn't correct.
Greetings,
Christian
At 17:51 13/09/2010, Gustavo Lopes wrote:
On Mon, 13 Sep 2010 16:28:47 +0100, Zeev Suraski zeev@zend.com
wrote:At 16:39 13/09/2010, Pierre Joye wrote:
You are not serioulsy suggesting to use phpdoc for runtime
annotation
support? Are you?I actually am (either that or get what you want done in some other
way). It's a rare enough use case that I think it's a very
reasonable
compromise. The disadvantages of adding a whole new branch of
syntax,
for this rare use case, far outweigh its advantages - IMHO.Rare use case? Have you seen any recent Java framework? Or Java EE 6?
Or
design by contract in C#? A declarative programming style can be very
handy.Framework code (as in code that actually goes into a framework, not
code
that uses a framework) represents a tiny percentage of the PHP codebase
at large. Most of it is application code.You misunderstood me. When I say the frameworks use annotation I don't
mean they use annotations in their own implementation (that's not
particularly relevant for the reason you present).What I mean is that the frameworks recognize annotations the application
code has so that the framework user can do stuff like injecting objects,
run methods in transactions or check post-conditions in a declarative
fashion, by adding annotations.By the way, you ignored the rest of the e-mail.
How do you evaluate the complexity/return of features such as annotations
with that of e.g. LSB? Why are they not adequate for PHP, but may be for
other languages?I do not understand this.
I see no one other than Symfony / Doctrine people pushing for this
annotations patch.How can this special-purpose feature (which would add entirely new language
semantics in the form of an embedded micro-language) even be open for
discussion, when other, more generally-useful RFCs like
http://wiki.php.net/rfc/shortsyntaxforarrays were shot down on the basis
that they were hard to read and confusing for new developers?Sorry, but I don't see how this is even remotely close to being appropriate
for PHP. Maybe I'm missing something. :-)Thanks,
- Nate
It's the same as Zeev said:
"The fact we have complex components in PHP is no excuse to add more
complexity to the language. It's not a binary state, with PHP "already
being complex", so we can add as much complexity as we want. Complexity
accumulates."
The fact that we rejecteded better features in PHP is no excuse to reject
good ideas from the...
at least without a discussion which is just happening.
Tyrael