Re: Attributes support proposal

php.internals

Duncan McIntyre

21 years ago
Sebastian - how's the parser going? I've finished my patches to make attributes work as native PHP tokens. You can get the code and read a discussion about the various possibilities for implementation at http://www.calligram.co.uk/oss/Attributes I really hope we can come to a consensus on how to suppor this in PHP. Duncan

Hendy Irawan

21 years ago
> http://www.calligram.co.uk/oss/Attributes
Whew Duncan! That's *VERY* nice. Anyways... Annotations (structured comments) vs. Attributes? Here's my take: Since annotations are comments, you can remove them without modifying behavior. However, attributes are actually *needed* since they are part of the code. If you remove the attributes, you're changing behavior. phpDoc comments are... comments! You can remove all comments in your code and your script will run just as well when they did have comments. So, IMHO, attributes != annotations. They're two different beasts, for different purposes.
-- Hendy Irawan http://www.gauldong.net http://dev.gauldong.net

Christian Schneider

21 years ago
Duncan McIntyre wrote:
> http://www.calligram.co.uk/oss/Attributes
In your example I fail to see how @[ WidgetType("Select"); AllowableValues(array("Current","Savings")); ] is different from the good old var $WidgetType = "Select", $AllowableValues = array("Current", "Saving"); apart from looking weird and scary (-:C Just my $.02, - Chris

Duncan McIntyre

21 years ago
It's different because in your example there is no way of knowing that $AllowableValues refers to $WidgetType. You would have to explicitly code that relationship into every class which needed to know it. On Monday 25 April 2005 5:28 pm, Christian Schneider wrote:
> Duncan McIntyre wrote: > > http://www.calligram.co.uk/oss/Attributes > > In your example I fail to see how > @[ WidgetType("Select"); > AllowableValues(array("Current","Savings")); ] > is different from the good old > var $WidgetType = "Select", $AllowableValues = array("Current", "Saving"); > apart from looking weird and scary (-:C > > Just my $.02, > - Chris
Duncan

Christian Schneider

21 years ago
Duncan McIntyre wrote:
> It's different because in your example there is no way of knowing that > $AllowableValues refers to $WidgetType.
My solution would be var $attributes = array( 'accountType' => array( 'Type' => "Select", 'AllowableValues' => array("Current","Savings") ) ); with a central attribute definition or alternatively var $attributes_accountType = array( 'Type' => "Select", 'AllowableValues' => array("Current","Savings") ); But then again I think the whole thing is typical OO bloat anyway and that's why I don't want to have language features added for it (-:C Over and out, - Chris

Zeev Suraski

21 years ago
At 20:12 25/04/2005, Christian Schneider wrote:
>[snip] >But then again I think the whole thing is typical OO bloat anyway and >that's why I don't want to have language features added for it (-:C
I wholeheartedly agree. Zeev

Duncan McIntyre

21 years ago
On Wednesday 27 April 2005 1:28 pm, Zeev Suraski wrote:
> At 20:12 25/04/2005, Christian Schneider wrote: > >[snip] > >But then again I think the whole thing is typical OO bloat anyway and > >that's why I don't want to have language features added for it (-:C > > I wholeheartedly agree. > > Zeev
I remember similar arguments being made about most of the new OO features in PHP5. Out of interest, how is this more bloated than storing doc comments in memory? If you are worried about removing bloat, I suggest removing doc comments from the engine. You are already storing the filename and linenumber where elements are defined, retrieving associated doc comments could happen in userland and a lot of memory would be saved. Or again, how is this more bloated than named parameters? There are reasons why modern languages provide this feature: because it's useful and because you cannot emulate it. And no, rigidly enforced variable naming schemes are not a substitute - what about inheritance? multiple declarations?. Of course if you think that is a substitute, then why not go the whole hog and require classes to declare the methods listProperties() and listMethods() and do away with reflection entirely? That's just OO bloat too. When you need a feature like this and it doesn't exist, the workarounds lead to - fragile classes as consumer classes need to know implementation details of the classes they consume, rather than being able to use reflection. - bloat in the application code. - disconnect between the declaration of an element and the information the class wishes to provide about the element. Imagine if public/private/protected didn't exist. I can imagine a ghastly workaround which would work, but you wouldn't want to use it. Same goes for attributes: they are an intrinsic property of an element, and to declare them somewhere else in the code makes no sense. The implementation requires as much space in the property_info struct as doc_comment, and twenty lines of c code. Not a lot. And the work's been done for you already! How about a deal: I'll remove the doc_comment code from the engine and put it into the reflection api if you'll accept my attributes patches. You'll end up with a faster engine which uses less memory, and the rest of us will get a seriously useful new feature. How about it? Duncan

Zeev Suraski

21 years ago
At 16:58 27/04/2005, Duncan McIntyre wrote:
>I remember similar arguments being made about most of the new OO features >in PHP5. > >Out of interest, how is this more bloated than storing doc comments in memory?
It's feature bloat, not memory consumption bloat. Adding obscure operators is the worst thing to do, since it reduces readability and complicates the language. Comments can be ignored, removed, be completely 'broken', etc. - you can use them if you understand them and they're useful to you, but you'll never get a piece of code which you wouldn't understand because of the comment. Not so with features such as attributes.
>If you are worried about removing bloat, I suggest removing doc comments >from the engine. You are already storing the filename and linenumber where >elements are defined, retrieving associated doc comments could happen in >userland and a lot of memory would be saved.
Again, I care less about memory consumption (which is quite small in both cases), and more about readability and intuitiveness.
>Or again, how is this more bloated than named parameters?
This one is arguable, but subjectively, I think that both the concept and syntax of named arguments are very intuitive, if only for being standard in most of the languages PHP borrows syntax from.
>There are reasons why modern languages provide this feature: because it's >useful and because you cannot emulate it. And no, rigidly enforced >variable naming schemes are not a substitute - what about inheritance? >multiple declarations?. Of course if you think that is a substitute, then >why not go the whole hog and require classes to declare the methods >listProperties() and listMethods() and do away with reflection entirely? >That's just OO bloat too. > >When you need a feature like this and it doesn't exist, the workarounds >lead to > >- fragile classes as consumer classes need to know implementation details >of the classes they consume, rather than being able to use reflection. > >- bloat in the application code. > >- disconnect between the declaration of an element and the information the >class wishes to provide about the element. Imagine if >public/private/protected didn't exist. I can imagine a ghastly workaround >which would work, but you wouldn't want to use it. Same goes for >attributes: they are an intrinsic property of an element, and to declare >them somewhere else in the code makes no sense. > >The implementation requires as much space in the property_info struct as >doc_comment, and twenty lines of c code. Not a lot. And the work's been >done for you already!
Yes, drawing the line of what should go into PHP and what shouldn't is a tough job. We may have already gone too far with what we've done with PHP 5, although I don't think we did. What that means is that not every useful feature should find its way into the language, since the biggest advantage PHP has is not the richness of its features, but the facts they glue together nicely into a language that's very easy to use. If in the few cases where attributes are required you'd have to implement a couple of more interfaces and complicate your code, so be it, it's much better than introducing a feature that would be useful for very few and at the same time decrease the readability of the language.
>How about a deal: I'll remove the doc_comment code from the engine and put >it into the reflection api if you'll accept my attributes patches. You'll >end up with a faster engine which uses less memory, and the rest of us >will get a seriously useful new feature. How about it?
I'm not too thrilled about this deal. I don't think I'd be in favour of accepting this attributes patch regardless of just about anything else. Not sure how others feel about it, but at least in my opinion, this feature is a clear 'no no' for PHP. Zeev

Derick Rethans

21 years ago
On Wed, 27 Apr 2005, Zeev Suraski wrote:
> I'm not too thrilled about this deal. I don't think I'd be in favour of > accepting this attributes patch regardless of just about anything else. Not > sure how others feel about it, but at least in my opinion, this feature is a > clear 'no no' for PHP.
Indeed it is. Derick

Duncan McIntyre

21 years ago
On Wednesday 27 April 2005 2:19 pm, Zeev Suraski wrote:
> At 16:58 27/04/2005, Duncan McIntyre wrote: > >I remember similar arguments being made about most of the new OO features > >in PHP5. > > > >Out of interest, how is this more bloated than storing doc comments in > > memory? > > It's feature bloat, not memory consumption bloat. Adding obscure operators > is the worst thing to do, since it reduces readability and complicates the > language. Comments can be ignored, removed, be completely 'broken', etc. - > you can use them if you understand them and they're useful to you, but > you'll never get a piece of code which you wouldn't understand because of > the comment. Not so with features such as attributes. >
Moving this sort of metadata away from the element it belongs to and declaring it in another method or property doesn't do much to help understanding either. Interfaces or not.
> >If you are worried about removing bloat, I suggest removing doc comments > >from the engine. You are already storing the filename and linenumber where > >elements are defined, retrieving associated doc comments could happen in > >userland and a lot of memory would be saved. > > Again, I care less about memory consumption (which is quite small in both > cases), and more about readability and intuitiveness. >
Hmm. As I mentioned to Christian in a private email, I have a system which is 350K LOC. Now not all of that gets loaded at one time of course (thank God for __autoload()!), but there are times when a significant proportion of it is loaded. And then it munches memory. Yes, I can strip the comments from production code. But that defeats the object of the getDocComments() reflection code. And screws me for my fallback attributes methodology :-( ... ... ...
> I'm not too thrilled about this deal. I don't think I'd be in favour of > accepting this attributes patch regardless of just about anything > else. Not sure how others feel about it, but at least in my opinion, this > feature is a clear 'no no' for PHP. > > Zeev
And there was I thinking you'd jump at it :-) D.

Andrey Hristov

21 years ago
Hi, Duncan McIntyre wrote:
> On Wednesday 27 April 2005 2:19 pm, Zeev Suraski wrote: > >>At 16:58 27/04/2005, Duncan McIntyre wrote: >> >>>I remember similar arguments being made about most of the new OO features >>>in PHP5. >>> >>>Out of interest, how is this more bloated than storing doc comments in >>>memory? >> >>It's feature bloat, not memory consumption bloat. Adding obscure operators >>is the worst thing to do, since it reduces readability and complicates the >>language. Comments can be ignored, removed, be completely 'broken', etc. - >>you can use them if you understand them and they're useful to you, but >>you'll never get a piece of code which you wouldn't understand because of >>the comment. Not so with features such as attributes. >> > > Moving this sort of metadata away from the element it belongs to and declaring > it in another method or property doesn't do much to help understanding > either. Interfaces or not. > > >>>If you are worried about removing bloat, I suggest removing doc comments >> >>>from the engine. You are already storing the filename and linenumber where >> >>>elements are defined, retrieving associated doc comments could happen in >>>userland and a lot of memory would be saved. >> >>Again, I care less about memory consumption (which is quite small in both >>cases), and more about readability and intuitiveness. >> > > Hmm. As I mentioned to Christian in a private email, I have a system which is > 350K LOC. Now not all of that gets loaded at one time of course (thank God > for __autoload()!), but there are times when a significant proportion of it > is loaded. And then it munches memory. Yes, I can strip the comments from > production code. But that defeats the object of the getDocComments() > reflection code. And screws me for my fallback attributes methodology :-(
Wooha, what a beastie, 350 kloc. Never seen such a thing in PHP.

Duncan McIntyre

21 years ago
On Wednesday 27 April 2005 2:19 pm, Zeev Suraski wrote:
> At 16:58 27/04/2005, Duncan McIntyre wrote: > >I remember similar arguments being made about most of the new OO features > >in PHP5. > > > >Out of interest, how is this more bloated than storing doc comments in > > memory? > > It's feature bloat, not memory consumption bloat. Adding obscure operators > is the worst thing to do, since it reduces readability and complicates the > language. Comments can be ignored, removed, be completely 'broken', etc. - > you can use them if you understand them and they're useful to you, but > you'll never get a piece of code which you wouldn't understand because of > the comment. Not so with features such as attributes. >
How about adding a new keyword instead, if you don't like @[..]? Say, attributes(..) or metadata(..) or something we can all agree on? D.

Derick Rethans

21 years ago
On Wed, 27 Apr 2005, Duncan McIntyre wrote:
> On Wednesday 27 April 2005 2:19 pm, Zeev Suraski wrote: > > At 16:58 27/04/2005, Duncan McIntyre wrote: > > >I remember similar arguments being made about most of the new OO features > > >in PHP5. > > > > > >Out of interest, how is this more bloated than storing doc comments in > > > memory? > > > > It's feature bloat, not memory consumption bloat. Adding obscure operators > > is the worst thing to do, since it reduces readability and complicates the > > language. Comments can be ignored, removed, be completely 'broken', etc. - > > you can use them if you understand them and they're useful to you, but > > you'll never get a piece of code which you wouldn't understand because of > > the comment. Not so with features such as attributes. > > > How about adding a new keyword instead, if you don't like @[..]? > Say, attributes(..) or metadata(..) or something we can all agree on?
It's not the way how it's written down, it's the whole concept. Derick
-- Derick Rethans http://derickrethans.nl | http://ez.no | http://xdebug.org

Zeev Suraski

21 years ago
At 17:44 27/04/2005, Duncan McIntyre wrote:
>Hmm. As I mentioned to Christian in a private email, I have a system which is >350K LOC. Now not all of that gets loaded at one time of course (thank God >for __autoload()!), but there are times when a significant proportion of it >is loaded. And then it munches memory. Yes, I can strip the comments from >production code. But that defeats the object of the getDocComments() >reflection code. And screws me for my fallback attributes methodology :-(
With the proper compiled code cache, even with 350K lines of code the amount of memory necessary for storing all of the data shouldn't be too big. Zeev

Andi Gutmans

21 years ago
At 03:28 PM 4/27/2005 +0300, Zeev Suraski wrote:
>At 20:12 25/04/2005, Christian Schneider wrote: >>[snip] >>But then again I think the whole thing is typical OO bloat anyway and >>that's why I don't want to have language features added for it (-:C > >I wholeheartedly agree.
So do I. If you really need such functionality (very questionable), implement it in ways which were recommended. You can always cache tokenizer results or other results in order not to suffer performance loss (if you'd feel it in the first place). Andi

Duncan McIntyre

21 years ago
On Wednesday 27 April 2005 10:16 pm, Andi Gutmans wrote:
> At 03:28 PM 4/27/2005 +0300, Zeev Suraski wrote: > >At 20:12 25/04/2005, Christian Schneider wrote: > >>[snip] > >>But then again I think the whole thing is typical OO bloat anyway and > >>that's why I don't want to have language features added for it (-:C > > > >I wholeheartedly agree. > > So do I. If you really need such functionality (very questionable), > implement it in ways which were recommended. You can always cache tokenizer > results or other results in order not to suffer performance loss (if you'd > feel it in the first place). > > Andi
I do. OK. I concede defeat. But since Zeev tells me doc comments survive compilation/acceleration whatever, I can use that approach and parse them out by hand. Stick it on the list for php6? D.

Andi Gutmans

21 years ago
At 11:25 AM 4/28/2005 +0100, Duncan McIntyre wrote:
>On Wednesday 27 April 2005 10:16 pm, Andi Gutmans wrote: > > At 03:28 PM 4/27/2005 +0300, Zeev Suraski wrote: > > >At 20:12 25/04/2005, Christian Schneider wrote: > > >>[snip] > > >>But then again I think the whole thing is typical OO bloat anyway and > > >>that's why I don't want to have language features added for it (-:C > > > > > >I wholeheartedly agree. > > > > So do I. If you really need such functionality (very questionable), > > implement it in ways which were recommended. You can always cache tokenizer > > results or other results in order not to suffer performance loss (if you'd > > feel it in the first place). > > > > Andi >I do. > >OK. I concede defeat. But since Zeev tells me doc comments survive >compilation/acceleration whatever, I can use that approach and parse them out >by hand. > >Stick it on the list for php6?
Nope :) Andi

Sebastian Bergmann

21 years ago
Duncan McIntyre wrote:
> Sebastian - how's the parser going?
Have a look at http://pear.php.net/pepr/pepr-proposal-show.php?id=237
-- Sebastian Bergmann http://www.sebastian-bergmann.de/ GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69