Hacker News new | ask | show | jobs
by rkagerer 9 days ago
I used attributes for a serialization framework (long ago before any good ones existed for C#) and found they were exactly what I needed. The solution was easy to understand and reason about, consistent, even somewhat elegant (and I use that adjective cautiously as I've seen lots of code that was "elegant" but fragile). I agree with your forewarnings, but there are absolutely instances where it's the right tool for the job.
1 comments

Yes, and the attributes that TFA whines about are what make NUnit very powerful. [Values] on an enum argument creates useful tests.

That being said, when I started my current job I replaced some complicated reflection-based code with a dictionary of delegates. I also turbocharged a an ASP (.net 4.x) app's startup time by explicitly referencing each controller in startup code.

It seems you didn't read the article. It's not whining about how people use or write custom attributes. It's whining about how they're implemented in the language.

And I wouldn't really describe it as whining, I thought it was an interesting article that rases valid points and suggests a solution.

The 2nd half of the article is an explanation of the problem of reading enums referenced in attributes, specifically about how it impedes performance, which I am directly discussing, both in this thread and https://news.ycombinator.com/item?id=48373294

Seems you didn't read the article!

The author is saying the .NET devs did a bad job implementing that, they are not saying you shouldn't use it. So you talking about using attributes is irrelevant to the article, it has nothing to do with developers using attributes nor how they do so.