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

String interning and String.Empty

Here’s a curious program fragment: object obj = “Int32”;string str1 = “Int32”;string str2 = typeof(int).Name;Console.WriteLine(obj == str1); // trueConsole.WriteLine(str1 == str2); // trueConsole.WriteLine(obj == str2); // false !? Surely if A equals B, and B equals C, then A equals C; that’s the transitive property of equality. It appears to have been thoroughly violated here….

26

The Stack Is An Implementation Detail, Part One

I blogged a while back about how “references” are often described as “addresses” when describing the semantics of the C# memory model. Though that’s arguably correct, it’s also arguably an implementation detail rather than an important eternal truth. Another memory-model implementation detail I often see presented as a fact is “value types are allocated on…

36

Representation and Identity

(Note: not to be confused with Inheritance and Representation.) I get a fair number of questions about the C# cast operator. The most frequent question I get is: short sss = 123;object ooo = sss;            // Box the short.int iii = (int) sss;         // Perfectly legal.int jjj = (int) (short) ooo; // Perfectly legalint kkk…

26

Santalic tailfans, part two

As I have said before many times, there is only one sensible way to make a performant application. (As an aside: perfectly good word, performant, deal with it!) That is: Set meaningful, measurable, customer-focused goals. Write the code to be as clear and correct as possible. Carefully measure your performance against your goals. Did you…

36

A nasality talisman for the sultana analyst

The other day my charming wife Leah and I were playing Scrabble Brand Crossword Game (a registered trademark of Hasbro and Mattel) as is our wont. I went first, drawing the Q and a bunch of vowels. Knowing that the Q is death to hold onto, I immediately opened with QI for 22 points. I…

24

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

Trivial Projections Are (Usually) Optimized Away

OK, computers aren’t entirely dumb when it comes to LINQ. Here’s an example of a place where we’re a bit smarter. Consider the following query: IEnumerable<int> query = from n in number_array orderby n select n; Does this get transformed by the compiler into IEnumerable<int> query = number_array.OrderBy(n => n); or IEnumerable<int> query = number_array.OrderBy(n…

8

Computers are dumb

  A few short takes today, from questions I’ve received recently about LINQ in C# 3.0. The first question was “in the following code, does it really check every single non-negative integer, or does it use the knowledge that once you’re beyond ten, you can stop iterating?” var smallNumbers = Enumerable.Range(0, int.MaxValue).Where(n => n <…

13

Lambda Expressions vs. Anonymous Methods, Part Five

Last time I demonstrated that the compiler could have to do an exponential number of bindings in order to determine whether there was a unique best overload resolution for a function call that takes a lambda. Some of you may have wondered whether we simply were not being clever enough in the compiler. Perhaps there…

6