4 ms·
People abuse Linq a lot though; enormously complex queries over very large datasets without really knowing what you are doing. When people need .Each, some will
by tluyben2 8y ago
People abuse Linq a lot though; enormously complex queries over very large datasets without really knowing what you are doing. When people need .Each, some will just do .ToList().Each(. Etc. I found a bigger issue even with abuse/overuse) (or use at all really) of dynamic. I wish there was a way of to ban it at compile time.
- jenscow 8y agoI will challenge every use of dynamic (and var, for that matter), unless it's used in the very few appropriate cases.
- reubenbond 8y ago`var` is entirely syntactic sugar (compile-time type inference) and there's no runtime cost associated with it. I find it makes most (but not all) code more readable, particularly given that we have great IDEs/tooling in the .NET world.
- ralphael 8y agoI agree, by using var you need to name your variable better therefore making your code more readable. Rather than relying on the interface/class definition to explain to someone why you used "obj".
- quickthrower2 8y agoTo var or not to var is purely a "tabs 'n' spaces" debate, but doesn't affect performance.
- jenscow 8y agoIt will affect the performance of someone trying to read your code.
- goto11 8y agoPeople are still afraid of `var`?
- manigandham 8y agoWhat's wrong with any "use at all" of dynamic? It's just another type like object that has runtime reflection built-in and works well for interop, and without much performance problems.
- gameswithgo 8y ago>without much performance problems. Just depends on the kind of thing you are working on. For many people you could use dynamic all over, no problem. For many people that would be a disaster. (super high throughput server, things that need super low latency, games, rendering, libraries that could be used in any of those domains)
- joshschreuder 8y agoFrom personal experience it also gets abused by people looking for ways to shortcut writing actual classes
- tluyben2 8y agoExactly: I am usually writing backends for financial systems which need high throughput and low latency; dynamic is just a massive performance hit. And almost never needed; people usually use it because lazy in my experience. It is just ‘faster’ for people to dump JSON into dynamic and write against that than it is to properly create structured classes. In the end ofcourse the unittests validate the JSON, the code is slow and harder to use and refactor; you would have saved time and stress actually just writing classes with proper typing.