Where to draw the line between attributes and XML.

It's not the first time that I have that feeling after long code review that programmers don’t know where to draw the line between using attributes as declaratives or using XML and interfaces to achieve the same goal. While it's true that attributes are more clean way to declare your intension about certain class then using virtual classes or interface it's not always the right choice. I didn’t see it often but I saw programmers using attributes in places where interfaces is needed due to the need to implement interface by declaring class. What I've seen often is using of attributes where XML are more suitable. Well maybe its just point of view, and anyone got its own, but I see clear line between them. Attributes should be use just for declarative purpose of the programmer (I want logging or auditing in that function please).  XML should be use for sys admin usage like setting logging on/off for a given system. Moreover, XML setting should override attributes setting if they clash.

 

Well that's my point of view I'd like to hear others …

2 Comments

  • I very agree that .net developers are sometimes guilty of thinking that attributes are cool and should be used whenever possible. For instance, they don't seem appropriate for persistence mappings, since mappings may change due to external changes, and yet many O/R mapping vendors require attributes. Their main arguments tend to be attributes are better than xml and proper design should not allow changes to external databases.

  • In my view, the only things that should sit in xml files are settings that can and might be changed without the need of re-compiling the system.



    I use attributes only when an 'external' tools has to 'understand' something about my class, member, etc., regardless of where it would be.



    I don't really understand what you're talking about with interfaces, but if you mean to say that you declare a class as supporting something, I say you can't go in without considering it first. Interfaces might require you to write code. This is not neccesarily big. If we're talking about an empty interface, I'd just rather use an attribute.

Comments have been disabled for this content.