Is C# a strongly typed or a weakly typed language?

Presented as a dialogue, as is my wont! Is C# a strongly typed or a weakly typed language? Yes. That is unhelpful. I don’t doubt it. Interestingly, if you rephrased the question as an “and” question, the answer would be the same. What? You mean, is C# a strongly typed and a weakly typed language?…


Foolish consistency is foolish

Once again today’s posting is presented as a dialogue, as is my wont. Why is var sometimes required on an implicitly-typed local variable and sometimes illegal on an implicitly typed local variable? That’s a good question but can you make it more precise? Start by listing the situations in which an implicitly-typed local variable either…


What would Feynman do?

No one I know at Microsoft asks those godawful “lateral-thinking puzzle” interview questions anymore. Maybe someone still does, I don’t know. But rumour has it that a lot of companies are still following the Microsoft lead from the 1990s in their interviews. In that tradition, I present a sequel to Keith Michaels’ 2003 exercise in…


Ambiguous Optional Parentheses, Part One

(This is part one of a three-part series on C# language design issues involving elided parentheses in constructor calls. Part two is here.) Another amusing question from StackOverflow, which I present here as a dialogue, as is my wont: In C# 3.0 the object initializer (and collection initializer) syntax permits both new Foo { Bar…


Don’t repeat yourself; consts are already static

Today, another entertaining question from StackOverflow. Presented again as a dialogue, as is my wont. The specification says “even though constants are considered static members, a constant-declaration neither requires nor allows a static modifier.” Why was the decision made to not force constants to use the static modifier if they are considered static? Let’s grant…


What’s the difference between a destructor and a finalizer?

Today, another dialogue, and another episode of my ongoing series “what’s the difference?” What’s the difference, if any, between a “destructor” and a “finalizer”? Both are mechanisms for cleaning up a resource when it is no longer in use. When I was asked this, at first I didn’t think there was a difference. But some…


Simple names are not so simple, Part Two, plus, volcanoes and fried foods

I’ve returned from a brief vacation, visiting friends on the island of Maui. I’d never been to that part of the world before. Turns out, it’s a small island in the middle of the Pacific Ocean, entirely made out of volcanoes. Weird! But delightful. The most impressive thing about the Hawaiian Islands for me was just how obvious were…


As Timeless As Infinity

User: Recently I found out about a peculiar behaviour concerning division by zero in floating point numbers in C#. It does not throw an exception, as with integer division, but rather returns an “infinity”. Why is that? Eric: As I’ve often said, “why” questions are difficult for me to answer. My first attempt at an answer to…


What’s the difference between conditional compilation and the conditional attribute?

User: Why does this program not compile correctly in the release build? class Program { #if DEBUG     static int testCounter = 0; #endif     static void Main(string[] args)     {         SomeTestMethod(testCounter++);     }     [Conditional(“DEBUG”)]     static void SomeTestMethod(int t) { } } Eric: This fails to compile in the retail build because testCounter cannot…


The correct answer is "no"

No technology today. I have not done a post on relationship advice in ages! Compare and contrast these two conversations: ****** Version One: Alice: Thanks for having lunch with me. I suppose you know what I want to talk about. Eric: Yeah, I do. I think you shouldn’t jump to conclusions solely on the basis…