Hi! My name is Cédric Bozzi, I make websites and iOS apps, and this is my blog about technology (mostly a Twitter archive, really).

6 July 2004


Watch out for the technical point. It’s not even about the web, but Windows programming, so you can just skip it. Besides, considering my current sleeping cycles, I’m dead now, so this post will be particularly bad. And what I’m writing about isn’t even new anymore. That’s how interesting it is.

So, if you’re nosy, you can still click the icon and download the program, which isn’t of much use — it’s just a technical demo — but, well, I like to brag with my software. (Hoping it’ll work on other computers than mine. And, of course, since that’s the post’s topic, you need the .NET runtime.)

If you’re using Windows, and you like to play with new software once in a while, you certainly have already encountered some freeware thatrequired the .NET runtime. If you’ve got broadband, it isn’t much: you follow the link, click where you have to, or launch Windows Update, and it gets installed, and you trust it because it’s on the Microsoft website (mwahaha), and so there. But if you’re on dialup, and those still exists, it’s harder to considering downloading 20MB or Microsoft crap in order to get a 100KB shareware to load.

Because .NET has to be crap, hasn’t it? For starters, it has a ridiculous name, that makes you think it only has a few web connection and XML processing functions. And it’s very reminiscent of those Visual Basic DLLs that were way too big for their time (when many people were still on dialup) and existed in fifteen different versions. Basically, something for lazy, incompetent programmers, who can’t code for themselves. Right? Nope.

I got curious yesterday, or maybe I got bored, but I think both go together, and I finally downloaded the SDK, read the documentation, checked out what this thing has to bring, and I came to this unsettling conclusion: it’s good! (Oops, so much for suspense.) For context, I have to say that, when I went back to Windows programming two and a half years ago in order to make Ghrone, and I discovered Visual C++, I had been terribly disappointed: the MFCs (the object-oriented interface that allowed you to program for Windows in C++), now that was crap. Of course, maybe I expected too much from those, because two years earlier I had gotten into BeOS programming (object oriented from the start, incredibly simple to program for). But I’m just certain that at the time I was using Borland C++ (that’s in 1995-96, when I made a nice NeXTstep interface clone, at a time when cloning OSs wasn’t the big rage yet) classes were much better designed, code wasn’t as messy, and everything was much more simple and convenient.

I won’t get into (more) detail, because either you’re not interested or you already know about that: to synthesize, I’ll say that, between my past disappointment in Visual C++ and .NET’s ridiculous name, plus all the noise Microsoft had made around it for years before laying low with all commenters saying it was much ado about nothing, I really didn’t expect much.

Surprise! .NET is precisely everything the MFCs should have been for years: a real object-oriented layer, that finally masks all system calls and allows you to access the Windows system in a way that makes sense, and automatically manages all those little obvious things that required lots of silly code with the MFCs.

I decided to get into it when I found out (reading the MSDN blogs, and it’s a good thing I use an aggregator now, because otherwise they’re really not digest) that Microsoft offered a free Visual C++ compiler. In case you wanted to try it out, here’s a little spoiler: forget it. Programming for .NET in C++ is awful, because they’re visibly trying to respect the language’s standards and you have to type lots of macros and weird, heavy definitions, ending up with horrid code. Not to mention the fact that the documentation offers very scarce C++ samples — and that one is as much a cause as a consequence. Microsoft created C# specially for .NET (but Visual Basic also works, it’s just exactly the same language without the curly braces) and, contrary to what you may believe before you get into it, they didn’t just do it in order to own the place, it really has a point.

The big particularity of .NET as a programming environment, and the main reason why it’s unusable in C++, is managed memory: the .NET runtime includes a garbage collector (I think Java does too, right?). Now that I know how it works (I had never really looked into it, so it remained just some kind of magic to me), I’m not able to, not explain it to you, but confirm that it’s really important: you used to spend hours in the Windows documentation, trying to figure out when and how to allocate a string or a structure, and when and how to discard it. It was the same for everybody, not that I’m stupid, but just the APIs weren’t always quite coherent in this regard. The funny thing is, it seems to me that Borland C++, eight years ago, and without resorting to a garbage collector, managed to get rid of much of that trouble simply by shielding the programmer from the evil Windows APIs. But not Microsoft, no, they had to reinvent their OS and their programming language. Bah.

Anyway, this is quite nice, but it’s not the most spectacular. Being rid of pointers is a welcome rest, but the most impressive thing in .NET (and what’s most interesting to me) that GUI programming is now as simple as it can be. A few examples:

Button button1 = new Button();
button1.Click += new System.EventHandler(button1 Click);

There you go: the button is created and attached to the window, and clicks are processed, all in three lines. No constants to define so you can create events, no classes to inherit — you can perfectly program a small application without even having to create a class for the main window!

ListBox listBox1 = new ListBox();
listBox1.Size = new System.Drawing.Size(120, 173);
listBox1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
listBox1.Items.All = new object[] {“Item One”, “Item Two”, “Item Three”, “Item Four”};

Besides the list being filled in just one line, there’s something amazing in this snippet: thanks to Anchor, this lists will move and resize automatically when the user changes the window’s size. It’s apalling that we had to wait until .NET for this, but I’m so glad I don’t feel like complaining.

ContextMenu button1ContextMenu = new ContextMenu();
button1.ContextMenu = button1ContextMenu;

And now you have a context menu attached to a button (or to the main window, or to anything) in just two lines. And, of course, I edited some stuff out, but you can fill it up and define the event handling functions in just a few lines too. Crystal clear.

It’s now time to conclude this publicity operation (it’s all for free — you don’t think I’d accept money from Microsoft, do you?) with my little program of mine : in just a few hours of programming, in just a few pages of code, a program that displays an image (uh, yeah… but, seriously, it was so complicated before — particularly as it’s a JPEG, and at the time I made Ghrone I had to find a third-party library in order to read something other than BMP), downloads the blog’s RSS feed, displays it in an embedded Explorer, and opens the browser when you double-click a post.

Total time: eight hours. Including two hours trying to get a C++ .NET file to compile (I told you, forget it), one hour looking for the C# compiler that is indeed included for free with .NET (don’t know why it’s in the Windows directory instead of with the SDK), another hour to figure out how to include a damn icon in the program’s resources (I always had lots of trouble with Windows resources, don’t know why, I really find it poorly designed — and now it’s obviously worse when you work in command-line mode), one hour to launch the system browser when you double-click the list (I don’t know if it’s .NET, Firefox, or the anti-monopoly Windows Service Pack, but now you can’t just execute the URL, you have to get the browser’s location yourself in the registry) and one hour for the ActiveX control to launch the default browser too when you click a link.

Which means, in just two hours I could create my very first .NET C# program, displaying a picture at the top, managing a listbox, integrating a mini-browser, and processing an RSS feed. Two hours, and I was just discovering .NET with a far from optimal documentation (and on that level too, it seems to me that Borland documentation was better at the time).

As a result, I just have to get back to programming. Have to. I talked about it recently, but now I know it’s really possible: I cant to make an Exposé + Dashboard + Dock clone. Can be done. I only have to stay motivated long enough.


2001 01 02 03 04 05 06 07 08 09 10 11 12

2002 01 02 03 04 05 06 07 08 09 10 11 12

2003 01 02 03 04 05 06 07 08 09 10 11 12

2004 01 02 03 04 05 06 07 08 09 10 11 12

2005 01 02 03 04 05 06 07 08 09 10 11 12

2006 01 02 03 04 05 06 07 08 09 10 11 12

2007 01 02 03 04 05 06 07 08 09 10 11 12

2008 01 02 03 04 05 06 07 08 09 10 11 12

2009 01 02 03 04 05 06 07 08 09 10 11 12

2010 01 02 03 04 05 06 07 08 09 10 11 12

2011 01 02 03 04 05 06 07 08 09 10 11 12

2012 01 02 03 04 05 06 07 08 09 10 11 12

2013 01 02 03 04 05 06 07 08 09 10 11 12

2014 01 02 03 04 05 06 07 08 09 10 11 12

2015 01 02 03 04 05 06 07 08 09 10 11 12

2016 01 02 03 04 05 06 07 08 09 10 11 12

2017 01 02 03 04 05 06 07 08 09 10 11 12

2018 01 02 03 04 05 06 07 08 09 10 11 12

2019 01 02 03 04 05 06 07 08 09 10 11 12