Live data from Hacker News

PHP Annotations Are a Horrible Idea

theunraveler.com

81–90 of 127 posts

Re: PHP Annotations Are a Horrible Idea

#81
post #50

Earlier quoted context omitted.

Came here to post the same thing. I don't know if it has been fixed in 5.4, though.

Nope, the parser seems to be pretty brittle around this. Someone who knows more about the internals can probably explain why this works: class User { public $mapping = array( 'username' => array( 'type' => 'string', 'length' => 32, 'unique' => true, ) ); public function __construct() { $this->mapping['nullable'] = function() { echo "test"; }; $this->mapping['nullable'](); } } $user = new User(); And this doesn't: cla…

I used to be interested in helping fix PHP, but I gave up.

The reason is because Rasmus and a few others seem to think that using the syntax definition to do your type checking for you is a good idea, and that the hundreds of possible cases they didn't think of, don't matter.

Re: PHP Annotations Are a Horrible Idea

#82

Earlier quoted context omitted.

PHP OO is broken in many ways (of which you can find a list in the blog post "php a fractal of bad design" PHP is naturally (due to it's C libs) non-OO and will thus only implement OO "that" far. Lastly, OO is not a silver bullet and is best used only in front-end, and languages that were designed with it in mind.

Well, OOP in PHP seems to work rather well for thousands of large projects out in the wild - making your argument invalid.

Well, smoking cigarettes seems to work rather well for millions of successful people out in the wild - making your argument invalid.

It IS possible to make "business good" software in brainfuck, that's just not a reason to call it "not broken".

See, this is about science, logic, and whether or not a feature is properly supported by a language, not about whether or not somebody managed to build and sell a solution while using that feature.

Re: PHP Annotations Are a Horrible Idea

#83

Earlier quoted context omitted.

> I never know that, but still, the point stands: making a comment necessity for code to function properly is bad, bad, bad. Not really. > That's why the Java folks throws it out right? I'm not sure what that's supposed to mean. "Java folks" don't throw anything out, Sun introduced a better and better-supported mechanism for doing what javadocs were coerced into doing.

> I'm not sure what that's supposed to mean. "Java folks" don't throw anything out, Sun introduced a better and better-supported mechanism for doing what javadocs were coerced into doing. I mean the Java community didn't use it anymore, because the "annotation inside comment" thing is worse than "annotation supported natively by the language". Granted, it's the only practical way to do it in PHP for now, but it still…

[deleted]

Re: PHP Annotations Are a Horrible Idea

#84

Earlier quoted context omitted.

> I never know that, but still, the point stands: making a comment necessity for code to function properly is bad, bad, bad. Not really. > That's why the Java folks throws it out right? I'm not sure what that's supposed to mean. "Java folks" don't throw anything out, Sun introduced a better and better-supported mechanism for doing what javadocs were coerced into doing.

> I'm not sure what that's supposed to mean. "Java folks" don't throw anything out, Sun introduced a better and better-supported mechanism for doing what javadocs were coerced into doing. I mean the Java community didn't use it anymore, because the "annotation inside comment" thing is worse than "annotation supported natively by the language". Granted, it's the only practical way to do it in PHP for now, but it still…

> I mean the Java community didn't use it anymore, because the "annotation inside comment" thing is worse than "annotation supported natively by the language".

Sure, unless you don't have "annotations supported natively by the language".

> Granted, it's the only practical way to do it in PHP for now

Indeed.

> I wonder why SensioLabs (the creator of Symfony and Doctrine) didn't make the PHP's annotation RFC into reality. They are a quite huge powerhouse in the PHP world...

They might be a powerhouse, but they still aren't the drivers of PHP itself, Zend is. They can ask for the RFC to be finalized and implemented but at the end of the day, they also need to ship. And probably to ship on more versions than a hypothetical future 5.5.

Re: PHP Annotations Are a Horrible Idea

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

I think this is quite a good technical reason: Because code comments should never be necessary for a script to function properly. In which other language do you see comment is necessary to make the code function properly?

In which other language do you see comment is necessary to make the code function properly?

Oracle SQL hints come to mind: http://www.dba-oracle.com/t_sql_hints_tuning.htm

There is it even worse because the hint may be needed to make your code run, but Oracle doesn't tell you whether or not the hint is actually in use or made a difference.

Re: PHP Annotations Are a Horrible Idea

#86
post #83

Earlier quoted context omitted.

> I'm not sure what that's supposed to mean. "Java folks" don't throw anything out, Sun introduced a better and better-supported mechanism for doing what javadocs were coerced into doing. I mean the Java community didn't use it anymore, because the "annotation inside comment" thing is worse than "annotation supported natively by the language". Granted, it's the only practical way to do it in PHP for now, but it still…

[deleted]

> No, Java uses the same syntax with annotation inside comments.

Mostly incorrect, these are javadoc annotations which usually aren't used by code (aside from the javadoc extraction tool that is, and sometimes code editors for the @deprecated javadoc tag)

Since java 5, java has notations as language syntax e.g.

    /**
     * Some javadoc comment
     */
    @Annotation
    public void someMethod() {
        // stuff
    }
http://docs.oracle.com/javase/tutorial/java/javaOO/annotatio... which are supported by a formal extraction framework and are syntax- and type-checked by the java parser itself, and attached as metadata to classes and methods by the same.

Before java5, these were inside comments (alongside javadoc tags), fully processed by third-party tools and had no support from the JVM itself.

Re: PHP Annotations Are a Horrible Idea

#87
post #54

"Without the special @Template comment, Symfony does not know where to find the template file." First off, this is completely false. With symfony2 the action needs to return a Response object. This annotation isn't required and the team I work with, we rarely use this. It's very useful for when you are just adding a page that contains no real business logic. "Doctrine 2 does the same thing when declaring object prope…

> First off, this is completely false. With symfony2 the action needs to return a Response object. This annotation isn't required and the team I work with, we rarely use this. Correct. But if you want use the form where you just return an array of variables to use inside your template, and have Symfony smartly located the template for you, you have to use an annotation. See http://stackoverflow.com/questions/12922827…

> Correct. But if you want use the form where you just return an array of variables to use inside your template, and have Symfony smartly located the template for you, you have to use an annotation. See http://stackoverflow.com/questions/12922827/symfony-2-php-te.... for an example.

Your point is that this is required, it's not. Using annotations is optional. The user you point to in the example wanted to use the annotations and wanted to use php templates.

The FACT is that in Symfony2, your Action MUST return a Response object. Using annotations is an easy way to get around this.

> Yes, there are other BETTER ways to do it. Making comment-based annotations available as one of the ways pretty much guarantees that people will use it, and that seems like a bad idea to me. Just remove them so no one is able to choose the bad practice.

Why is this a bad practice? Everything I need to now is right there in the annotation. I know that it's a string, integer, or anything else. I don't need to open up another file to check.

> Uhh, OK? How about comment folding in text editors? Would you, as a developer, be happy if you encountered some code that made heavy use of annotations for critical application logic? I wouldn't--this is what I mean by DX.

... You can't unfold them? You mean to tell me that having an editor that folds comments is bad design for the software that uses annotations? I'm trying to figure out this critical application logic you speak of. If I'm using annotations to describe a column that is a "string" type and has a length of "32" then what is the difference of it's in a yml or xml file? I enjoy being able to tell that as well as what relationships there are.

> The same thing you gain by var_dump()ing any variable--an understand of what's happening under the hood.

Again, why are you trying to var_dump something that has no value in using a var_dump on? An example of using var_dump and it being useful is "var_dump($user->getSomeRandomCrap())". It tells me what is returned by that method. Is an object or something else returned. WHY DO NEED to var_dump "@Column(type="string", length=32)"? I know the property should be a string and should be a max of 32 characters long?

Re: PHP Annotations Are a Horrible Idea

#88

Earlier quoted context omitted.

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. Maybe it is subjective, but it sure gives me an icky feeling. You're breaking down a clear division between code and comment - fuzzing the lines. There's something about the idea that yes, I can only describe as being gross. To each thei…

Some people don't like 4 space indentations, some don't like using tabs, and in most cases there's just an icky feeling behind it. Who's right? In your own post, you give a reason for why you think (and not feel) it is wrong, and that's the right way to do. Icky feelings aren't. Maybe people saying that it feels wrong are crossing a line too?

You can be intuitively against something, but not be able to work out why. A few hours later, you often realize the rational reasons behind your original feeling.

Re: PHP Annotations Are a Horrible Idea

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

Any editor that starts with comments collapsed is going to hide the functionality buried in comments. But that's a minor issue.

Comments are exactly that - comments. They are not intended to be executed and can be changed or removed at will. They are not necessary. They exist to provide further explication for code that is not self-documenting (or just plain programmer wankery).

This changes the deal. This means that some comments are required without providing clear boundaries to those who are not cognizant of the new convention.

PHP would be better served by adding naked @annotations and leaving comments to be non-parsed.

Re: PHP Annotations Are a Horrible Idea

#90

Earlier quoted context omitted.

I think this is quite a good technical reason: Because code comments should never be necessary for a script to function properly. In which other language do you see comment is necessary to make the code function properly?

Its a syntax problem then ? what if the annotation wasn't inside comments would that make it ok ?

A lot of this boils down to PHP's feeble "array" declarator. Take a page from JavaScript and make it easy.
Post reply on HN