Precision and accuracy of DateTime

The DateTime struct represents dates as a 64 bit number that measures the number of “ticks” since a particular start date. Ten million ticks equals one second. That’s a quite high degree of precision. You can represent dates and times to sub-microsecond accuracy with a DateTime, which is typically more precision than you need. Not…


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…


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…


Reading Code Over the Telephone

In my youth I once attended a lecture given by Brian Kernighan on the subject of code quality, which was very influential on my attitudes towards writing legible code. One of the things that Kernighan recommended was to endeavour write code that was so clear that it could be easily read over the phone and…


Do Not Call IsBadFooPtr, Indeed

Here’s a story that I said a long time ago that I was going to tell you all, and then promptly forgot about it. Raymond Chen’s blog entry today reminded me of it, because this is the story of how I found out the hard way that IsBadFooPtr is bad, bad, bad. Those of you…


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…


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….


Implementing Event Handling, Part Two

It’s been an insanely busy month for me, between having multiple out-of-town guests, throwing a party for the people who couldn’t make it to the wedding, and oh yeah, getting up to speed on the C# compiler and trying to understand the implications that LINQ features are going to have on the current implementation.  Not…


250% of what, exactly?

I just got a question this morning about how to take two collections of items and determine how many of those items had the same name. The user had written this straightforward but extremely slow VBScript algorithm: For Each Frog In Frogs  For Each Toad In Toads    If Frog.Name = Toad.Name Then      SameName = SameName +…


VBScript Default Property Semantics

Here’s a question I recently got about VBScript, where by “recently” I mean August 28th, 2003. This code works just fine: Set myObject = CreateObject(“myObject”)myObject.myName = “Eric” WScript.Echo myObject ‘ myName is the default property, so prints “Eric” But myObject = “Robert” doesn’t set the default property, it sets the variable to the string. Why does…