4 ms·
I feel the same way. Too many corner cases, not many I deal with very often. So far null propagation seems like the most useful feature for cleaning up clutte
by gambler 13y ago
I feel the same way. Too many corner cases, not many I deal with very often.
So far null propagation seems like the most useful feature for cleaning up cluttered code I'm used to dealing with.
Auto-property initializers are nice, but the syntax looks a bit ugly and I don't see them making that big of a difference in readability. I would rather see something that tackles the ugly-but-necessary construct I see the most: lazy-loading getters. Generic memorization of methods and properties would be even more useful. And yet even more useful would be something that could be used for both memoization and transparent caching:
[Cache(For = 1000 /*milliseconds*/)]
public GetSomethingFromDB(){ ... }
That would be tough to implement well, though. Unless they added Python-like attributes. Which would give us memoization, caching an a myriad other things.
- Yrlec 13y agoYou might find these two links interesting: http://stackoverflow.com/questions/3180685/how-can-i-make-method-signature-caching/3180764#3180764 http://stackoverflow.com/questions/3180685/how-can-i-make-me... https://bitbucket.org/Yrlec/funccache https://bitbucket.org/Yrlec/funccache The first one is an answer I wrote on SO and the other is a library I wrote a couple of years ago. Both are are different solutions to the caching problem you describe.
- bruceboughton 13y agoLazy<T> is quite useful for lazy-loading/memoization.
- lukasLansky 13y ago... and writing your own Lazy<T> with time- or otherwise-limited cache validity is not a problem, also.
- gambler 13y agoYes, but cleaner syntax for it would be nice. Right now it looks quite messy: private Lazy<string> _someVariable =new Lazy<string>(SomeClass.IOnlyWantToCallYouOnce); public string SomeVariable { get { return _someVariable.Value; } } Imagine the same things with a long lambda inside.
- sebastienros 13y agoTo answer this, the nice thing with Roslyn that is not explain in this blog is that it's also an API that you can extend with plugins. You project can contains them and they will have access to the AST at compile time, altering the compiled logic. So in your example you could create one to detect your attribute and inject custom logic instead. You can unleash the full power of AOP at the compilation level.
- gambler 13y agoI'll probably try that, but I'm worried about maintainability of such solutions.