I have based many designs and frameworks that use C# Attributes over the past 4 or 5 years.
But lately I see many people openingly discouraging their use or changing their frameworks to reduce the need or use of them.
I found them to be a godsend but now I am starting to wonder what I am missing.
To clarify: Use Convention over Configuration is becoming a major principle to follow especially in the ORM field. Is this area you can map fields with a config file (XML), use an attribute, or have a common naming convention that maps directly to fields in your database tables. I don’t have any references to quote but I have read some backlash against adding another Attribute to the mix.
But I feel over the three choices I just listed that Attributes still make the most sense. A Config file is harder to maintain and a common naming convention ties you to the implementation of the database field. Attributes are placed exactly where they are needed and the implemntation can change without disconnecting from where it is used.
There are really two purposes of attributes: as user visible things, and as things emitted by a compiler.
I assume you are talking about user visible attributes.
In general, I would say that user visible attributes are not ideal.
Most of the time they are used to embed some form of custom language on top of C#. DLINQ attributes are a good example of this. A better approach, from the consumer’s perspective, would be to add first class support to the host language. That would end up feeling much more natural. (having language support for defining tables and foreign keys would be much easier to work with then all the crazy linq-to-sql attributes).
In reality, however, extending a programing language is too cost prohibitive for most developers. The benefits just don’t out weigh the costs.
Perhaps someday C# will have meta-programing features, which will make doing that kind of thing easy.
At the moment, however, that capability does not exist.
This leaves you with 3 options:
Usually #1 ends up being the easiest choice to make, even if it isn’t ideal.