Comment moderation enabled

Posted by

I've upgraded to an even newer version of b2evolution today. This version has a comment moderation feature, which I've turned on. So if you post a comment, it might take a while to show up (especially when I'm sleeping!)

But this should free me from all the comment spammers. The bastards.

C# constructors with both a this() and a base()

Posted by

Let’s say I have the following, rather simple, class hierarchy:


class FooBase
{
    public FooBase(int a)
    {
        Console.WriteLine("FooBase({0})", a);
    }
}

class MyFoo
{
    public MyFoo(int a, string s)
    {
        Console.WriteLine("MyFoo({0}, \"{1}\"", a, s);
    }
}

Now, let’s say I’m adding a new constructor to MyFoo. You can use the following syntax to call another constructor with different parameters on your own type:


MyFoo()
    : this(10, "something else")
{
    Console.WriteLine("MyFoo()");
}

In this case, the output after constructing with this constructor would be:

MyFoo(10, "something else")
MyFoo()

You can also use the following syntax to call a base class’s constructor:


MyFoo()
  : base(10)
{
    Console.WriteLine("MyFoo()");
}

And in this case, the output after constructing with this constructor would be:

FooBase(10)
MyFoo()

So why can’t you call both, like so (for example):


MyFoo()
    : base(10), this(15, "something else")
{
    Console.WriteLine("MyFoo()");
}

? In this case, I would expect the base class’s constructor to run first, MyFoo(int, string) next, and then the body of the current constructor to run third, giving the following output:

FooBase(10)
MyFoo(15, "something else")
MyFoo()

I can’t think of any reason for why that wouldn’t be allowed. Perhaps you can do it, and I just don’t know the syntax, but when you look at articles in this topic (for example, this one on MSDN) it just lists the first two that I mentioned, without any mention of whether you can (or how to, or why you can’t) combine them.

The problem with NOT using ClearType

Posted by

While some teams over at Microsoft seem to think ClearType is so good that it deserves to be turned regardless of whether the user actually wanted it on, it seems that others don’t even have it turned on themselves.

Because if the Visual Studio team had ClearType turned on, they’d know that you always have to clear the background before you repaint your control.

Take a look at the “Start” page in Visual Studio 2005:

Part of the Visual Studio “Start” page

If I click on the “Recent Projects” text, it becomes this:

Part of the Visual Studio “Start” page

I did a “difference” of the two images (and, admittedly, I ramped the difference up a bit to make it more obvious), and got this:

Difference between the two above images

So they’re obviously repainting the text without first clearing the background, and ClearType is writing it’s anti-aliased pixels twice. Yucky!

More on Visual Studio and Ligatures

Posted by

It seems I got a reply to my bug report on ligatures in Visual Studio. Not really what I was hoping for, but not entirely unexpected, I guess:

Hi, thank you for reporting this issue. We do realise that some fonts are not optimal for code editing, so while this is a problem, this is not something we are able to address.

Thank you,
Prasadi de Silva
VS Program Manager

I would say “not entirely unexpected” because it’s true: some fonts really aren’t appropriate for coding (some have even gone so far as to say that using Calibri is a violation of some natural law :))

So I guess I’ll just have to live with it (or choose a font which doesn’t contain ligatures). But it say that it “is not something we are able to fix” is wrong, it’s not impossible to fix, but maybe it’s just not worth it.

The problem with hindsight

Posted by

I was just doing some browsing today, and I ran across an article in the 1996 Microsoft Systems Journal Archives, basically the question asked was:

In order for us to get the "Designed for Windows® 95" logo, we must supply an application that uninstalls our software from the user's machine. We have developed an application called UNSETUP.EXE. But how can we make UNSETUP.EXE delete itself?

Which is a fair enough question back then (remember, there was no such thing as Windows Installer!) The problem is the answer that was given is just horrendous! Basically, the author went through various attempts at trying to delete the “UNSETUP.EXE” program while it was still running.

I won’t go through all of them, but at one point, he was calling FreeLibrary on the executable’s HINSTANCE handle in an endless loop, to see if he could force it to close. The reason is pure brilliance: you see, calling FreeLibrary on the executable’s HINSTANCE actually worked in Windows 95 (he tried it already) – it cause the module to be unloaded, but as soon as that happened, the program crashed. Well, he figured out that he could just inject the code from the module directly into the process’s address-space and then unload it. But it didn’t work on Windows NT because Windows NT didn’t let you call FreeLibrary on the main executable (or it just kept returning TRUE). So he figured maybe Windows NT just sets the reference count really high, and by calling FreeLibrary in a loop, it might cause the reference count to go down to zero eventually.

Luckily it didn’t work and he had to come up with a different method.

He eventually came up with the idea of spawning off a batch file which simply deleted the UNSETUP.EXE and the deleted itself (batch files can do that). This worked, but it only worked because of one of the most annoying features in ever - that is, if you try to delete a locked file, Windows will wait a couple of seconds and try again. So that’s why if you try to delete a file in explorer that’s locked, it takes a couple of seconds for the error message to come up. It’s only a couple of seconds, but by god it’s the most annoying couple of seconds in my day!

And the reason that “feature” is there is exactly because of this kind of hack! People would try to delete files from a scripting language, and they never bother to include retry logic. So the behaviour they see is that “I try to delete it from a batch file and it doesn’t work, but if I delete it from explorer once the batch file exits, then it works – batch files are broken!”

So the behaviour was made into what we see today. Of course, what should have happened is that explorer should have given an error straight away, and the batch files should have tried again – different interface, different behaviour. I have Vista installed, but I can’t be bothered trying to figure out if it’s been “fixed”... I hope so :)

Anyway, to Raymond, I just want to say – I feel your pain! I can’t imagine how hard it must be trying to improve Windows in the face of this kind of “advice.” Mind you, I also think Microsoft would be doing the software-development world a big, big favour if they took these crappy article off the web.

By the way, how would I have done it? Well, I would have gone with his original idea of using MoveFileEx. But I guess nowadays having a few files around waiting to be deleted on the next reboot isn’t as big a problem as it was back when hard drives were only 50MB big. (Also, I would have changed the behaviour slightly: I would copy the UNSETUP.EXE to the user’s temporary folder first – that way the UNSETUP.EXE in the temp folder can delete the whole hierarchy, and if the user cleaned up the temp folder before the reboot anyway, then so much the better).

Now the problem with hindsight is that it’s 20-20 – today the “proper” solution is almost obvious. Back then it might not have been. And I’m sure if the original author were to come back to that article today, he’d be just as embarrassed as I would be to read it.