out varfeature.Since writing that post, the leakage rules have changed, so I thought it time to revisit the topic.
out varfeature works. And suddenly that all changed. This minor feature has become a significant change to the language. And many people aren’t at all happy about it.
Continue reading “Why declarative programming is often better than imperative, even in C#”
Continue reading “Arnolyzer: adding clean-code static analysis to C# in VS2015”
ISomeInterface<T>, to be passed in, either via method parameters or through property setters (though good code will not contain the latter, of course). It’s perhaps no surprise that covariance is the opposite. Only when
ISomeInterface<T>allows instances of
Tto be passed out (either via method returns, or property getters), can that interface be covariant.
Continue reading “Generic variance in C#, part 3 — Covariance”
This is part 2 of a three part series on generic variance in C#. Part 1, covers invariance. The final part, covers covariance.
Continue reading “Generic variance in C#, part 2 — Contravariance”
The second part of this series, looks at what is probably the least well understood of the three terms: contravariance. If you feel you understand the other two terms, feel free to jump straight to that part therefore. The third, and last, part, looks at covariance and finishes with a summary of the difference between the three. But first, we start at the beginning: invariance.
Continue reading “Generic variance in C#, part 1 — Invariance”
IEnumerable<T>interface has numerous extension methods associated with it, including a number that return a single element if a match occurs, or return the default value for the type if that fails:
ElementAtOrDefault. These methods create two code smells due to the nature of .NET’s type system. As of version 1.5.0, Succinc<T> offers alternatives to these methods that overcome those smells.
Continue reading “Using Succinc<T> to overcome IEnumerable code smells”
One of the reasons cited for why it’s only a code smell is due to edge cases where a service locator can be used internally within an assembly as an implementation detail that doesn’t affect testing. It’s natural to ask what such a test-friendly service locator might look like. The Visual Studio/MSBuild and .NET framework combination supplies such a locator:
.resx files and the
Continue reading “An example of a benign Service Locator”
- You are still happily using inheritance,
if/elsecollections, have methods that are hundreds of lines long etc. You possibly haven’t heard of TDD or DI. There’s a very good chance that, if this is the case, you’ll likely never see this post as you likely do not read blogs by other developers.
- You do read around, you are aware of why inheritance,
switch, deeply nested and long code blocks are frowned upon by the well-informed. You are at least aware of TDD, even if you haven’t quite started using it yet. Also, you are likely aware of the growing excitement around functional languages and perhaps look on with envy at some of their features. If this is you, you possibly already use SHOF’s without knowing it.