The void is invariant

[UPDATES below]  A while back I described a kind of variance that we’ve supported since C# 2.0. When assigning a method group to a delegate type, such that both the selected method and the delegate target agree that their return type is a reference type, then the conversion is allowed to be covariant. That is,…

21

Iterators at the Summer Games

Ed “Scripting Guy” Wilson was kind enough to ask me to be a guest commentator at this years Summer Scripting Games, which have just completed. I’ve been working on a series for this blog about some unusual cases in the design of the “iterator block” feature in C# 2.0; this bit from my commentary is…

14

It Already Is A Scripting Language

My recent post about the possibility of considering maybe someday perhaps adding “top level” methods to C# in order to better enable “scripty” scenarios generated a surprising amount of immediate emphatic pushback. Check out the comments to see what I mean. Two things immediately come to mind. First off, the suggestion made by a significant…

51

Why Doesn't C# Implement "Top Level" Methods?

C# requires that every method be in some class, even if it is a static method in a static class in the global namespace. Other languages allow “top level” functions. A recent stackoverflow post asks why that is. I am asked “why doesn’t C# implement feature X?” all the time. The answer is always the…

58

Bug Psychology

Fixing bugs is hard. For the purposes of this posting, I’m talking about those really “crisp” bugs — those flaws which are entirely due to a failure on the developer’s part to correctly implement some mechanistic calculation or ensure some postcondition is met. I’m not talking about oops, we just found out that the product…

30

A Book By Any Other Name Would Smell As Sweet

As you might have gathered from my previous posts on the subject, I occasionally edit technical books as a hobby. It’s nice having a hobby that pays money instead of costing money. And I always learn something from every book. Many years ago, on one of my first editing gigs, the editor asked me my…

10

Human sacrifice, dogs and cats living together, mass hysteria! and thread model errors!

Reader Shaka comments on my post about error messages that “catastrophic failure” really does take the cake as being a terrible error message. I fondly remember the first time I saw “catastrophic failure” as an error message. I was an intern, running the build lab for Visual Basic for Applications, and I was trying to…

1

Checking For Script Syntax Errors, This Time With Code

A number of people asked me to clarify yesterday’s entry. Rather than try to talk you through it, I think the code is straightforward enough to speak for itself. Here’s a little skeleton that I just whipped up. #include <stdio.h>#include <activscp.h>#include <new> const GUID CLSID_VBScript = {0xb54f3741, 0x5b07, 0x11cf, {0xa4, 0xb0, 0x00, 0xaa, 0x00, 0x4a, 0x55, 0xe8}};const…

9

Checking For Script Syntax Errors

A reader asked me recently whether there was a way to check a chunk of JScript or VBScript for syntax errors without actually running the code. I’m sure that there are many third-party tools which you could find that do this. If you have your own script host, you can do it yourself quite easily….

8

Local variables considered not very harmful

Like I said, that code from last time was just test code, not real production code. Though clearly it works, I’d never write code like that in a million years. I’m not thrilled with the way it uses the answer variable of the outer scope as an accumulator, and it is profoundly weird that the “do…

6