out var
feature.Since writing that post, the leakage rules have changed, so I thought it time to revisit the topic.
Continue reading “C# 7, “out var” and changing variable scope, revisited”
out var
feature.Since writing that post, the leakage rules have changed, so I thought it time to revisit the topic.
Continue reading “C# 7, “out var” and changing variable scope, revisited”
Continue reading “Using C# 7 and Succinc<T> to give F# a run for its money”
out var
feature 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 “C# 7, “out var” and changing variable scope”
T
, for 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 T
to be passed out (either via method returns, or property getters), can that interface be covariant.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: FirstOrDefault
, LastOrDefault
, SingleOrDefault
and 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.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 ResourceManager
class.
Continue reading “An example of a benign Service Locator”
switch
statements, nested if/else
collections, 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.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.Continue reading “Do you SHOF? Higher order functions in OO languages”