Line Spacing

Posted by

I saw over on the fontblog a couple of posts about line spacing (namely “Typography Tip #3” and “More on Linespacing”).

Basically, they say you should try for 1.2x the font height for your line spacing. So I decided to update the CSS for my blog to match their recommendation. One thing I noticed, though, is that I had to actually set the line-height style to 1.4 instead of 1.2. Does anyone know why? I couldn’t find much in the way of documentation for the line-height style (at least, not much that I could understand...)

Here we go again with the ClearType stuff...

Posted by

First of all, I’m going to go on record as saying that I now have ClearType turned on on all of the computers I use (including ones hooked up to CRTs, which some people think doesn’t look good – and I would have agreed six months ago, until I tried the ClearType Tuning Wizard on it, which it fixed it right up).

Anyway, I noticed over on Michael’s blog a new post titled “Let Me Make One Thing Perfectly Clear[Type]” (too bad I’m not as good with the puns in my post titles!). It seems we’re not the only ones unhappy about various teams within Microsoft who believe they know better than their users about whether to turn ClearType on or off.

Particularly, this comment on the IE blog seems rather fishy to me.

Now, basically, he says that the original intention for ClearType was to be able to turn it on or off whenever appropriate, be it on a system-wide level, a per-application level or a per rendering-surface level even. And I think that’s a good thing (for reasons I’ll explain in a second)

The original blog post also says that people (in general) find ClearType easier to read than non-ClearType type:

We have solid, peer-reviewed empirical evidence showing that our users read more efficiently when ClearType is turned on. A couple of the findings have been described in our fontblog, including a 17% improvement in word recognition accuracy, and a simultaneous 5% improvement in reading speed with 2% improvement in reading comprehension. More studies are on the verge of publication, and will also be described in the fontblog.

I also think this is a good thing (and I believe their research – my own personal feeling is that I believe ClearType – especially on a high resolution LCD – is a lot easier to read than non-ClearType).

But to draw the conclusion that therefore you should turn ClearType on in IE regardless of the system-wide setting is totally incorrect.

Now, why do I think it’s a good idea that you can turn ClearType on/off on a per-surface level? Because there are plenty of applications where you don’t want ClearType, regardless of the setting. For example, if I’m rendering text to a texture in Direct3D, which I’ll then want to scale, rotate, etc in 3D, then I certainly wouldn’t want ClearType turned on. Also, if I’m capturing a screen shot for a web page (or something), then I’d also want it turned off (because I won’t know what my viewer’s LCD layout will look like, ClearType will be useless in an image)

But if ClearType really does make reading text easier, then there’s no reason to have it turned off in most applications and only have it on for certain applications (whether those applications are “reading-intensive” or not).

So my point still stands. If ClearType is such a huge benefit to reading comprehension (and I’m willing to believe that it is) then it should be turned on in the Operating System in a Service Pack, not on an application-by-application basis. It’s fine to turn it off on an application-by-application basis (for the reasons I listed above) but not to turn it on.

XmlSerializer and types you don’t know about

Posted by

I have a bit of a problem. I have a set of classes, let’s say it’s a parse tree for a simple language. The language is extensible, so I can add extra classes to it at runtime. Finally, I also want to be able serialize and deserialize the classes to XML.

What’s the problem? Well, to be able to serialize or deserialize the classes with the .NET XmlSerializer class, you need to know all the types involve to begin with. Now, for serialization, it’s not entirely impossible. For example, I can just do something like the following:


Node node = // this is the node we’re going to serialize...

List<Type> types = new List<Type>();
GetNodeTypes(types, node);

void GetNodeTypes(List<Type> types, Node node)
{
    if (!types.Contains(node.GetType()))
    {
        types.Add(node.GetType());
    }

    foreach (Node child in node.ChildNodes)
    {
        GetNodeTypes(types, child);
    }
}

Then I can pass the types.ToArray() array into the XmlSerializer constructor. But the hard part is, how do I do the same when trying to deserialize? I don’t know the types up-front, so I’m stuck, right?

Well, unfortunately, yes you pretty much are stuck. From this point on, I would consider all these methods to be ugly, ugly, hacks.

The first method I saw posted on Daniel Cazzulino’s blog, with the succinct title of “XML extensibility, xsi:type, XmlSerializer and configuration (or how to leverage XmlSerializer + OO extensibility)”. Basically, his version requires a “known” top-level class which contains a list of “child” classes, where we don’t know the types of those. I think this method is slightly ugly, because it requires that you modify the XML that is written to include a “type” parameter so that you know the types on input. Also, it requires a multi-pass approach, where you basically deserialize the constant stuff, then go through and parse out the stuff you didn’t know about before-hand (but looking at it’s “type” attribute).

Now, don’t get me wrong, for the situation he describes – that is, a “configuration” style file with pluggable “providers” – is good, as he says:

I believe this is a far more straightforward way of handling extensible configuration. Instead of implementing a sort of IProvider.Init(XmlNode config) feature, providers only need to care about the serialization format they want. I've seen that in many places in ASP.NET 2, providers receive some kind of NameValueCollection. This is clearly a step in the wrong direction. Complex configuration simply can't be handled by key-value pairs (or it's too ugly/cumbersome to do so).

But for me, it doesn’t really cut it. Now, what I decided to do is probably actually worse, at least from a design standpoint. It may seem like even more of a hack, and it is a hack. But like I said above, I don’t believe you can get around this problem without some sort hacking...

Basically, before I deserialize a document, I reflect all the types currently loaded into the AppDomain and pass all the types which inherit from by base class to the XmlSerializer constructor. For the sake of efficiency, I only reflect the types once, and I skip looking in the mscorlib assembly and any assemblies that start with the name “System”. To handle the case when a type might be loaded later, I add an event handler for the AppDomain.AssemblyLoaded event, and parse those assemblies the next time a deserialize needs to happen.

This does place a requirement on all my types that they have unique names, or that they specify unique names via an XmlElementAttribute but it works, and (once you’ve loaded the first document at least), it’s fairly fast. It also requires that all the types you’ll be loaded are already loaded into the current AppDomain. This one may or may not be a problem, depending on your own circumstances, but for me it’s not that big of a deal.

Change for the sake of Change

Posted by

I was reading Paul Thurrott’s excellect review of Windows Vista February 2006 CTP, and one quote which he made in Part 5: Where Vista Fails really stood out for me:

But what Media Center, like much of Windows Vista, does is punish people for being familiar with the previous interface. My family has been using Media Center for four years now. It's their TV interface, the only one they know. Now it's very different, confusing, and ugly to boot.

That’s surprisingly true of so many of Microsoft’s products. One example that is exceedingly obvious is when we moved from Visual Studio 6 to Visual Studio .NET (aka Visual Studio 2002). Pretty much all the keyboard shortcuts changed. It was no longer “F5” for build, it was “Ctrl+Shift+B” (why was such a common task given such an overly complex shortcut anyway?)

Another one, Enterprise Manager for SQL Server 2005 had “F5” for “run script” but in SQL Server 2005’s version of the same program, it’s “Ctrl+R”.

Now, I suppose they have to move some shortcuts around in order to make room for extra features and such, and you can still change the shortcuts if you really want. But if it were only shortcuts that seem to change to for no apparent reason, then I wouldn’t have much to complain about.

But it’s not just shortcuts that change. It’s the whole user interface which seems to go through arbitrary changes for no apparent reason. One of my favourite programs, in terms of UI and usability is (believe it or not) Office. Since Office first started, there have been relatively few changes in the base UI, so if you know Office 97, you can still find your way around Office 2003 without too much trouble. Now, they’ve pretty much hit the limit with how far they can take the Office UI – which is why the Office “12” UI is so different. But I don’t mind that. A radical redesign for the sake of feature discoverability is a good thing.

And the fact is, I know why the Office UI is changing. But the changes in the development tool’s user interfaces (and even in the Windows Shell, certainly in Vista anyway) mostly just seem like random changes for the sake of making the product look different.

Reports of my death are greatly exaggerated

Posted by

I haven’t died, but I have just moved house, and I’m still waiting to get the internet connected there, which is why the posts have somewhat dropped off.

One thing I would like to mention is that I’ve currently banned any comments or trackbacks from Blogspot, Google’s blogging service, after an enormous wave of comments pointing to splogs on that service. Something like 400 comments in the last week or so!

Anyway, I’m still planning to upgrade my version of b2evo (when I get the internet on at home, and I have a spare hour or two), and when I do that, I’ve noticed there is a nice hack for doing “moderated” comments, which I’ll do at the same time.