You are viewing a single thread.
View all comments View context
4 points
Deleted by creator
permalink
report
parent
reply
16 points

Your assumption that “using reflection means the code is wrong” seems a bit extreme, at least in .Net. Every time you interact with types, you use reflection. Xml and Json serialization/deserialization uses reflection, and also Entity Framework. If you use mocking in test you are using reflection.

We have an excel export functionality on our sites that uses reflection because we can write 1 function and export any types we want, thanks to reflection.

permalink
report
parent
reply
3 points
Deleted by creator
permalink
report
parent
reply

A good sense of “code smell” is one of the most valuable programming skills. I think your “probably” is justified: if you’re doing X, you should look twice at how you’re doing it. Maybe it’s right, but usually it’s not, so it’s worth a pause and a thought.

permalink
report
parent
reply
2 points

Modern .NET is reducing dependence on reflection. System.Text.JSON and other core libraries have leveraged source generation to produce AOT + trim friendly, reflection free code. But yeah, it’s not a taboo like say dynamic, it’s perfectly normal to use reflection in idiomatic C# code.

permalink
report
parent
reply
5 points

Hm, I’m currently working on a project with a ton of runtime-configurable plug-ins and dependencies between them. All of that is held together with a copious amount of black QMetaObject magic. I had the same thought about it, but I’m not sure how you’d get similar functionality without reflection and not making it even more convoluted and fragile…

permalink
report
parent
reply
3 points

Metaprogramming is extremely useful for long term code readability. What you’re doing is probably fine but we can’t really evaluate that without seeing the actual code.

permalink
report
parent
reply
2 points

That’s why I stopped writing code and started writing ASTs and AST transformers that can be configured to emit libraries.

permalink
report
parent
reply
1 point
Deleted by creator
permalink
report
parent
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 6.8K

    Monthly active users

  • 1.4K

    Posts

  • 32K

    Comments