tag:blogger.com,1999:blog-74696822024-02-08T16:08:11.619+10:30Matt's MindMatthew Phillips' occasional blog for your time-wasting pleasure. Software development, technology, coffee brewing, farnarkling ... you name it, I'll comment on itMatthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.comBlogger45125tag:blogger.com,1999:blog-7469682.post-5963813656615946472011-03-26T00:32:00.008+10:302011-03-26T19:58:02.650+10:30Lisp take 2(This post has the dubious honour of being my first in 4 years. I had all sorts of grandiose ideas about moving this blog from blogger to something slightly more hip like posterous or my own hosting, but that would really have been such a waste of time. In the meantime, the planned move was a good excuse not to write anything. Further excuses like getting married and the birth of our daughter then presented themselves. What decided me to write again was re-reading some old articles and comments, and discovered some things I didn't even remember writing as well as some interesting comments - I realized I missed blogging.<br />
<br />
Just for added nerd points, this article was written on an iPad. Using the touch keyboard. Yes, I also, apparently, did not get the memo that <a href="http://daringfireball.net/linked/2010/06/01/thurrott-understanding">the iPad is only for consumption of content</a> [link is to John Gruber's teardown of that strange meme].)<br />
<br />
I recently re-read an article I wrote in 2007 about not being able to think in Lisp and worrying about what that meant to my development, or otherwise, as a programmer. Since then, I've resembled even more the developer's equivalent of a midlife crisis, and tried quite a few other languages, including Haskell, Scala, Groovy and, Brainfuck (just joking about that one but, frankly, I'm not convinced J or Forth, which I also had a look at, are that much different :) ).<br />
<br />
Recently I've started a new commercial project using Clojure for the server backend and Objective-C on iOS for the (iPhone) client. And I'd like to report that I actually believe I can now, finally, think in Clojure, i.e. Lisp. Yay. It surprises and elates me to no end as it turns out.<br />
<br />
What's more, writing significant software in Objective-C has given me an excellent basis of productivity comparison with Lisp and, I have to say, the Lisp code is so much more information dense,* it's a little scary. Partly so because I'm worried that means it's a write-only language from the point of view of anyone else. And also partly because I may not want to go back to OO Java land again.<br />
<br />
That's not to say I don't like Obj-C, I do, and I really like the Cocoa/UIKit framework on iOS too: it's quite clearly the result of software API craftsmen working at the highest level. But things like the .h/.m file separation and, particularly, the lack of literal syntax for lists and maps are constant irritants, the latter so much so that I've started writing complex data structures in JSON and using a library to translate this into NSDictionary's/NSArray's at runtime, because it's just too verbose otherwise. And tracking retain/release bugs can be a huge black hole for productive time.<br />
<br />
Did learning Lisp make me a Paul Graham-certified programming god? I rather suspect not, but I now I know what I was missing out on. And it was most certainly worth it in terms of mind-expansion and generally feeling more secure as a programmer nearing his 40's.<br />
<br />
<br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">* The server, which implements a fairly scary data replication database, is less than 3,000 lines of Lisp. Whereas I suspect at least one of the Obj-C classes is probably that big by now :/</div>Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com1tag:blogger.com,1999:blog-7469682.post-51893075752128303872007-08-11T19:59:00.000+09:302007-08-11T20:03:29.265+09:30A close encounter of the spiny kindYesterday I had an encounter with a very rare creature, an encounter which I suspect will be hard to top. It was effectively right in my backyard, for one of the advantages of living where I am in Adelaide is that getting out of the city into the (semi) wild is only a 20 drive up into the Adelaide Hills.<br /><br />While the hills are certainly not an unspoilt wilderness, and have been changed quite a bit by introduced species and marauding ape-descendants, large areas are protected as National Park, and some of the more tolerant Australian wildlife still calls it come. This includes increasingly-ridiculous numbers of Koalas in some places: a group of us walkers once counted 21 Koalas in 1.5 hour walk.<br /><br />Koalas are common as muck, and it's only interesting if you see one actually moving, which they seem to do about three times a day [<a href="#spiky_fn1">1</a>]. Kangaroos are more rare, but there are at least two groups that live in the areas run and walk in so it's interesting, but not a major event, to see them on the occasions that they are out, usually in the evening in open grassy areas.<br /><br />But a real rarity and treat is seeing an Echidna [<a href="#spiky_fn2">2</a>], small spiny little buggers that are right up there with Platypuses in the weird stakes. Classifying them gave taxonomists some trouble, since they're basically mammals, except they lay eggs. They are small, secretive and roam widely, characteristics guaranteed to make sure you won't see one often.<br /><br />I was out running starting from a place called Chamber's Gully up to a ridge, which is imaginatively named Long Ridge, cos it's quite long, you see? I went up the nice easy tourist trail to the ridge, and when I got to the top, with some spectacular 360º views, I found that the sun was setting and decided I needed to cut the run short.<br /><br />So I watched the sun go down over the ocean and then headed down what is basically the opposite of the nice track I came up, basically part-time stream masquerading as a track, cutting vertically down the side of the hill. But it has the virtue of halving the time needed to get back to the bottom. [<a href="#spiky_fn3">3</a>]<br /><br />I was on my way down this track in twilight, with an evening breeze from the plains pushing back on me, when I saw, shuffling up towards me on the same track, an Echidna. I stopped dead immediately; the wind direction had obviously worked in my favour since it showed no sign it had seen me and kept right on shuffling. So I squatted down and watched it come towards me. And keep on coming, until it nearly bumped into a running shoe, which it carefully sniffed with a pointy snout. It then sniffed the other shoe, looked around myopically with little black beady eyes, and then, with me trying not to laugh out loud, <i>it started to work it's way between my feet and got stuck with me squatting on it</i>.<br /><br />Now this is not a situation I had anticipated being in that evening and, if there had been any reasonable prospect of someone coming down the trail and seeing me squatting on a protected native species, I would have been inclined to get out there immediately. But there wasn't anyone else, and the Echidna seemed to have decided that this wasn't a bad place for a break, even if it did smell slightly like ape-descendant. So I felt I could take my time working out the best way to deal with this.<br /><br />It was when the spines started to make themselves felt that I started imagining what a suddenly-startled Echidna, wedged in what must be admitted is a fairly sensitive area, might do to my chances of producing any of my own personal ape-descendants. So, I quickly devised an executed a cunning plan, which involved suddenly leaping up and forwards, and thus simply dealing with a steep rocky path and gravity, rather than have an angry monotreme wedged in my crotch.<br /><br />Amazingly, the plan worked and this turn of events didn't seem to faze the little bugger. What it had previously judged as a warm, dark hole to rest in for a bit had just leaped out of the way, but no worries, these things happen. It shuffled off in silence, while I continued to try not to wee myself laughing at the utter ridiculousness of what had just happened.<br /><ol><br /><li><a id="spiky_fn1"></a>I once saw one jump between two trees and miss, which may also be hard to top.<br /><br /><li><a id="spiky_fn2" /></a>See <a href="http://en.wikipedia.org/wiki/Echidna">wikipedia entry</a>. This <a href="http://www.nwf.org/nationalwildlife/article.cfm?articleId=763&issueId=61">article</a> is also worth a read.<br /><br /><li><a id="spiky_fn3" /></a>See long ridge between Greenhill and Waterfall Gully Road on <a href="http://maps.google.com/maps?f=q&hl=en&geocode=&q=adelaide&ie=UTF8&ll=-34.954285,138.677759&spn=0.019979,0.02193&t=h&z=15&om=1">this map</a>. If you zoom in on the head of the ridge, you can see the vertical track heading off in the direction of 3 o'clock down to Chamber's Gully.<br /></ol>Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com2tag:blogger.com,1999:blog-7469682.post-16516126571175994832007-05-13T17:00:00.000+09:302007-05-13T21:21:49.177+09:30Followup to "A Quick Restorative"Just a quick followup to the previous entry. Since I made those comments about resource forks not being backed up I've had reason to rethink. The reason I thought they were not being backed up up was that MS Office 2004 stopped working with an error about a broken Carbon shared library. I naively assumed this was a resource fork issue, but it turned out that erasing and re-installing Office didn't fix the problem. Plus, other native Carbon apps stopped working with the same error. Oddly, Eclipse and other SWT apps, which use the Carbon API, were OK.<br /><br />So, I had to bite the bullet and do what the Apple technical docs say, and do a system reinstall to fix Carbon. I was <em>so</em> not happy about doing this — in Windows this is just a world of pain, plus I was just about to go overseas on holiday and rebuilding the system just before a long trip sounded like an insane thing to do. But the "archive and reinstall" option that OS X has sounded straightforward, and I could always restore from backup, so off I went.<br /><br />Despite my trepidation, it went unbelievably well. I took the opportunity to not install all languages and printer drivers this time, which gave me back a few GB of disk as a bonus. Then re-installing OS updates cost a couple of hundred MB of download, but I had a fixed, working system, including Carbon apps in about 2 hours. And everything else about the system, except the development tools and my UI customisation haxies migrated across.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-24774714080550269272007-03-13T17:25:00.000+10:302007-03-13T18:32:46.622+10:30A Quick RestorativeA while ago I wrote a <a href="http://www.egg-tech.com/mac_backup/">short HOWTO</a> that describes how to back up a Mac OS X system to another drive using rsync. This was not for the pure academic enjoyment of it, it's what I use to back up my sidekick PowerBook, and I recently got to see how well it worked when The Worst Happens.<br /><br />Actually, the worst would probably be the laptop being stolen. What actually happened is, without warning, the hard drive lapsed into brick mode. In the short interval between being the heart and soul of the PowerBook and becoming an interestingly-shaped piece of metal, it started making strange noises. Being a professional computer geek I knew what this meant and wasn't even that surprised—laptop hard drives are notoriously fail-prone and mine had been spun up and down several times a day for 2 1/2 years plus the usual knocks laptops get when travelling. And there's that warm glow called Extended Warranty.<br /><br />What did surprise me was that even while I could <em>hear</em> the HDD dying, the SMART status readout in Disk Utility confidently continued to read "Verified". Some <a href="http://labs.google.com/papers/disk_failures.pdf">recent data from Google</a> (PDF) and the blogs that popped up in response seems to indicate SMART just isn't very reliable for detecting when your drive is about to fail—here's another data point to back that finding up.<br /><br />Anyway, when the drive started coughing, I tried to get some recent data off it, which just accelerated its demise. So I booted off the external backup drive and had my system back. I was just about to start feeling smug when I realised I hadn't backed up for nearly six weeks. Irritating, but I hadn't lost much and still had a working system to use in the meantime. A bootable backup is a must-have IMHO, you can limp along with this in the time between it being fixed. Commercial systems that create non-bootable backups are really hobbled in this regard.<br /><br />A week in the AppleCare hospital later and it had a new HDD. Reverse rsyncing from backup took about 2 hours and, after some messing around with the "Startup Disk" preference pane (the "bless" command didn't seem to stick for some reason), the machine booted and I was back to December 27, 2006 in PowerBookLand.<br /><br />So the backup and restore system worked. I really can't even begin to estimate how long it would have taken to reinstall Mac OS X, download 100's of MB's of updates and applications, reinstall Office, XCode, Eclipse, etc, tweak my settings, restore music, contacts, calendar, photos (assuming I had those), ...<br /><br />The more I think of how many things most people don't back up which cost them so much time and energy to set up I find it astounding. Of course there were three things in my favour<br /><ol><br /><li>I knew how much a disk failure and system rebuild would cost, having experienced this before,</li><br /><li>I had the technical knowledge to make a real backup rather than copy random directories every now and then, and</li><br /><li>I was using an OS that makes it easy to clone an entire system.</li><br /></ol><br />Because Mac OS X doesn't assume you're a pirate and require an activation scheme to prove you're not one (such as that used by some other companies which I won't mention but which sound like "Microsoft") it makes it possible to clone the system without the OS working against you. This is something I really appreciate about Mac OS X.<br /><br />One thing that didn't work was resource forks. None of these got restored because, as it turned out, none were being backed up. I just didn't check—when the system booted of the backup and everything appeared to work I naively assumed resource fork backup must be working. However the reason the backup worked is that almost no software seems to rely on them anymore.<br /><br />This was irritating, since the part of the point of the HOWTO was to add info on how to preserve these. But it certainly didn't have a large effect. What tipped me off is none of the Classic apps in my old "Applications (Mac OS 9)" folder which need the System 9 emulator work any more. No biggie, the System 9 apps were interesting for historical reasons, but I came into Mac land for Mac OS X.<br /><br />More annoying, none of the Microsoft Office 2004 applications run. They're not even recognised as applications any more. Neither are Carbon ports of OS 9 applications such as Graphic Converter. Still, this should be fixable, and once I've fixed them I'll start investigating why resource forks aren't making it through rsync and update the HOWTO.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-79950514004439667712007-03-05T20:35:00.000+10:302007-03-05T20:45:48.066+10:30VistaI just saw this ad on an IT shopping site:<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDA49imgRCdXQaKWCr8zB3_vdmfak6yEZslY_KndhnW8PUyn-fJcE_dykcrlyDKNr0WyBYWF3QlrQTOc-Ns1uRmlTaHJ-8CTB7pyZqmxHqmnNQNgMMK3drFTMgixLE49kO6jUEJg/s1600-h/vista_prices.png"><img style="margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDA49imgRCdXQaKWCr8zB3_vdmfak6yEZslY_KndhnW8PUyn-fJcE_dykcrlyDKNr0WyBYWF3QlrQTOc-Ns1uRmlTaHJ-8CTB7pyZqmxHqmnNQNgMMK3drFTMgixLE49kO6jUEJg/s320/vista_prices.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5038379872865855426" /></a><br /><br />Holy crap. My jaw dropped: AU$1,600 for Vista* plus Office. You can buy an entire PC for less than that. Hell you can buy a <i>Mac mini</i> plus a screen for less than that. What is the world coming to when Apple is the value-for-money option?!<br /><br />I don't understand why MS even bothers with the retail boxed version of Vista/Office when it's about appealing as a shite sandwich.<br /><br />* An XP -> Vista upgrade is a far more reasonable** $380<br /><br />** For a given value of "reasonable".Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com1tag:blogger.com,1999:blog-7469682.post-1166258721102296112006-12-16T19:08:00.000+10:302006-12-17T10:08:14.320+10:30Error handling and eleganceI was analing<sup><a href="#cvj_fn1">1</a></sup> some code today, and seriously reduced the size of some knotty configuration handling logic, which made me happy<sup><a href="#cvj_fn2">2</a></sup>.<br /><br />Here's the core Java logic as a snippet:<br /><pre><br /><span class="keyword">try</span><br />{<br /> ...<br /> config.setAll (propertiesFrom (fileStream (stringArg (args, ++i))));<br /> ...<br /> System.exit (0);<br />} <span class="keyword">catch</span> (<span class="type">Exception</span> <span class="variable-name">ex</span>)<br />{<br /> System.err.println (<span class="string">"Error starting app: "</span> + ex.getMessage ());<br /> System.exit (1);<br />}</pre><br /><br />The code just assigns all configuration properties read from a file stream, where the file name is read from the next command line option. I suppose some might argue that it's too highly nested, but I'd say that if you read it from left to right you get close to reading out its meaning: "set all properties from file stream ...".<br /><br />All the actual logic in the snippet is contained in functions, but the sheer number of failure modes in this code is huge. The options file could be missing, unreadable, unparseable. There could be unknown options, options in the wrong format, options out of range: setAll () has about a dozen option-related failures alone. The command line parameter could be missing. A malformed UTF-8 character could appear in the bowels of the config file. Anything.<br /><br />This is not even considering all the usual runtime errors such as out of memory exceptions. And yet the code above handles all of these without distraction from its core purpose, which is after all what it actually does 99.99% of its life. And generates good error messages, if you'll take my word for it.<br /><br />The reason the code is so simple is that all functions either return a valid result, or throw an exception indicating why they couldn't<sup><a href="#cvj_fn3">3</a></sup>. No function ever returns a value that could cause an error later on simply by being invalid.<br /><br />Now the reason I was pondering this is that Joel Spolsky, someone who I have a great deal of respect for, <a href="http://www.joelonsoftware.com/items/2003/10/13.html">doesn't like this exception-oriented approach at all</a>. The two main reasons he cites are:<br /><br /> 1. They are invisible in the source code.<br /> 2. They create too many possible exit points for a function.<br /><br />These, he argues are bad things. Which puzzles me, because, to me, these are good things. I have to assume *any* line could cause an error and any line of code could except out.<br /><br />This argument has been done to death by the way, not least of all <a href="http://www.joelonsoftware.com/items/2003/10/15.html">on Joel's own forum</a>. But I'm going to wade in anyway because I don' have anything better to do, and no one reads this blog anyway.<br /><br />C is a language that follows Joel's prescription for error handling. It doesn't have exceptions, and instead usually uses the function return code to indicate success/failure (and the global errno variable, which is the work of the devil ... don't get me started). You can alternately pass a pointer to an error info variable which gets filled in if there's an error, which I've seen done on occasion. As Spolsky puts it, best practice in C is to "[...] have your functions return error values when things go wrong, and to deal with these explicitly, no matter how verbose it might be."<br /><br />Both ways require error checks spattered throughout the code. Which, and here is where I wade into the debate swinging wildly, leads to ugly code that doesn't compose nicely - for instance you can't pass one function call as a parameter to another. However, in C this sort of chaining is often confounded anyway by the fact that allocated memory returned by a function must be deallocated.<br /><br />Do we really like longer, more complex code, where the flow is broken by all the error checking? And this repetition leads programmers to be lazy: "why bother check the result of this malloc()? It's a tiny amount of memory, it'll never fail" ... SEGV.<br /><br />Is this just my opinion? Quite possibly, but I decided to do my best to code the important logic above in C to see what it would be like as an alternative. The C version tries to keep the important properties of the Java code above, including trying to provide useful error messages (something that many C programs utterly fail at, leading to hilarious "Error: there was an error"-style messages).<br /><br />Here's my best attempt:<br /><br /><pre><span class="comment-delimiter">/* </span><span class="comment">better hope message doesn't overflow this </span><span class="comment-delimiter">*/</span><br /><span class="type">char</span> *<span class="variable-name">message</span> = <span class="type">char</span> [255]; <br /><span class="type">char</span> *<span class="variable-name">error</span> = <span class="constant">NULL</span>;<br /><span class="type">properties_t</span> *<span class="variable-name">properties</span> = <span class="constant">NULL</span>;<br /><span class="type">char</span> *<span class="variable-name">file_name</span>;<br /><span class="type">FILE</span> *<span class="variable-name">file_stream</span> = <span class="constant">NULL</span>;<br /><br /><span class="keyword">if</span> (<span class="negation-char">!</span>(file_name = string_arg (args, i)))<br />{<br /> sprintf (message, <span class="string">"Missing argument: %s"</span>, args [i]);<br /><br /> <span class="keyword">goto</span> <span class="constant">error_handler</span>;<br />}<br /><br /><span class="keyword">if</span> (<span class="negation-char">!</span>(file_stream = fopen (file, <span class="string">"r"</span>)))<br />{<br /> sprintf (message, <span class="string">"Failed to open file %s: %s"</span>,<br /> file_name, strerror (errno));<br /><br /> <span class="keyword">goto</span> <span class="constant">errorHandler</span>;<br />}<br /><br />error = <span class="constant">NULL</span>;<br /><br /><span class="keyword">if</span> (<span class="negation-char">!</span>(properties = properties_from (file_stream, &error))<br />{<br /> sprintf (message, <span class="string">"Error reading properties file: %s"</span>, error);<br /><br /> free (error);<br /><br /> <span class="keyword">goto</span> <span class="constant">error_handler</span>;<br />}<br /><br /><span class="keyword">if</span> (error = config->set_all (properties))<br />{<br /> sprintf (message, <span class="string">"Error setting properties: %s"</span>, error);<br /><br /> free (error);<br /><br /> <span class="keyword">goto</span> <span class="constant">error_handler</span>;<br />}<br /><br /><span class="comment-delimiter">/* </span><span class="comment">done! </span><span class="comment-delimiter">*/</span><br />exit (0);<br /><br /><span class="constant">error_handler</span>:<br /><br />fprintf (stderr, <span class="string">"Error starting app: %s"</span>, result);<br /><br /><span class="keyword">if</span> (properties)<br /> free (properties);<br /><br />exit (1);<br /></pre><br /><br />I should note that I cut my programming teeth on C, and got to what probably was a pretty reasonable level. But nowadays that may not be the case and the below might be considered bad style. If so, I'd be really interested to know how it could be improved.<br /><br /><h3>Footnotes</h3><br /><a id="cvj_fn1"></a> 1. A new verb I've invented for obsessively tweaking perfectly good code.<br /><br /><a id="cvj_fn2"></a> 2. And simultaneously sad in the eyes of most people reading this. Irony.<br /><br /><a id="cvj_fn3"></a> 3. The fact that GC handles cleanup for us is also a big reason why this code is so simple.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1164017729186801092006-11-20T20:16:00.000+10:302006-11-20T20:45:29.496+10:30Another reason why I like static typingI just finished porting a <a href="http://avis.sourceforge.net">fledgling project of mine</a> from one version of a <a href="http://directory.apache.org/subprojects/mina/index.html">library API</a> to a new one. The decision to convert was a no-brainer since the designers of the library had improved the API quite a bit over the previous one, and of course I wanted to be able to follow future updates.<br /><br />But the authors hadn't actually bothered to describe the changes or anything, so I just basically dropped the new JAR over the old one and looked at the red error markers scattered over the code files that turned up in Eclipse. This is the key place where static typing made life much easier: I had a clear map of what needed to be updated and how much work it looked like it was going to be.<br /><br />Things ranging from the obvious, like missing classes due to renaming, to more abstract errors such as unimplemented interface methods and exceptions that were no longer thrown were flagged. What was left was actual semantic changes and, after grokking some of their updated example code, a few search and replaces later: done.<br /><br />All in all, surprisingly painless considering I was going in blind. With a dynamically-typed app it I suspect it would have been considerably less scientific. I suppose I'd start by running tests and build a list of missing method errors (assuming I have 100% test coverage).<br /><br />But even when fixing these and having the tests pass I'd still be paranoid: what about "accidental" passes? Things like changed parameter lists, where extra parameters passed in but no longer used. And what happens when you use a library that uses dynamic tricks like handling missing methods in some clever way so what you're calling is no longer necessarily doing what you think it is?<br /><br />Don't get me wrong, I think things like this are very cool and would probably use them myself. But I worry that there is a price, which is to make the code harder to understand and evolve.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1140926195506037802006-02-26T14:22:00.000+10:302006-02-26T14:26:35.523+10:30The Real Alien 3At some point in my travels around blogland I made a note to have a look at <a href="http://www.pointlesswasteoftime.com/film/alien3script.html">William Gibson's unused screenplay for Alien 3</a>. As I started to skim it I found myself getting sucked in and I'm now halfway through. And you know what? The pictures are better in text. There are sometimes only perfunctory references to special effects scenes "... ANGLE ON THE HULL A towering cliff of metal, Sulaco..", but pieces like<br /><br /><blockquote>The ship slides past beneath us. A U.P.P. interceptor descends INTO FRAME, matching course and speed with Sulaco. The interceptor settles on Sulaco like a wasp.</blockquote><br />gel into a perfect SFX version the head, no CGI required.<br /><br />The other great thing is the screenplay format itself: it reads much faster than a novel. The characters are certainly more one-dimensional than in a novel, one of the key differences in novels is that you get direct access to the character's thoughts, which is not as feasible in film. So maybe I should be saying the screenplay reads much faster than watching the movie.<br /><br />Reading this non-existent Alien 3 is like being in an alternate universe, it's kind of a parrallel-quel, to coin a word that will annoy grammar nazis. The actual Alien 3 wasn't totally bad — it had atmosphere and was OK as a stand-alone film — but it didn't feel like one of the series. The fact that it killed off three of the key characters from Aliens after their heroic struggle to survive in the previous movie didn't endear it much either. With its original characters, gloomy claustrophobic space setting, William Gibson's Alien 3 feels like the true sequel to Aliens.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1137920982355499682006-01-22T19:34:00.000+10:302006-01-22T23:55:47.700+10:30Heatwave hackingWell, <a href="http://www.abc.net.au/news/items/200601/1552608.htm?adelaide">it's officially a heatwave here in Adelaide</a>: four consecutive days over 40° celsius. And now finally a cool change is moving in, along with smoke from bushfires in various places around the state.<br /><br />After the last few days a mere 30° feels nice and cool ;) 40° is at the level of heat where <em>everything</em> just feels hot. Put on a t-shirt and it feels like it's just been ironed. And even if you just sit still the shade you still sweat.<br /><br />So, a good day for staying inside. And sorting out my photo collection. Yes, I definitely know how to get down and party.<br /><br /><h2>The Problem</h2><br /><br />For historical reasons I currently have two sets of photos, one old set manually ordered into a "logical" set of folders and the new one in an iPhoto library. These overlap to a great extent, but I'm not totally confident that every photo in the older directory is now in iPhoto. Since there are about 2,500 photos I'm not too keen to match them all up myself. But I need disk space on my laptop, and removing 1.8GB of redundant photos would be handy.<br /><br /><h2>The Solution</h2><br /><br />The solution is obvious: write a utility in language I've never used before to find files not in iPhoto and then plug it into a tool I've never used before to browse them. The recipe for a happy day of hacking :/<br /><br /><h2>The Language</h2><br /><br />The chosen language: Ruby. For various reasons the other obvious candidate, Python, doesn't appeal and Ruby has a number of things to recommend it from my perspective. One, it seems to be Perl Done Right, and I'm a old-time Perl hacker who loves the power of it but hates the actual language. Ruby has proper OO, clean syntax, Perl regular expression goodness, and <a href="http://www.rubycentral.com/book/tut_containers.html">blocks up the wazoo</a>.<br /><br />The second reason is <a href="http://www.rubyonrails.org/">Rails</a> – at some point I really want to try this out, and knowing Ruby would obviously be a good idea for that.<br /><br /><h2>Ruby Experience</h2><br /><br />The Ruby experience was very positive. Apart from the usual thrashing needed to work out the nuts and bolts of a new language the script came together quite easily. Although I <em>really</em> missed the autocomplete and API browsing I get with Java in Eclipse. The ability to jump around the library without messing with a separate web browser is a godsend when learning a new API<br /><br />I needed to build a table of JPEG files in the two directory trees and then essentially do a "diff" on them (script is <a href="http://users.on.net/~scramjet/scripts/photo_diff.rb">here</a> if you care). For this task, Ruby's libraries were quite sufficient, although somewhat inconsistent. Strange things popped up like the <code>Array.nitems()</code> method, which actually gives you the number of non-null elements vs <code>Array.size()</code> can confuse if you just browse the method names and don't read the spec fully. <br /><br />Other <a href="http://www.cafeaulait.org/oldnews/news2005December8.html">people</a> have noted that Ruby's libraries can be a little lacking in coherence too. Another example: the <code>Dir</code> class used to access directories is quite good, except the pattern used to scan directories is gratuitously different from a regex. But nothing's perfect, and on the whole I think Ruby is now my language of choice for these sorts of hacking tasks.<br /><br /><h2>Automator</h2><br /><br />My script spat out a list of 600 files that appeared not to be in the iPhoto library. This was more than expected, and I needed a way to quickly inspect these and add any missing ones to iPhoto. The obvious route was to get them into Preview, from where I could then drag photos to iPhoto as needed. The obvious way to do this: connect my script and Preview with Apple's Automator.<br /><br />Now, Automator is pretty cool and at first this looked like a no-brainer. I dropped a "Run Shell Script" action in, told it to run my Ruby utility, then connected an "Open Images in Preview" action. Automator seemed happy with the match. But hitting "Run" made Automator do nothing but fire up an empty Preview and then beep happily.<br /><br />Of course hardened Mac heads are chuckling at this point since they know my mistake (the smug bastards). For some reason, even though the Mac has gone partly POSIX underneath and uses <code>file/paths/with/slashes</code> sometimes and eschews resource forks (in theory), it still seems to use HFS <code>file:paths:with:colons</code> for Cocoa (GUI) apps. My script was generating POSIX paths, and I needed to feed Preview HFS ones.<br /><br />I won't bore you with the Googling that followed, but some time later I had worked out to plug the AppleScript below in between the script and the Preview task (<a href="http://users.on.net/~scramjet/screenshots/automator_ruby.png">screenshot here (160K)</a>):<br /><br /><pre style="margin-left: 2em"><br /> on run {input, parameters}<br /> set output to {}<br /> repeat with i from 1 to length of input<br /> set x to item i of input<br /> set output to output & {POSIX file x}<br /> end repeat<br /> return output<br /> end run<br /></pre><br /><br />Once I had grokked this, Automator hummed away and fairly quickly I had Preview showing 600 photos. It turned out most of the "missing" photos were ones I had rotated or otherwise edited in iPhoto. But I did catch a couple that had slipped through the net. Well worth the hours of hacking ;)Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com1tag:blogger.com,1999:blog-7469682.post-1135850791014518842005-12-29T20:29:00.000+10:302005-12-29T20:37:31.680+10:30Mac: one year onI've now passed my one year anniversary of switching to a Mac PowerBook as my primary home computer, and I'm still loving it — this is still by far the best computer I've ever owned. But, as they say, familiarity breeds contempt, and although I certainly haven't developed contempt for the Mac, it does seem that one year of use has been enough to learn about the Mac's warts as well as its beauty.<br /><br />One of the deeper problems that has been bothering me about the Mac interface is how much the look of the desktop is becoming muddled with differently-themed applications. It's worrying because it seems that the applications on the Mac may have started to move towards the visual hodgepodge that is the norm on Windows, where I spend most of my working time. And, worse, it's often the developers at Apple that are the worst offenders in violating their own Human Interface Guidelines.<br /><br />Just a few trivial examples:<br /><ul><br /><li>Safari in brushed metal, just wrong.</li><br /><li>Finder, either brushed metal in one mode, or Aqua in another, more than wrong, just stupid ... "what were they thinking?" stupid.</li><br /><li>I won't even comment on Mail's toolbar changes in Tiger.</li><br /></ul>Don't take it from me: this is not just my personal insight, many more experienced Mac-heads out there have been bagging Apple about this. The Woz himself (Steve Wozniak) commented in <a href="http://inquirer.stanford.edu/2005/jstaffor/woz.html">a recent interview</a> that he believes much of the original Mac ethos is gone:<br /><br /><blockquote><br />... the big companies, Microsoft, Apple and AOL, they tend to turn out the crappiest products, you know, software-wise. The ones that have the most bugs, the most items that are supposedly in there but don't work. The most things that are left out because they aren't finished. The most things that are inconsistent with the way they did their last program. I get the worst, worst software almost always from Apple.<br />... It's like, there was such a cleaner, good approach to it and they did this stupid thing. But remember, the people who wrote the OS X weren't the people who developed the Lisa and Macintosh. Those guys are gone.<br /></blockquote><br />The original Mac purists aren't at Apple any more: they've been replaced by Job's cohort of ex-NextStep developers.<br /><br />John Gruber has also written about this in several articles, pointing out various questionable design decisions (e.g. <a href="http://daringfireball.net/2004/11/poof_consistency">"poofing"</a>) that are very much against the Mac ethos, and noting that <a href="http://daringfireball.net/2004/10/themes">Apple now have introduced at least four OS X application themes</a>. This was before iTunes 6.0 introduced yet another one.<br /><br />Bottom line: consistence, elegance and usability have always defined the Mac platform &mdash that's something that even recent switchers to the platform like myself understood was the reason for its existence. I'm not against Apple developing new user interface approaches, far from it, but I am against them randomly applying changes with no common underlying logic. These decisions, while they may seem superficial, mark a turning point if they indicate the platform's champions no longer care about the "ethos" behind the Mac. The Mac interface <a href="#moyo1">[1]</a> seems to be slowly deteriorating.<br /><br />I'm hoping Apple is aware of this, and have plans to renew the look and feel in OS X 10.5. OS X 10.0 loudly debuted with colourful, lickable, stripy Aqua which was visually striking and perfect for rapidly making a splash — it turned everyone's head. Since then Apple have gradually toned things down — e.g. they've all but removed the stripes and transparency — but kept the colourful buttons and added a muddle of visual styles.<br /><br />Colour has never been used well in the OS X interface IMHO. For example the red "close window" button is overly distracting and the blue Aqua buttons also stand out too much over the important content. But Aqua has at least avoided the overload that many Windows apps inflict, bristling with colourful buttons on all window edges and floating palettes <a href="#moyo2">[2]</a>. And Apple provides the "Graphite" option for those who find the colours distracting.<br /><br />I would like to see Apple start to back off from colourful, transparent and gaudy and go for modern, minimal and sleek. At the same time in 2006 as Microsoft, in a bid to look modern, is stuffing Windows Vista with arrays of gaudy icons, gratuitous glassy transparency and animated everything, Apple could outflank them by simply redefining "modern" as it did in 2001 with OS X 10.0 making Windows XP look like a Fisher Price knockoff.<br /><br />One way they could go is best embodied by a theme I saw being used by one of my favourite Mac bloggers, <a href="http://www.drunkenblog.com/">drunkenbatman</a>, in <a href="http://www.drunkenblog.com/drunkenblog-archives/2005_11.html">screenshots of his desktop</a>. What intrigued me was how minimal the theme was and how it erased Metal and tamed Aqua while looking elegant and letting the content in the windows take precedence over the frame decorations. I tracked this down to the <a href="http://www.maxthemes.com/themes/?theme=Milk">"Milk Chrome"</a> theme for <a href="http://www.unsanity.com/haxies/shapeshifter/">ShapeShifter</a> by Max Rudberg and installed it yesterday and have been absolutely loving it. It's erased a whole array of visual irrits that have been bugging me for a while, including banishing Metal for good. Unfortunately it can't fix Finder: only a bullet to the head could do that.<br /><br />Here's a screenshot of my desktop with the new theme (click to enlarge):<br /><br /><a href="http://photos1.blogger.com/blogger/7432/461/1600/shapeshifter_desktop.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://photos1.blogger.com/blogger/7432/461/320/shapeshifter_desktop.jpg" border="0" alt="" /></a><br /><br />Note how it erased Metal from Safari and the Calculator and even brought Mail into line somewhat. The white buttons and background get out of the way without being harder to access — the shading, shinyness and outlines of the controls are enough. The whole feel is actually a little like an iPod in fact: solid white rounded plastic controls.<br /><br />There are some minor rough edges: the button press animation could use some work — it makes the button appear to recess into the background, but isn't quite noticeable enough; and the theme messes badly with iTunes 6, which I guess is not surprising since iTunes apparently has its own custom look and feel.<br /><br />As far as I'm concerned, this one's a keeper until Apple can do better. It doesn't do anything to fix the various functional issues highlighted by Gruber et al, but cleans the visual appearance nicely. It does disturb me that I feel I need to go hack Apple's look and feel: after all they're supposed to be the masters. It will also concern me if Apple does not take the criticisms of well-respected pundits like Woz, drunkenbatman and John Gruber into account. Apple have been very quiet about OS X 10.5, so I can only hope that, disregarding the usual Apple fascination with secrecy, it's because they have something great in store.<br /><br />Footnotes:<br /><br /><a id="moyo1">[1]</a> That's "user experience", for any Microsoft marketdroids who might be reading this.<br /><br /><a id="moyo2">[2]</a> What is it about Microsoft's button fetish anyway? Since they "innovated" the toolbar on Office some years ago they've gone utterly nuts with little nobs and buttons. When I first got the Mac and ran Entourage I could immediately tell it was a Microsoft app, with tiers of horizontal and vertical toolbar buttons stuck everywhere. This was one of the reasons I switched to Apple Mail: it appeared they'd done some work on making the interface easy rather than busy. It's like those remote controls that actually have fold-out flanges to hold extra arrays of obscure buttons.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com2tag:blogger.com,1999:blog-7469682.post-1135758864792853092005-12-28T18:55:00.000+10:302005-12-28T19:04:24.800+10:30AppleScript ... argh!I just spent more than an hour wrestling with AppleScript, a language that is supposedly easy to use. Well maybe it is easy read, but it's not necessarily easy to understand.<br /><br />Quick quiz - what do you think the following prints?:<br /><pre style="margin-left: 1em"><br />set ch to "."<br /><br />if ch ≠ "." then<br /> log "not a dot"<br />else<br /> log "a dot"<br />end if<br /></pre><br />A cigar if you went with "a dot". Now, what will this print?<br /><pre style="margin-left: 1em"><br />repeat with ch in characters of "a."<br /> if ch ≠ "." then<br /> log "not a dot"<br /> else<br /> log "a dot"<br /> end if<br />end repeat<br /></pre><br />You'd think that since I just wrapped the previous example inside a repeat statement over the characters of "a." that you'd get "not a dot" and "a dot". I'm sure that by now you will have guessed that this is not what you get, or I wouldn't be whinging. In fact you get "not a dot" twice. After reading the AppleScript docs regarding characters, strings, loops and boolean operators I'm still stumped.<br /><br />The solution? Add this after the "repeat":<br /><pre style="margin-left: 1em"><br /> set ch to first character of ch<br /></pre><br />This makes me think that this is some sort of variable type issue, but I really can't be assed spending any more time on this.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com2tag:blogger.com,1999:blog-7469682.post-1130379131372728612005-10-27T11:37:00.000+09:302005-10-27T12:01:39.003+09:30WMA is ScrodSo, Apple has <a href="http://www.zdnet.com.au/news/software/soa/iTunes_Music_Store_comes_to_Australia/0,2000061733,39218798,00.htm">finally launched the iTMS music store in Oz</a>. I've been thinking that Microsoft's WMA music format and associated Janus DRM are in trouble for a while, but kept quiet because of MS's famous talent for coming from behind (e.g. behind Netscape and Palm) and eating the competition. But I think the tipping point for this race went past some time ago, so I can now happily say in public that I cannot see any way in which MS's dreams of a media monopoly are not, in fact, totally scrod.<br /><br />The numbers tell one part of the story: 600 million AAC/FairPlay songs are out there and iPod has 70-75% of the portable market share. And, of course, the cute iTunes interface that works on Mac and Windows, against Windows Media Player, which is an odd-looking beast and works only on Windows. The iPod integration in iTunes is perfect (funnily enough) and the iPod interface is a work of genius. And Apple are now busily rolling out video.<br /><br />This is despite the fact that <em>everything</em> that's not an iPod, from the $700 HDD-based players to the shittiest little $20 flash ones, supports WMA <a href="#fn1">[1]</a>. I can only assume that MS gives away WMA licenses to anyone that looks like they might be building a player. I half expect my next credit card to include a WMA-compatible player on it.<br /><br />But MS's spray-WMA-around-unti-it-sticks policy doesn't seem to be working. The plethora of bit-players <a href="#fn2">[2]</a> that support it may actually be hindering things by confusing the customers, and MS's "Plays For Sure" campaign seems downright insane, given that WMA does not in fact Play For Sure on three out of any four randomly-selected players on the street. <br /><br />Napster's WMA-based subscription music store may be making some money but, when people realise they can't put the tracks on an iPod and that their music collection goes away if they ever stop paying their monthly fees, I suspect there will be an exodus. In Australia, the Big Pond music store doesn't even work unless you're running IE on Windows. An article on ZDnet lists <a href="http://www.zdnet.com.au/news/software/soa/BigPond_Music_can_t_compete_with_iTunes_Analyst/0,2000061733,39218815,00.htm">the other reasons why Big Pond music is doomed</a>.<br /><br />I actually do feel a little hypocritical gloating here. After all, if MS, in a fit of unusual innovative fervor, created the mPod (or ActivePod or, more likely given their track record for exciting names, Windows Media Portable Device <a href="#fn3">[3]</a>), had created the mPod first, and tied Windows Media Player, the mPod and mTunes so tightly together, I'd be up in arms and buying only Ogg-compatible devices that require four Linux shell scripts to sync music.<br /><br />The difference with Apple being in this position is that they're the underdog in everything else, so they have to actually keep delivering cool stuff to stay ahead, rather than doing very little cool stuff and maneuvering to make sure they keep squeezing more money out of old boring stuff.<br /><br />Maybe in a few year's time I'll be bitching about Apple and its damned music monopoly. But for now I'm just happy to see yet another example of MS failing to parlay it's massive bank balance and Windows/Office hegemony into other areas.<br /><br /><a id="fn1">[1]</a> With the possible exception of Sony devices that probably still stubbornly do only mp3 (and that only recently) and ATRAC.<br /><br /><a id="fn2">[2]</a> I'm very happy with that term "bit players" It works in a number of ways in this context<br /><br /><a id="fn3">[3]</a> Someone once said "if MS made toilet paper, they'd call it MS Butt Wipe".Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1123390484008341242005-08-07T14:19:00.000+09:302005-08-07T14:24:44.016+09:30Open source getting down to businessI had a revelation about the real reason for open source's huge acceptance for business use the other day courtesy of Linux kernel maintainer Andrew Morton (Linus's right-hand man). I was listening to <a href="http://www.itconversations.com/shows/detail594.html">Andrew's address to SD Forum</a> where he made the blindingly obvious but brilliant observation that <b>free market economics doesn't work for core infrastructure like operating systems and backend services</b>.<br /><br />The reason you can't have real competition (and thus a free market) for infrastructure technology is simply because the cost of swapping infrastructure massively outweighs any potential gains - you can't switch without re-tooling, re-training and possibly buying new hardware.<br /><br />So we either have a convergence on a closed monopoly (Microsoft) or we agree on an open infrastructure and concentrate on making money in a free market in the things that we can mix and match (Linux and its software stack). And it's mostly in IT infrastructure that open source is making a killing right now, Linux hosting, Apache web serving, BIND DNS provision, Samba file sharing, etc.<br /><br />We have little reason to worry, like we might have a decade ago, that Microsoft will be able parlay its monopoly in the desktop space into a monopoly in the server space - the emergence of Linux and the rallying of many of the key IT players behind it (IBM, Sun, etc) put an end to that possibility.<br /><br />Andrew goes on to express the refreshingly sensible opinion that open source is just a sound method of doing business, not a religion, philosophy or way of life. Closed source development is just as "legitimate", both systems can work depending on the ecosystem they're working in.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1120367453893794552005-07-03T14:37:00.000+09:302005-07-03T14:57:33.820+09:30LispI listened to a <a href="http://www.itconversations.com/series/sdforum.html">podcast of Guido Van Rossum</a>, the architect of <a href="http://www.python.org/">Python</a>, talking at SD forum recently and, although it made me vaguely irritable the way dynamic typing people often condescendingly assume that "strong typing is for weak minds" (actual quote from an audience member), it did resurrect my desire to learn a new language.<br /><br />Not Python - despite Pythonistas' claims I've done enough Python to convince me that it isn't different enough from other OO languages to change the way I think about programming. Indeed, since Python didn't start out OO, it can be slightly obtuse in that area - I think I'd like to avoid writing "self.foo" all the time to reference data members, and avoid, too, the subtle bugs that come with forgetting the "self" (I realise that only weak minds would make this mistake though).<br /><br />I recently revisited Paul Graham's writings on Lisp, and his claim that all languages strive to become Lisp (Guido touched on that too in comparing Python to Lisp), so I decided to have another go at that disturbing language (I'll elaborate on the "disturbing" part next). Luckily Paul Graham has a very good book available online called "<a href="http://www.paulgraham.com/onlisp.html">On Lisp</a>".<br /><br />What I immediately found from the first few chapters of Graham's book is that, although I can recognise deep down the elegance of Lisp, I find I can't "think" in it at all. I had the same experience at Uni looking at examples in Lisp and Miranda - after some forehead-wrinkling and mental contortion they finally clicked in my head and I was able to see the mathematical elegance of the solution. Although the elegance can be somewhat lost when "real" Lisp programmers try to avoid non-tail recursions for performance reasons and make the code that much less clean - see section 2.8 of the book if you care. <br /><br />The problem may be that I had already learnt to program before I went to Uni. I learnt snippets of basic on my friend's Commodore 64. Then I moved to MS GW BASIC when my family finally got our own, IBM compatible, PC. From there I moved to QuickBasic, which lived up to it's name - I've never had such a speed improvement for "free" by just by upgrading compilers, it was almost like magic. QuickBasic had examples of programming with, gasp, procedures with no line numbers. Actually, this procedure thing wasn't totally alien, I knew about gosub/return, but named procedures with actual parameters, wow, what a revelation when I "got" that idea.<br /><br />From QuickBasic I moved to QuickC. C actually wasn't too much of a leap from procedural basic, except of course pointers and complex data structures were new concepts. But basically C had the same core forms as basic (pointers and malloc/free excepted). And it was a "real" programmer's language. For the first time I was able to develop (what I thought were) real applications. I eventually got into writing low-level 8086 assember inside C to do things like write to the text mode screen buffer, execute the terminate and stay resident DOS call and access the then new MS mouse BIOS driver API's (and I can still remember that it was interrupt 33H).<br /><br />My rambling back down memory lane is not intended to show that I can't stay on the point. It's intended to illustrate that I've had nearly 20 years (and I'm only 33) of procedural thinking. And while my current language of choice, Java, is a nice language, it wouldn't be at all alien to the me of 15 years ago.<br /><br />So, I'm getting that same "hard of thinking" problem when reading the Lisp in Paul Graham's book. After some staring, I can get the examples, but I wouldn't have had the first clue how to write them. So it appears learning Lisp might be like my attempts to learn to touch-type, and fail for the same reason - while learning my productivity would be so painfully bad I'd give up.<br /><br />It does vaguely worry me that the facility with which I can write code one way might be paid for by the inability to learn new, better, ways of doing things. After all, I somehow suspect that we haven't achieved perfection with current languages and tools.<br /><br />In spite of this, or perhaps, because of it, my own belief is that language has very little overall effect on productivity. Things like GC, protected memory, sophisticated tools, copious good-quality libraries and a massive community support seem to be much more important factors than whether I can sort a list using a custom comparison function in two lines of code rather than 6. And the key factor? The quality of the developer obviously makes the most difference.<br /><br />But of course I may be wrong. How can I really know whether I'd be a much better developer if I could think in Lisp? But I suspect the human mind at my age (i.e. post adolescence :/ ) has room for only one major language, programming or otherwise.<br /><br />I'll keep at the Lisp though.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com4tag:blogger.com,1999:blog-7469682.post-1119082340055452502005-06-18T17:08:00.000+09:302005-06-18T17:43:53.010+09:30Swing's new text rendererIt looks like Swing (or more correctly Java2D) is getting sub-pixel anti-aliased text (aka ClearType) in Java 1.6. This addresses one of the chronic problems with Swing's native look and feel emulation - it's hard to look native when you're the only jaggedy-ass app on the desktop.<br /><br />Or it <em>would</em> address the issue if Swing's slightly retarded font renderer didn't bravely snatch defeat from the jaws of victory.<br /><br />Look at this <a href="http://javadesktop.org/images/chet/LCDText/lcdwindows.png">side-by-side example</a>. Swing'osities abound. The Sans Serif font is particularly worth mentioning: bollixed up letters include "M", "W" and "y". It looks like it gave up anti-aliasing the "2" altogether. The "#" is sloped in the original, but Swing goes for the more upright look. And the letter spacing for "FOX" is quite original. In fact looking Swing's "FOX" rendering compared to the rendering on the Mac I'm writing this on forced an involuntary guffaw.<br /><br />I don't want to come across as totally mean-spirited here. It seems that Sun is getting the message. It's just that it also seems they aren't competent to address it. The well-meaning <a href="https://jdic.dev.java.net/">JDIC project</a> is producing components like the taskbar icon API, which developers have already built many times over (I know, I wrote one too), but this one at least has the virtue of trying to be cross-platform (e.g. task bar icons sort of work on Mac OS X too, for a given value of "work").<br /><br />However, the fact that Swing menus attached to taskbar icons cannot popup over the taskbar means they do the same crazy dancing workaround as all other Swing popup windows and can thus appear several centimeters <em>above</em> the icon when you click on it.<br /><br />This is kind of emblematic of the Swing attitude right now: let's add anti-aliasing before we fix the basic font renderer. Let's add taskbar icons before we fix the basic popup menu support. Let's add a new look and feel skinning engine before we fix the native look and feel on the world's largest desktop platform.<br /><br />There's no reason to be surprised that many developers are happy to put up with the extra deployment hassles that come with using SWT - at least these are something we have some control over.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1119079943920016762005-06-18T16:53:00.000+09:302005-06-18T17:45:56.533+09:30Whereis ...I generally use www.whereis.com.au reflexively when looking for maps online. Not sure why, given that they insist on using POST to generate map pages meaning you can't send a whereis link to anyone or bookmark it.<br /><br />Looking at their URL while cursing their POST technique, I noticed they do put <em>some</em> info in the URL. There's a "brandId" field, which selects which brand logo appears in the page. Slightly amateurish but, even better, setting brandId to an invalid value (e.g. 4) generates a server error (what a 733t hax0r I am).<br /><br />Even if I couldn't tell they're using Struts by the ".do" in the URL, the NullPointerException gives the game away. I wonder why such a big site can't afford to employ developers with some sort of clue?Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1115355208801012832005-05-06T13:55:00.000+09:302005-05-06T14:23:28.826+09:30Windows ... notJust as a followup to my whinge about Mac OS X previously, and to illustrate how Windows usually manages to bollix things up much more efficiently than OS X, here's a <a target="pic" href="http://www.users.on.net/~scramjet/screenshots/go_explorer.png">screenshot of Explorer on my XP machine</a> - see if you can spot the mistake.<br /><br />Yes, the tree on the left shows two directories under "work" while the list on the right shows, correctly, three. No amount of F5'ing would convince the bugger otherwise, even though this is a local NTFS filesystem where you'd think MS could get it right by now.<br /><br />Later on, it got better. I decided to delete one of the three directories and got the <a target="pic" href="http://www.users.on.net/~scramjet/screenshots/go_explorer2.png">dreaded "file in use" dialog</a>. Windows users know this indicates that, no matter what, be they Administrator or even God, they will not be able to delete this file short of booting Knoppix and nuking it from orbit. The only other alternative is the "check every process to see if it might be using the file" mamba<br /><br />In this case I knew damn well that no process was using the bugger - I had just created the thing. But, because I was desperate (I couldn't get any work done until I could reset that directory) I shut down all cmd.exe's, killed the virus scanner, closed emacs, everything. And still no dice. I went to get a coffee and simmer down ... and when I came back, without having done a damn thing, now I could delete the folder.<br /><br />This sort of random crap: locked files, flashing icons on the desktop, endlessly scrolling Program menus and drivel-spouting pop-ups drive me mad when using Windows. Actually I shouldn't have mentioned the random pop-ups, for some reason they particularly elevate my blood pressure: Take a tour of Windows!? Hide inactive icons!? ... what I'd like is for you to f*ck off and let me get some work done, son of clippy.<br /><br />XP came out in 2001, so for 4 damn years I've been putting up with this blizzard of shit every time I log into a new PC. Not mention the fact that turning off the fisher-price "task panes" and other crud has become an automatic process, no longer requiring higher-brain intervention.<br /><br />Maybe Mac OS isn't so bad after all.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1115351075329718282005-05-06T13:05:00.000+09:302005-05-06T15:57:58.636+09:30Spotlight ... not?OK, I got all excited about Spotlight when I upgraded to Mac OS X 10.4 recently. I've been doing some research into making DVD's from recorded TV and keeping the results (links, text snippts, etc) in a folder. But this folder has gotten very full, so I assumed a better way to find stuff now is to use Spotlight to search for topics of interest, rather than page through it all.<br /><br />So, I'm looking to see if I've saved any info on a tool called "replex". I go Ctrl+Option+Space "replex" ... nada. Which is odd because I <em>know</em> I saved an email recently (as a text file) on that subject. So I manually find the email. And here's a <a href="http://www.users.on.net/~scramjet/screenshots/spotlight_not.png">screenshot of the text file with "replex" in it</a> with Spotlight failing to, er, spotlight it.<br /><br />I also discovered, while trying to post the screenshot via FTP, that Mac OS X will happily mount an FTP volume (with username + password) but won't write to it. WTF?<br /><br />Much as I love my Mac, things aren't perfect in Mac land right now.<br /><br />Update: further investigation showed that Spotlight was only working for files that aren't in my home directory. I'm using FileVault, and I suspect this is related. After logging out and then logging in again, Spotlight is working fully. Let's hope that's fixed in 10.4.1. I'd report this as a bug, but after spending a lot of time trying to find out where to report a previous bug in iCal and then getting zero feedback, I'm not too excited about the prospect.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1114425692454018562005-04-25T19:37:00.000+09:302005-04-25T20:29:54.903+09:30High FidelityNote: in this blog entry (actually a minor essay, sorry) I'll be using the term "HD DVD" to refer to both of the proposed next-generation high definition video standards: <a href="http://en.wikipedia.org/wiki/HD-DVD">HD DVD</a> and <a href="http://en.wikipedia.org/wiki/Blu-ray_Disc">Blu Ray</a>. And I'll be using the term "suits" as a friendly way of referring to MPAA and other music and movie industry middlemen.<br /><br />So, it looks like HD DVD will have encryption up the wazoo, what a shock. Who would have thought the movie industry would react to the cracking of CSS with the cry of "if at first you don't succeed, just use more?"<br /><br />They will of course have access to the finest minds money can buy, and indeed the likely encryption system for HD DVD looks pretty impressive - must have cost millions to develop (it's called AACS: see <a href="http://yro.slashdot.org/comments.pl?sid=146168&cid=12246625">a short description of it on slashdot</a>).<br /><br />The AACS system guarantees that, if a key is cracked, instead of being forced to continue to produce discs that they know can be cracked (as is the case now in DVD-land), they can issue new keys, revoke player keys and distribute updates onto players via the HD DVD discs themselves. I'm told this sort of system is in use for satellite links, and hasn't been hacked yet.<br /><br />Yes, the suits must shiver with delight when they consider that they'll finally be one step ahead of those pesky, copy-happy consumers.<br /><br />Leaving aside the issue of why suits are so worried about small-time copying - the real pirates will continue to do what they've always done and use high-grade bit-for-bit copiers which defeat both CSS and the proposed systems - do they really expect this system to work in the presence of open platforms like Linux, where the last resort for copying is to simply hijack video and audio at the driver level?<br /><br />Of course not. Encryption is only as strong as it's weakest link, and in order to make it impossible to copy on consumer-grade equipment they need to control your hardware and software from the top to the bottom. This even includes the cables that connect your components, like <a href="http://anandtech.com/multimedia/showdoc.aspx?i=2321">HDMI</a>, which has anti-copy encryption built in. Because, otherwise you sneaky consumers will just hook your high definition HDMI connectors into a recording setup.<br /><br />Open systems like Linux are impossible to "protect" from sneaky consumers. So don't expect HD DVD or Blu Ray on Linux any time soon. Or ever.<br /><br />One of the things that made DVD one of the fastest-adopted consumer technologies ever was the synergy between PC's and DVD players. The massive market for DVD drives on computers helped make them extremely cheap very fast. Unfortunately for suitdom, the hosting of DVD players and their associated software on generic platforms made CSS open to attack from the inside, and it didn't take long to fall.<br /><br />To be as successfully-adopted HD DVD also needs to ride the PC wave, but this time around, the suits think they can do it right and lock us thieving customers out properly.<br /><br />But in order for cunning plan to work on the PC, they need a PC platform that is unhackable. Enter Palladium, or <a href="http://www.microsoft.com/resources/ngscb/default.mspx">Next Generation Secure Computing Base (NGSCB)</a>, or <a href="http://news.com.com/2100-1001-982127.html">whatever it gets called next when the populace figure out what the current obscure name actually entails</a>. NGSCB, or its derivative, requires both "secure" PC software and hardware. Which means cryptographically protected from meddling by untrusted parties, i.e. you. You won't be able to write a driver or create any hardware for the system until you've handed over some serious money and signed away your first-born child to the consortium that controls the HD DVD standard. If you write a hacked driver that permits copying, you go to jail. If you leak a key, they revoke that key, and you go to jail. If they decide they don't like you for any reason at all, they revoke the key.<br /><br />Nirvana for the suits is when your equipment will lock you out of doing anything but what they've prescribed you can do. Fair use goes out the window. So does competition: to publish titles and make hardware you'll need to sign up and pay a fee to get a key. And, if the current "forced" sections on some DVD's are any indication, once they've got more control we may well see ads on purchased HD-DVD's - all in high definition of course.<br /><br />It may sound paranoid, and indeed I've been indulging in some worst-case speculation. Happily, reality tends to intrude even on the best-laid plans of mice and middlemen. There are two lights at the end of the tunnel, and they're not an oncoming car.<br /><br />One roadblock is that the very existence of large numbers of Linux installations guarantees a market for non "secure" PC's. This means that suits, in collaboration with Microsoft and the various other usual robber barons of the PC world, cannot force the market by fiat to replace open platforms with "secured" ones. This still won't make HD DVD available on open platforms, but at least the rest of us will have a place to play and a platform for competitors to target.<br /><br />The second roadblock is that HD DVD isn't quite the guaranteed winner that the suits are dreaming of. DVD was so wildly successful because it was simply a quantum leap from VHS - there is not a single way in which VHS is competitive with DVD. DVD's have a better picture and enormously better sound, are cheaper to produce, have smaller and more reliable media, allow easier navigation, can play in PC, sport nice friendly menus, and frequently ship with extra features and DVD-ROM goodies.<br /><br />But when we go from DVD to HD DVD, the new format offers ... well, a better picture is about it. Given the current woeful penetration of HDTV's, this is not going to be a major selling point for some time. And even when (or if) the price of a decent HDTV drops below $1,500, the suits will need to wait until people retire their old TV's. DVD's didn't require retirement of old components to see benefits. To demonstrate an advantage, HD DVD's do.<br /><br />The other problem is that people have consistently demonstrated that more is better: given the choice between higher quality and more, they'll take more - given the quality remains acceptable, and DVD certainly provides acceptable quality. So it's entirely possibly people will use HD DVD's as simply a larger DVD. Maybe two or three movies on a disc.<br /><br />This more-is-better fact of human nature, plus the current high price of HDTV's and the inevitable initial high price of HD DVD units and movie titles, plus draconian DRM restrictions may doom HD DVD to stillbirth, or at best a minor niche in the cashed-up techno-geek market, similar laserdisc.<br /><br />What's the alternative to next-generation uber DRM and pissed-off customers? Well, the suits could try something utterly crazy, like reduce the price of movie titles to the point where there's no point in anyone copying them. If HD DVD titles were, say, $10 I, for one, would never buy another blank disk again. When you take into account the amount of time and effort to make a copy plus the lack of cases and cover art, I'd pay $10 for the real thing over $1 for a bad copy any day.<br /><br />The real problem is that the current usual DVD price of $25 is over the invisible line for which many people will make the effort to copy rather than buy. I buy maybe three DVD's a year simply because the ones I want to spend $25 on need to be guaranteed good, and the only ones in that category are <em>ones I've already seen</em>. Which means I only buy DVD's that are so good I'll see them 5+ times - otherwise it's just cheaper to hire them, which is my usual method of viewing. There are very few movies that I want to see 5 times, but there are quite a few that I'd like to see more than once, and which I'd pay $10 for. But, for most suits, I imagine a $10 standard price for a DVD is too scary to even consider.<br /><br />Will HD DVD flop? Time will of course tell. In the meantime I, for one, won't be particularly worried if I have to stick with DVD's for while.<br /><br />Further reading:<br /><br /><a href="http://www.freedom-to-tinker.com/archives/000800.html">Next-Gen DVD Encryption: Better, but Won't Stop Filesharing</a><br /><br /><a href="http://www.spectrum.ieee.org/WEBONLY/publicfeature/jan05/0105ldvd.html">DVD Copy Protection: Take 2</a>Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1111298330601176872005-03-20T16:28:00.000+10:302005-03-20T18:14:54.303+10:30MonoDevelop == Eclipse#? (plus why OSS pisses me off)Is it just me or does MonoDevelop look a hell of a lot like Eclipse?<br /><br />Check out this <a href="http://primates.ximian.com/~lluis/blog/images/md3.png">screenshot of MonoDevelop</a> in this <a href="http://primates.ximian.com/~lluis/blog/pivot/entry.php?id=36">article on its progress to date</a>. Then compare this to <a href="http://www.users.on.net/~scramjet/screenshots/eclipse.png">this Eclipse screenshot</a> (140K). Projects (sorry, "solutions" in Microsoft-speak) on the left, tasks at the bottom, source code on the right complete with closable tabs. In a few years time, they'll have written Eclipse#, probably complete with their own plugin system.<br /><br />I realise Eclipse has borrowed a lot from other IDE's, but this is really too similar to credit, even down to copying the bad parts of Eclipse like the unscalable tabbed source viewer that becomes clumsy after about 6 tabs. I suppose they'll soon be "innovating" (Bill's favourite MS-speak) refactoring support.<br /><br />This is getting off-topic, but Mono is also busy forking Java staples like Ant (NAnt) and JUnit (NUnit). Why exactly did the Mono/Novell guys decide to build on .NET when they could have taken on the years of work gone into OSS Java VM's like Kaffe and GNU Classpath?<br /><br />The muti-language thing is a furphy - .NET runs any language that looks like C# (single-inheritance, single return value, statically-typed, etc) just like Java runs any Java-like language. They can both run other languages like Python, but they end up more as interpreters-on-a-VM, since neither natively supports Python-like dynamic types and multiple inheritance. Plus, regardless of language, you still get the same C# or Java-oriented system frameworks. You end up writing C# programs in Python (or VB.NET, or whatever) syntax.<br /><br />The static compilation thing also holds no water: Java can be statically-compiled if you wish (gcj or Excelsior JET are two that I've used). Although, <a href="http://tweakmind.blogspot.com/2004/07/java-vs-net-runtime-optimization.html">as I've argued before</a>, this seems to be more to appease hard-core C addicts than to actually improve performance.<br /><br />I'm going to veer even more off-topic and say that this is the thing that pisses me off about the OSS world at the moment: so much time is spent by tribes of geeks busy re-engineering existing stuff that very little that is truly innovative is appearing. Case in point: KDE and Gnome are both run-of-the-mill desktops, trying to match Windows. They're OK, but meanwhile Mac OS X still continues to blow me away.<br /><br />The OSS world just seems to have zero big-picture vision at the moment, it appears to be just a bunch of tribes squabbling over which is The Way, KDE vs Gnome, Java vs .NET vs Python, RPM vs DEB, etc. They're not building new stuff, they're continually rebuilding old stuff, much of which is tools and frameworks for building things rather than the things themselves that would make enough difference to someone considering switching from boring old Windows. I can't think of a single thing about KDE, Gnome or Windows that would make a big difference if I was forced to use only one.<br /><br />Each OSS project that essentially duplicates another is not progress, it's not healthy competition and it's not about helping choice: it's fracturing standards, duplicating effort and balkanising OSS.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com1tag:blogger.com,1999:blog-7469682.post-1107325772233923152005-02-02T15:58:00.000+10:302005-02-02T17:00:53.026+10:30Speed bumpShifting to a PowerBook for my home computing has underlined a something that I should have realised a while ago: it's time to rethink the obsessive focus on speed in computing. Case in point: I'm writing this on a computer with a "mere" 1.33 GHz CPU with what I recently heard someone call an "anemic" 167MHz bus connecting it to the rest of the system. This laptop has a relatively slow hard drive, memory and a "small" 1024x768 display. By the yardsticks of many hardware fetishists, this rates as a truly poky system speed-wise. And yet this is hands-down the smoothest and nicest-looking PC I've ever used. At work I have a 2.4GHz system with vastly faster components, and it somehow doesn't manage to feel any faster.
<br />
<br />I realise I haven't been excited about computer hardware performance improvements in quite a while. This may be just a sign of getting jaded, but it wasn't always this way and I do believe a change is happening. My first PC was a 4.7MHz IBM XT clone. Then a 25 MHz 386 which felt like a supercomputer - this thing was at least 15 times the speed of the XT, try to remember when you last had that big an upgrade. Then a 66MHz 486 which was nice but not as huge as the previous jump.
<br />
<br />After Uni when I started working, I got the chance to use one of the first 100MHz Pentium PC's on the site - once again I had a little supercomputer on my desk. Coupled with NT 4, which was an equally huge improvement over the squalid world of Windows 95, this just felt like a next generation system. But since then, speed has become less and less of a noticeable improvement (and newer versions of Windows have failed to improve much either, but that's another story).
<br />
<br /><a href="http://www.gotw.ca/publications/concurrency-ddj.htm" target="article">This article</a> points out a hard truth that hasn't been discussed much: CPU speed has hit a wall, one which is not likely to shift for a while. The article includes a graph of CPU speed over time, and shows that it was in 2003 that we hit the wall. In 2005 we should have 10GHz CPU's, in reality we may get a 3.7GHz one this year.
<br />
<br />And what if we did have 10GHz CPU's? Maybe I'm just limited in imagination, but what would we actually <em>do</em> with them? Fancier graphics? This "anemic" Mac already has some serious graphics chrome thanks to the GPU. Faster compiles for us developers? It's been years since I had to wait for the compiler thanks to incremental compiles. Games? Get a PS2, for $250 it'll give you way more bang for buck than a tricked-out PC at ten times the price that draws more current than a toaster oven. There are always uses for more power in tasks requiring sheer calculating grunt e.g. audio compression, video/graphics editing etc, but these won't change the computing experience for most of us.
<br />
<br />The good bit is, what gets me excited today (professionally anyway ;) is the software, not the hardware. Technologies built on platforms like Java, OS X, and next gen languages are evolving nicely. I just hope that the hardware speed wall won't impede the progress of these technologies.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1102323072076602682004-12-06T19:19:00.000+10:302004-12-06T19:21:12.076+10:30Bad toolsNot to seem like I'm down on Sun or anything, but I can only assume that they really want us to avoid using their command line tools for Java development. First it's the Java runtime complaining about a class not found when really the class is there, it's a class that <span style="font-style: italic;">it depends on</span> that's missing. Then, while using "jarsigner" today I get this error:
<br /><pre>
<br />[signjar] java.lang.InternalError: jzentry == 0,
<br />[signjar] jzfile = 10414112,
<br />[signjar] total = 1555,
<br />[signjar] name = C:\development\invision.ui.web\clovis_view.jar,
<br />[signjar] i = 1,
<br />[signjar] message = couldn't read LOC header
<br />[signjar] at java.util.zip.ZipFile$2.nextElement(ZipFile.java:321)
<br />[signjar] at sun.security.tools.JarSigner.getManifestFile(JarSigner.java:985)
<br /> ...
<br /></pre>"Oh no, that looks serious, I have a corrupt JAR file" was my natural response. Rebuild JAR file. Same error. Turns out that, although jarsigner allows you to specifiy the same source and target file, it doesn't quite go as far as actually handling that and tries to read and write to the same JAR file - bad. A simple <code>if (inputFile.equals (outputFile) <warn poor sod user I can't do that></code> would have saved me, and probably 5,000 other programmers 10 minutes of time.
<br />Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1101945816365395052004-12-02T10:29:00.000+10:302004-12-02T12:01:54.653+10:30Swing "Hi-Fi"<a href="http://weblogs.java.net/blog/bino_george/archive/2004/11/hifi_swing_or_i_1.html">This article</a> from a Sun engineer working on Swing in JDK 1.6 ("Mustang") and the comments it inspired revisit some of the Swing issues I've banged on about before. Here's an excerpt:
<br /><blockquote>In Tiger and Mantis, we have provided support for the Windows XP look and feel. The mechanism used to provide this support was based on reading the resources embedded in the XP styles files and using those icons and colors to render our Windows Look and Feel. Unfortunately, Microsoft has changed the Styles files in Longhorn so that the resources are no longer visible using the mechanism we used in Tiger and Mantis
<br />[...]
<br />We talked this over with engineers from Microsoft's graphics team, they suggested that the way to work with the Longhorn themes was to use the UxTheme API. So Leif Samuelsson (Swing Windows Look and Feel Author) and I prototyped a version of the Windows XP Look and Feel that uses the UxTheme engine to perform the rendering of Swing components.</blockquote>And one of the responses:
<br /><blockquote>I for one am not holding my breath. This very approach was suggested to Sun <em>three years ago</em> in <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4587653">bug #4587653</a>, right down to the names of the API functions to use. It has even been submitted multiple times by independant posters. But it has consequently and repeatedly been turned down by reviewers in favor of the always-trailing-behind bitmap copycat approach.</blockquote>Obviously he's been in the same situation I have: he's tracked problems, suggested solutions, voted for them, and then waited years for any acknowledgement that there's even a problem. And then the Sun guy actually seems to be expecting people to congratulate them on finally doing it the right way instead of the unsupported hack they're using right now. And we'll have to wait another JDK cycle (18 months) before we can use this.
<br />
<br />This guy goes on to say:
<br /><blockquote> Surely, no future builds of Mustang will look any more native than the current one before the font support is fixed, too. Don't bother suggesting any APIs for this, however. That should be considered redundant as the issue will probably be talked over with some Microsoft engineers already around the end of this decade.</blockquote>Sounds bitter. I feel his pain ;)
<br />
<br />Another interesting comment:
<br /><p></p> <blockquote> <p> Natively themed drawing means that you're using the toolkit's functions to perform the painting, but without having any of its structures associated with the component. This still doesn't save you from the anomalies stemming from a mock user interface, but at least it looks the same. [...]
<br /></p> <p> It is often portrayed as the only way to achieve platform-independant user interfaces (why anyone would want that is above me), but in reality it is more like writing your own filesystem on top of the disk driver.The real reason it is done is probably because the model of custom drawing fits better with the garbage collector in Java. You still have to close your files explicitly, but nobody is complaining about that, though. </p> </blockquote> <p></p> The comparison with emulated Swing and wrapped native IO is telling. Anti SWT pundits often claim that disposing widgets is "non-OO" (whatever that means), but rarely realise there are quite a few real-world operations that unfortunately don't fit the GC model. If Sun had written it's own filesystem implementation to avoid having to do icky things like close () files, people would have agreed that was insane. When they decided to write an entire widget framework <span style="font-style: italic;">and</span> graphics stack, the major part of a modern OS's interface with its user, somehow that didn't sound insane.
<br />
<br />This article is particularly apt, coming as it does as the latest <a href="http://java.sun.com/products/jfc/tsc/sightings/S21.html">Swing Sightings article</a> goes out. There are some truly <a href="http://www.groxis.com/service/grok/g_products.html?id=adbJeG2Z">excellent</a> and <a href="http://www.blogbridge.com/productpage.htm">sophisticated</a> apps in that selection. And all the good examples in there contain workarounds for Swing's L&F issues. Either they use one of the extended L&F's, or they apply WinLAF-style tweakage. If the Sun guys hadn't painted Swing into such a corner, these sorts of uber-apps might have appeared 4 years ago and blown people away compared to the dull Windows apps of the time.
<br />Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com0tag:blogger.com,1999:blog-7469682.post-1101095831095928012004-11-22T14:20:00.000+10:302004-11-24T10:19:14.520+10:30SWT and Swing: Clash of philosophies<blockquote>Most shoppers don't like to get in car that looks and smells terrible, even if it does have a nice engine.
<br />
<br />-- From email discussing SWT vs Swing history</blockquote>
<br />
<br />I’ve written about Swing vs SWT before, but for some reason I feel compelled to expand. This is probably because I needed to write a small Swing GUI last week and it once again prodded a sore point. The reason it’s a sore point is that, once upon a time, you wouldn’t have found a more ardent supporter of Swing than me. I started working with Swing in 1997, while it was in the development 0.x releases, and followed it as it went from com.sun.java.swing, tracked the arguments about whether it should be java.swing or javax.swing, and celebrated the final release as part of Java 2.
<br />
<br />I know Swing inside and out. I’ve written big applications, and developed Swing application frameworks for esoteric things like integrating copy/paste/drag/drop between tree, table and list views, command integration for dynamically managing commands in menus, popups and toolbars. I know <em>why</em> you need to add components to JFrame.getContentPane (). I feel I can justly claim to know Swing.
<br />
<br />And I went from being a Swing booster to a rebel.
<br />
<br />Why? The conversion corresponded to a transition in my view on software, from focusing on technology to usability, from abstract to pragmatic when I first started to get feedback by people using my applications. I started to realize that excuses don’t cut it: if I want people to like and use my software then it needs to Just Work.
<br />
<br />The software and frameworks I wrote back then were like Swing, big and intricate. Everything was abstracted to the nth degree. And they were so complex that, after a while, even I had trouble extending, debugging and using them. At the time I, arrogantly perhaps, assumed that the others having trouble with the software I wrote were just less smart and would “get it” eventually and realize the wisdom of my approach.
<br />
<br />This is the reason why Swing failed to win the hearts and minds of developers: it was written by people with this mindset. It’s powerful and abstract. It has a complex inheritance hierarchy and an even more complex pluggable L&F system. And it’s hard to learn, hard to extend. It is consistent rather than intuitive. It obsessively uses models for everything, even buttons. And it tries to avoid any special cases so, for example, if you want a set of radio buttons to behave normally (ie have only one selected), you need to know to create a ButtonGroup and add the buttons to it, otherwise they'll just <em>look</em> like radio buttons. Because having radio buttons in the same panel automatically exclusive would be a special case and wouldn’t fit the clean Swing model.
<br />
<br />And Swing often doesn't provide things that <em>every</em> GUI app is going to need: eg if you want to add a context menu then, up until Java 5.0, you had to create your own right-mouse-click listener and add the special right-click selection behavior expected in trees and tables yourself. This means that, until recently, <em>every Swing programmer had to reinvent the same context menu logic</em>, including having to ensure the menu doesn’t go off screen. Not to mention the lack of a font selection dialog box or spinner (introduced years late in 1.4).
<br />
<br />Swing also rates platform integration as a very low priority. It even seems to go out of its way to make it harder to add platform-specific extensions: one of the things that finally convinced me to ditch Swing was when Sun gratuituously removed the last sane way to get a window handle on Windows in JDK 1.4.1. There was no technical reason, since I can see from the source code that it still uses the same way internally to get the handle. The alternative Sun provided, the JAWT library, was designed to allow native plugins and explicitly stops you getting a handle for anything but a Canvas, so I had to use a horrible hack and create an invisible Canvas in the frame and then walk up to the parent frame using native code. And after I got that working it turned out that the JRE didn’t actually put the JAWT DLL in the path, so I got linker errors when deploying: it was clear the Sun guys didn’t actually use any of this stuff themselves.
<br />
<br />Many of the irritating things about Swing stem from the fact that it tries live in its own world: the lack of native anti-aliasing (ClearType or otherwise) stems from the fact that Java2D doesn’t integrate with the platform’s font renderer; the wrong default font probably stems from the fact that Java2D has it’s own TrueType renderer that doesn’t handle Tahoma properly; the sticky menus are due to the fact that it doesn’t support mouse capture; missing display effects like shadows, wrong borders because it’s just too hard to rewrite all this stuff. Collectively they induce a feeling of no confidence.
<br />
<br /><blockquote>This seems to me to be a case of some overly zealous Win32 API programmers thinking they could do things a better way. Even though Eclipse looks responsive, IDEA has proven that you can do the same thing with Swing.
<br />
<br />I just read that IDEA has anti-aliased fonts using Java2D layer, can you get that with Eclipse?
<br />
<br />-- <a href="http://javalobby.org/forums/thread.jspa?threadID=7034&messageID=58866069&tstart=0">JavaLobby Swing-booster talking about SWT</a>
<br /></blockquote>
<br />Here’s the thing that differentiates the new me from the old me, and me from the guy quoted above: I now realize that the people using my software don’t <em>care</em> that I can do anti-aliased fonts. In fact, if my app is using anti-aliased fonts when none of the other apps are, then they may complain that it looks funny. They <em>do care</em> if they’re used to ClearType and the application doesn’t use it, and Swing apps are almost unique on Windows in that they end-run around ClearType: even my old NTEmacs, compiled 2 years before ClearType even existed, happily uses it. Before supporting anti-aliased fonts, Swing needs to get the basics right and do things like actually use the correct default system font on Windows.
<br />
<br />Users care about things like menus not going away when they click outside them, or that tooltips appear in all sorts of odd places. They may care that the app uses several MB more of memory. They may not consciously notice that Swing widgets look subtly wrong (eg see <a href="http://winlaf.dev.java.net/">WinLAF</a>) and don't support the same shadows, animations, etc as the other apps, but they'll likely feel that your app looks a bit naff regardless. They definitely care that the File Open dialog doesn’t support their Favorites links, or their context menus, thumbnail image view or D&D from the desktop. They will also likely feel that the UI feels slow, even though Swing is way faster than it started out. I still don't why that is, but I experience it myself and I'm convinced it's real.
<br />
<br />Programmers on the other hand care that laying out GUI’s with SWT's GridLayout is much easier by hand than GridbagLayout with its 8 or so parameters per layout info object.
<br />
<br />Here’s a response further down:
<br /><blockquote>> I don't know about the IDEA hacks, but the standard
<br />> Swing in J2SE still doesn't use the font antialiasing
<br />> feature of Java2D, after so many years..
<br />>
<br />
<br />Not true.
<br />
<br />Try this to create an antialiased label:
<br /><pre>
<br />_perspectiveHeaderLabel= new JLabel() {
<br /> protected void paintComponent(Graphics g)
<br /> {
<br /> ((Graphics2D) g).setRenderingHint(
<br /> RenderingHints.KEY_TEXT_ANTIALIASING,
<br /> RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
<br />
<br /> super.paintComponent(g);
<br /> }
<br />};
<br /></pre>
<br />-- From <a href="http://javalobby.org/forums/thread.jspa?threadID=7034&messageID=58866168&tstart=0">JavaLobby</a></blockquote>Okay, so I just need to subclass every widget then I can enable anti-aliasing (not sure what you do if you use 3rd party components). So this isn’t useful, but that apparently isn’t what the author thinks is the point.
<br />
<br />SWT takes a “make it as simple as possible, but no simpler” approach that I would once have derided. It is simpler than Swing. It is not simpler than it should be. It hits a sweet spot that Swing abandoned in its focus on software engineering geekery.
<br />
<br />SWT doesn’t have pluggable table cell renderers or buttons you can put animated graphics on. It doesn’t have three ways to create a window, JFrame, JWindow, and JDialog: it has a Shell. Instead of 20-odd methods with 5+ arguments each on the strangely-named JOptionPane, it has MessageBox, which 95% of the time does what you need. MessageBox doesn't do HTML text, but instead it gets the basics right by making the correct alert sounds and wrapping the message text properly.
<br />
<br />SWT has Table and Tree classes that look and feel native (because they are) down to the expansion animation and smooth scrolling. It doesn’t support pluggable renderers, but supports straightforward customization of text, icon and tooltip, which is all the majority apps usually need, without forcing you to deal with the horrors of Swing’s Component-based cell renderer approach.
<br />
<br />In short, SWT tries to Get Out Of The Way (tm) and Just Work in the 95% case. And for that 5% case where you need animated graphics in an auto-scrolling TreeTable view: write your own or use one of the custom widgets that SWT already supports. Custom advanced widgets are just as straightforward in SWT as Swing (see some <a href="http://azureus.sourceforge.net/screenshots_v2.php">Azureus screenshots</a> for an example). People who don't use SWT often don't realise that it's not limited to native widgets, and in fact has several "emulated" widgets in its default toolkit (eg CLabel and StyledText), it just <em>defaults to native whenever possible</em> rather than rebuilding the world.
<br />
<br />OK, so now I feel I’ve got this off my chest. I bought into Swing in a big way and, after years of defending it and believing that Sun would live up to the expectations I had, it was a big deal to admit that I was wrong. Thankfully the designers of SWT seem to have the same philosophy as I do, and I don’t have to trust they’ll get it right eventually: SWT has already got it right enough, and now I can get on with writing the software.Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com2tag:blogger.com,1999:blog-7469682.post-1098772091500614552004-10-26T15:47:00.000+09:302004-10-27T15:52:01.926+09:30First, do not suckHave to get this rant off my chest: <span style="font-weight: bold;">I am so sick of software sucking</span>. Today was an extreme example, but every day I use computers there's several examples of self-imposed software stupidity driving up the blood pressure.
<br />
<br />So I propose a new maxim for software designers based on a maxim from medicine, "First, do no harm":
<br /><ul> <li>First, do not suck</li> </ul>So: do not tell me one thing is wrong when in fact something totally other is. Do not randomly do stupid things that I can't stop you doing. Do not <span style="font-style: italic;">assume</span> anything that I can't correct you about.
<br />
<br />The highlights of the random screwups so far for today:
<br /><ul> <li>Both my monitors randomly refresh occasionally, setting icons blinking, windows flashing
<br /></li> <li>Saving a file in Acrobat sometimes burns 100% CPU for no apparent reason. Cursor still blinks in Save As dialog, but dialog is dead. Comes back after about a minute</li> <li>Acrobat informed me that the disk for temporary storage was full (a mere 5GB free), when in fact the file name was too long.</li> <li>Java app using XML parser works on one PC with JDK 1.4.2 but fails to find SAX parser on identical machine with identical JDK.</li> <li>Letters take half a second to appears when typing a filename into the Save As dialog when pointing to a network drive (presumably due to the dialog trying to auto-complete the name)</li><li>Open an image by double clicking. Try to compare it with another image by double-clicking - replaces first image. No apparent way to turn this off.</li> <li>Text an Excel spreadsheet that was displaying fine suddenly turns into a bunch of "######"'s. Checked that format of cell was "Text". Only by changing format to "General" did I manage to fix it</li><li>Word pops up irritating panel whenever I copy more than one piece of text - take a few minutes to work out how to blow that away. It then insists on selecting whole paragraph randomly when I want to select a piece. Wade through checkboxes in options to turn that off</li> <li>While editing this post, discover that Ctrl+S publishes - I was trying for Ctrl-A to select all. Why do I need a shortcut for publishing? It's hardly something I do every few minutes.</li><li>An endless number of apparently temporary user account profiles are appearing in my "Documents and Settings" folder. They're using several gigabytes of disk, but can't be deleted because something is using the files. No idea what that something is though.</li> </ul>Matthew Phillipshttp://www.blogger.com/profile/03638108677381246692noreply@blogger.com2