Skip to content
This repository was archived by the owner on Apr 5, 2020. It is now read-only.

Conversation

@thekid
Copy link
Member

@thekid thekid commented Jan 25, 2012

Implementation for xp-framework/rfc#218

<?php
  class Example extends Object {

    #[@$conn: inject(name= 'db')]
    public function setConnection(DBConnection $conn)  {
      // ...
    }
  }
?>

See also pull request #33

- Add hasAnnotation()
- Add getAnnotation()
- Add hasAnnotations()
- Add getAnnotations()
- Add normalParameterGetAnnotationRaisesException()
@thekid
Copy link
Member Author

thekid commented Jan 27, 2012

Quoting @mrosoiu

the syntax for method parameter annotations is pain and suffering to my eyes :)

Hrm, in Java it's similar:

public class Example {

    public void setConnection(@Inject(name = "db") DBConnection conn)  {
        // ...
    }
}

See http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html

Same goes for C#:

public class Example 
{

    public void SetConnection([Inject(Name = "db")] DBConnection conn)
    {
        // ...
    }
}

See http://msdn.microsoft.com/library/z0w1kczw.aspx

Is the pain in our syntax proposal caused by the /* ... */?

@thekid
Copy link
Member Author

thekid commented Jan 27, 2012

@mikey179 proposed embedding the parameter name in the annotation and the writing it on top of the method declaration line (or was it in the apidoc) - can't remember exactly where. Anyways, this could be an alternative:

<?php
  class Example extends Object {

    #[@$conn: inject(name= 'db')]
    public function setConnection(DBConnection $conn)  {
      // ...
    }
  }
?>

This is also similar to C# syntax for attribute targets (see above MSDN page, about halfway down the page).

@mrosoiu - how does that look to you?

@mrosoiu
Copy link
Member

mrosoiu commented Jan 27, 2012

Timm, the "pain and suffering" is definitely a matter of personal taste. Please don't take it as something against your and @mikey179's efforts on this issue. Plus, it was said in a funny context, with awesome llamas and all :)

I understand the reasons behind the need of /*[...]*/ syntax and the fact that this is a language constraint and there is no alternative... but, same as with the PHP official namespacing schema, I just think it looks ugly. When I can't use XP-Framework, I prefer to write old-school / no-namespace PHP, for the simple fact that the backslashes hurt my eyes.

Regarding your alternative proposal with parameter annotations included in method annotations: I've been playing with it a bit and it doesn't look bad at all; not sure about performance / speed impact, but I definitely like it more than /*[...]*/

@thekid
Copy link
Member Author

thekid commented Jan 28, 2012

@mrosoiu - @mikey179 and me discussed this yesterday in the bar, and we also prefer the #[@$conn: inject(name= 'db')] syntax... I'll incorporate this back into the RFC, I think.

  one containing the annotations and one the annotations with targets
- Parse the regular annotations into DETAIL_ANNOTATIONS as before and
  the annotations with targets into the new element DETAIL_TARGET_ANNO
- Remove tokenizing the method signature
# Backwards compatible
# See changes to lang.XPClass
# See changes to lang.XPClass
# See changes to lang.XPClass
@thekid
Copy link
Member Author

thekid commented Jan 28, 2012

XP Language way of doing this @ xp-lang/compiler#4

thekid added a commit that referenced this pull request Sep 30, 2012
XP Framework method parameter annotations
@thekid thekid merged commit 3b23781 into xp-framework:xp5_9 Sep 30, 2012
thekid added a commit that referenced this pull request Sep 30, 2012
# See xp-framework/rfc#218, implemented by pull request #116
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants