There is a definite gap between TAP Utilities Task.WaitAny and Task.WaitAll. How do we wait for the first 'N' tasks from an array of tasks. That is one utility that is missing from TAP's rich repository. It might not be hard to implement one by yourself though. The above code uses existing Task Collaborators Task.WaitAny … Continue reading WaitForFirstN Tasks Method
Month: March 2018
Why avoid Conversion Operators
No doubt that the Conversation Operators makes developers life easier by bring in a kind of substitutability, but it comes with a price. If not properly designed/used, it could result in subtle errors that can be easily ignored. Consider the following code. We have a class called Car, which exposes a single property - MakerName. We … Continue reading Why avoid Conversion Operators
Nominal Vs Structural Type System
Anonymous Types and Tuples might look very similar, but there is one significant difference which separates them. As always, nothing can be more explanatory than writing code. Consider the above code. What could be the output ? Are both false or are both true ? Interestingly, the output is as follows. Though syntactically similar, both … Continue reading Nominal Vs Structural Type System
Evil Code #006 : Build Configurations
This one is courtesy Wouter de Kort, from his famous book. Okay, so what's the evil code here. Consider the following code and predict the output in Debug as well as Release modes. Output of the code under different configurations Isn't that weird that the output has varied in Debug and Release modes ? Well, … Continue reading Evil Code #006 : Build Configurations
Design Patterns : State Pattern
State Pattern is share a lot of similarities with Strategy Pattern, but has its own fundamental differences as well. The State pattern allows to change the behavior of a method, depending on the state of an object, in other words it encapsulates the behavior dependent on the state (the What). This is different from the … Continue reading Design Patterns : State Pattern
Design Patterns : Null Object Pattern
Null Pattern is probably one of the most underestimated and often most ignored among the design Patterns., though it turns out to be one of the easiest to implement. The intend of the pattern is to ensure we won't end up with NullReference Exceptions, while avoiding the long list of repeated preconditions that checks of … Continue reading Design Patterns : Null Object Pattern
Evil Code #005 : Readonly Value Types
Time to review another of Evil Code Series and this time, we are dealing with read-only value types. Review the below code and predict the output. Strangely enough, the output is {3,2}. Yes, it means the Increment Method return a value of 3 for MyValue, but a follow-up statement to display MyValue explicitly, … Continue reading Evil Code #005 : Readonly Value Types
Benchmarking Span<T> Performance
Span<T> is yet another addition to C# 7.x and is particularly useful in developing memory intensive applications. So what is Span all about ? As Microsoft describes it, Span<T> is a new value Type which enables the representation of contiguous regions of arbitrary memory, regardless of whether the memory is associated with a managed … Continue reading Benchmarking Span<T> Performance
Ref Value Type
In an earlier post, we discussed the readability factor of the reference semantics, mentioning how it kind of makes the code less readable. However, that doesn't take away the big door of opportunities the new features add. Consider the following scenario. Now, prior to C# 7, this was difficult. There was no way we could … Continue reading Ref Value Type
Technical Debt Quadrant
In a practical corporate software development scenario, there are times when you have (willingly or otherwise) to give up to trade-offs and compromises especially when the deadlines looms over you or, in worst case, you are LAZY !!. You might be prompted to choose a less than optimal solution due to situational constraints, which might … Continue reading Technical Debt Quadrant