Persistence, Facades and Roslyn’s Red-Green Trees

We decided early in the Roslyn design process that the primary data structure that developers would use when analyzing code via Roslyn is the syntax tree. And thus one of the hardest parts of the early Roslyn design was figuring out how we were going to implement syntax tree nodes, and what information they would…

23

Atomicity, volatility and immutability are different, part three

So what does “volatile” mean, anyway? Misinformation abounds on this subject. First off, so as to not bury the lead: in C# the rules have been carefully designed so that every volatile field read and write is also atomic. (Of course the converse does not follow; it is perfectly legal for an operation to be…

18

Atomicity, volatility and immutability are different, part one

I get a fair number of questions about atomicity, volatility, thread safety, immutability and the like; the questions illustrate a lot of confusion on these topics. Let’s take a step back and examine each of these ideas to see what the differences are between them. First off, what do we mean by “atomic”? From the…

23

Read-only and threadsafe are different

Here’s a common problem that we face in the compiler realm all the time: you want to make an efficient immutable lookup table for mapping names to “symbols”. This is in a sense the primary problem that the compiler has to solve; someone says “x = y + z;” and we have to figure out…

15

Graph Colouring With Simple Backtracking, Part Two

Before I begin a quick note: congratulations and best wishes to David Johnson, currently the president of my alma mater, the University of Waterloo. The Queen has appointed him to be the next Governor General of Canada come this October. For those of you unfamiliar with the Canadian political structure, Queen Elizabeth is the sovereign…

18

Graph Colouring With Simple Backtracking, Part One

As regular readers know, I’m interested in learning how to change my C# programming style to emphasize more concepts from functional programming, like use of immutable rather than mutable data structures and use of declarative control flow like LINQ queries instead of imperative control flow in the form of loops. I thought I’d solve a fairly…

23

Too much reuse

A recent user question: I have code that maintains a queue of pending work items waiting to be completed on various different worker threads. In certain unfortunate fatal error situations I complete each of these by throwing an exception. Can I create just one exception object? Are there any issues throwing the same exception object…

71

What is this thing you call "thread safe"?

Caveat: I am not an expert on multi-threading programming. In fact, I wouldn’t even say that I am competent at it. My whole career, I’ve needed to write code to spin up a secondary worker thread probably less than half a dozen times. So take everything I say on the subject with some skepticism. A…

30

Events and Races

Here’s a question similar to one I saw on stackoverflow the other day. Suppose you have an event: public event Action Foo; The standard pattern for firing this event is: Action temp = Foo;if (temp != null)      temp(); What the heck is up with that? Why not just call “Foo()” ? First off, this pattern…

30

Arrays considered somewhat harmful

I got a moral question from an author of programming language textbooks the other day requesting my opinions on whether or not beginner programmers should be taught how to use arrays. Rather than actually answer that question, I gave him a long list of my opinions about arrays, how I use arrays, how we expect arrays to be…

63