Tag Archives: Joel Spolsky

Replace the Replace

I grabbed this screenshot during an online conversation about some of the more bizarre coding people have seen that came about as a result of the ongoing nasty surprises Phil Winstanley (@plip) keeps turning up in his current work.

Replace the ReplaceThis picture however shows some code that used to be in one of our systems, but was swiftly coded out when we found it. It was written by a contractor who amongst other things claimed to have worked with Microsoft writing parts of the .Net Framework.

Looking at this, if you’re a .Net Framework user you’d be forgiven for thinking that he didn’t have anything to do with the string classes, however one of his other regular complaints was how inefficient parts of the .Net Framework were, hence why he needed to spend time rewriting stuff that was already there! We could find no evidence to indicate that this function was any faster than the built in string.Replace, and since having this was a confusion and maintenance overhead it was removed.

Aside from the function being unnecessary there are a couple of other things I wouldn’t do. First up is the use of “” rather than string.Empty – Brad Abrams explains why on this short blog post. Secondly the whole routine uses systems Hungarian notation which is explicitly discouraged by the Microsoft naming conventions – ironic as it was their programmers that created systems Hungarian notation in the first place. Joel Spolsky (@spolsky) has an excellent blog post here that amongst other things discusses Hungarian notation. The third thing, which is more a matter of my personal taste is that there is a single line if statement which I would usually surround with {}, partly to make it clear, and also to help with maintenance – I’ve come across one or two difficult to spot bugs caused by missing braces, so I tend to think it’s better to use them all the time.

Spot the Difference

Safari/Firefox Compare

The announcement of a Windows version of Safari, the default browser under MacOS X has provoked a good deal of discussion.

Personally I’m of the opinion that it’s existence is primarily about providing a platform for iPhone development on Windows – very much that they need a platform, rather than any deep seated belief that the Windows platform needs another browser.

From my point of view that is made even more clear by the lengths to which Apple have gone to make it look and operate exactly like the MacOS X version, even down to the look of the buttons and scroll bars.

The identical behaviour even extends to how the browser renders fonts and graphics. If you take a look at the picture above, this shows the blog open in Firefox and Safari on Windows. Looking at the fonts, you’ll notice that the text looks subtly different – some people regard it as more blurry – this is because the browser is eschewing the usual Windows Cleartype in favour of the algorithm used by MacOS X. In theory, the MacOS X algorithm is intended to produce fonts that are as close to the original typeface design as possible, whilst Cleartype fits to the pixel grid – better screen wise – at the expense of accurately rendering the typeface. Coding Horror has a good article explaining the differences – ultimately it comes down to personal taste.

The other thing to note from the screen shot is the differences in the colour of the sunset picture at the top of the page. This is because Safari on Windows also treats graphics containing embedded colour space information differently. The sunset picture on the top of the page contains the colour space information from the original picture I took – Safari finds this and renders the graphic differently (although not necessarily correctly – ironically only the now defunct Mac Internet Explorer correctly interpreted colour spaces) resulting in the more vibrant orange hues that can be seen in Safari.

All of these duplicate features make it clear that alongside converting Safari, large amounts of MacOS X have been ported too to make it all work! Hence if you compare the memory usage of Safari with other browsers on Windows you’ll find it’s using a lot more than anything else…

Finally, one irony of Safari on Windows though is that whilst I don’t tend to use the browser much on MacOS X – preferring Firefox, I’m using Safari on Windows quite a lot because the text looks way better on the machine at work…

Update: The Safari on Windows debate rolls onward. With the news that the browser has been downloaded over one million times in the forty-eight hours since release, there is an interesting article from a Microsoft employee who initially is bemoaning the fact that Safari does everything itself, and then having read a posting by Joel Spolsky and the Coding Horror posting I mentioned above realises that it is unlikely that things will change!

The Spolsky posting is a good read in terms of the history – the Apple philosophy is very much about wanting to make fonts look as close to the printed original as possible – Joel explains in more detail why this is important to the desktop publishing and design communities. Choice quote of the posting has to be this:

“Typically, Apple chose the stylish route, putting art above practicality, because Steve Jobs has taste, while Microsoft chose the comfortable route, the measurably pragmatic way of doing things that completely lacks in panache.”

He also gives some opinions which go to explain why I’m preferring Safari on Windows – which are as much to do with familiarity as anything else!