W
W
wittyrider2015-09-06 13:24:34
symfony
wittyrider, 2015-09-06 13:24:34

Are there any objective reasons to refuse an annotation?

It's more of a matter of religion, but why are annotations bad?
Now I am writing everything (validation / mapping / serializer) on annotations, what kind of rake can I get into in the future?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-09-06
@wittyrider

Why are annotations bad? Because there are no annotations in PHP (at least not yet). And what is there is a hack based on phpdoc.
In general, annotations are good and convenient. If you are doing something that will be used by third party developers, do not use annotations, yaml gives more flexibility in terms of configuration management. But again, this is a highly debatable point.
There is one more BUT. Let's say I was once categorically against the use of annotations in doctrine entities. Imagine a typical symfony project. We have some kind of field and we must write there at least an annotation for the doctrine and an annotation for the validator. If we write an API, then all sorts of serializers and other nonsense appear, API documentation, and so on. Well, actually phpdoc itself. As a result, at least 5 lines in phpdoc with annotations go to one entity field.
But the way out of this situation is obvious: stop using doctrine entities outside the service layer (in controllers, forms, and other nonsense), validate only DTO, and ensure that the model, in principle, cannot enter an invalid state. And then there are only annotations for the doctrine, which I can put up with because I'm lazy. Validating a request or a form is quite simple.
In short, annotations and attributes are a cool way to declaratively define how a system should behave. But many developers somehow go too far with this. The rest is just a matter of taste.

B
BoShurik, 2015-09-06
@BoShurik

If annotations are used for routing, the routes cannot be sorted in the correct order. In the end, you still have to resort to yaml: example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question