In the previous exciting episode I ended on a cliffhanger; why did I put a loop around each wait? In the consumer, for example, I said:
It seems like I could replace that “while” with an “if”. Let’s consider some scenarios. I’ll consider just the scenario for the loop in the consumer, but of course similar scenarios apply mutatis mutandis for the producer. Continue reading
Locks are tricky; I thought today I’d talk a bit about some of the pitfalls of locking that you might not have seen before. Continue reading
One of the early stumbling blocks people run into when learning traditional Aristotelian logic is the idea that “a false proposition implies any proposition”. Let’s briefly review material implication, and then I’ll talk about what the implications of material implication are to programming.
UPDATE: A commenter points out that today is the 200th anniversary of the birth of George Boole; I had no idea when I scheduled this article that it would be so apropos. Happy birthday George Boole!
Here’s a little-known and seldom-used fact about C# operators: you can apply the
| operators to
bools, not just to integers. The
| operators on
bools differ from
|| in only one way: both operators always “eagerly” evaluate both operands. This is in marked contrast to the “lazily” computed evaluation of the
|| operators, which only evaluate their right hand argument if needed. Why on earth would you ever want to evaluate the right hand side if you didn’t need to? Why have this operation at all on
A few reasons come to mind. First, sometimes you want to do two operations, and know whether both of them succeeded: Continue reading
A question I occasionally get is, suppose I have code like this:
const double x = 200.0;
const double y = 0.5;
void M(double z)
double r = z * x * y;
Does the compiler generate code as though you’d written
z * 100.0?
In part one I gave a bunch of reasons to reject the proposed feature where the compiler infers additional type information about a local variable when inside the consequence of a conditional statement:
if (animal is Dog)
// instead of ((Dog)animal).Bark();
But the problem still remains that this is a fairly common pattern, and that it seems weird that the compiler cannot make the necessary inference.
A number of readers anticipated my denouement and made some of the same proposals I was going to make in this part. Let’s go through a few of them; see the comments to the previous article for a few more.
I am excited to announce that Essential C# 6.0 is now available in stores!
As always, Mark did the vast majority of the work. And as always, I was delighted to be asked once again to contribute to one of my favourite C# books. The title is well-chosen; it really does give the essentials.
Mark and I are both cyclists (though he is in a lot better shape than I am!) and so I also love that every edition has gotten more and more bicycle on the cover: