I hate ugly hacks, but sometimes you're left with no choice. I was hacking away at the XML schema for one of our projects, and eventually settled on a neat solution. Imagine the following scenario: your system stores its configuration in XML format; the configuration defines several types of events that can occur, and all these events share the same actions. What's the most efficient way to go about it?
Borrowing a page from the object-oriented software design book, I decided to create an abstract BaseActionType. It will include some basic self-describing information (lets suppose I'd like to have an action category; I would simply add an element to the base type and override the value in each subclass.) Each subclass would describe a different type of action, for example a SendEmailActionType would extend BaseActionType, override its category with a fixed value and add fields such as server, subject etc.
Unfortunately, it appears that XML Schema only supports one of two modes of derivation: derive by extension or derive by restriction, whereas what I in fact require is a hybrid of the two. xs:extension will not allow you to override values, whereas xs:restriction will not allow you to define new elements. This is a problem I used to encounter all the time when creating XML schemas, and today it finally pissed me off enough to find a solution. I was really stumped for a while, but eventually noticed that one of the examples on the XML Schema specification was:
<xs:element name="size" type="xs:nonNegativeInteger"/>
<xs:element name="unit" type="xs:NMTOKEN"/>
It got me thinking: how can they be restricting a type while adding elements? Then it hit me - this is in fact a restriction on an xs:any particle! Here's the solution I came up with:
<xs:element name="Category" type="CategoryType" />
<xs:any processContents="strict" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="Category" fixed="Synchronous" />
<xs:element name="Server" type="xs:string" />
I reckon developers who are more experienced with XML than I am already knew the answer, but since I've been using XML far more intensively than the average developer and was repeatedly stumped by the same problem I hope someone finds this useful.
Update (January 2nd, 10:26): My technological enthusiasm has an annoying tendency to turn into a display of naïveté. Specifically, the hack above seems to work just fine for Stylus Studio (any maybe other technologies, who knows?) -- but isn't really accepted by the .NET SDK xsd.exe tool. There are two issues here:
- The tool fails to recognize fixed="value" attributes for enumerations ("Schema validation warning: Element's type does not allow fixed or default value constraint.")
- The tool does not recognize restriction of xs:any ("Schema validation warning: Invalid particle derivation by restriction.")
I haven't been able to work around these limitations (yet), nor have I the time at the moment to research into XML Schema and find out if these features are supposed to be supported. In the meanwhile I'm reverting to another solution.
I've been getting into ARM assembler a little bit. The ensuing conversations were amusing in the extreme (I'm Holograph, in case that wasn't obvious):
(11:49:59) Holograph: you mean to tell me that this shit:
(11:50:00) Holograph: str r4, [sp, #-4]!
(11:50:07) Holograph: all it does is basically "push r4"?
(11:50:35) YK: ja
(11:51:53) Holograph: that is FUCKED UP
(11:53:15) YK: not really, thats the normal way of doing things, x86 is fucked up
I rest my case.
Some software-related tidbits (I'll be updating this during the day):
- ReSharper 2.0 EAP build 213 is out (lots of builds since the 210 I have installed on my machine at work). I'll have a go at it and post comments in the ReSharper EAP post as usual.
- GAIM 2.0 beta 1 is also out. I've been using it for the past few hours, it seems pretty stable - there've been a lot of small improvements (away mode handling, account display, preferences) but don't expect a quantum leap in usability.
- Dying to get rid of Windows XP Automatic Update's super-nagging 10-minute interval "Restart Now or Later" dialog? So am I. Luckily, Coding Horror's got the answer.
- There's no avoiding QuickTime these days, but what with all the iTunes hype the player is taking up ridiculous amounts of drive space (the installer itself is over 30MB!) I've installed the latest QuickTime Alternative and never looked back.
Been a while since I posted about one of my biggest passions, being movies of course. Aside from spending an increasingly larger portion of my time on studies (who knew differential and integral calculus can be so demanding?) I'm still trying to find the time to work on some of my pet projects, particularly the home theater and car stereo systems I use. I did manage to see some movies and stuff though, so here we go:
- Tim Burton's latest movie Corpse Bride is a mixed bag. Objectively speaking, aside from maybe being a little short (76 minutes) it is spectacular: visually beautiful, musically brilliant and featuring some of the best voice acting talent ever heard from behind the big screen. The problem is that it's not just a movie, it's a Tim Burton movie. It's no secret that I consider Tim Burton the best film director since... well ever, really, and I'm used to being so moved by his movies that I find it hard to breathe. Corpse Bride was great - the first half particularly so - but it gave me none of those "holy crap, I must've been holding my breath for 10 minutes straight" minutes that are the real highlights of the moviegoing experience.
- I went to see Serenity with a bunch of friends today, but since some of them have already seen it the choice of movie inexplicably changed to The 40 Year Old Virgin. As far as shitty light comedies go this actually had some genuinely funny movies, but that's probably only because I wasn't expecting much. Bottom line: it's not much better than you'd expect, so stay away.
- On the same note, Deuce Bigalow: European Gigolo is another "light" comedy. This movie is the embodiment of what I despise in Holywood (stupid, pointless and unbelievably coarse), so I won't bore you with the details. There are funny moments certainly, but the bottom line is it's a really crappy movie.
- I finally got to see Harry Potter and the Goblet of Fire and was vaguely disappointed. My compadré Oren seems to have similar feelings about the movie; it was in many ways great (particularly the way they went all-out on effects), but it missed out on a lot of seemingly unimportant details that are absolutely vital to the entire Harry Potter experience. Read my comments on Oren's post for more insight (?).
- Finally, my brother and some friends came over and we settled on watching Total Recall again. It's been at least 5 years since I've seen the movie and it's every bit as good today as it was years ago, with one important distinction: now that I'm older it's far more obvious to me how bad a couple of actors are (yes, Arnold, that means you. You're still the bomb though), and it's also far more astounding that despite the action-oriented mindset of the movie it is actually very well written. They manage to give you all of the clues and none of the answers, and they don't even hint at what the questions really are right until the very end (with that poorly chosen "What if it IS a dream?" line). Bottom line: terrific movie. God I miss the '80s.
Some movies I'm looking forward to:
- The Chronicles of Narnia: The Lion, the Witch and the Wardrobe might be the "next big thing" (after Lord of the Rings...) I read the prequel a while back and the first book a couple of weeks ago and wasn't actually overly impressed - so far it seems like a plainly overrated fairytale (I can certainly appreciate fairytales, just not the overly childish ones). In some aspects it keeps reminding me of Lemony Snicket's A Series of Unfortunate Events (which upon reflection was actually really very good), I guess I'll just wait and see.
- I'm still waiting for Memoirs of a Geisha. As someone who's usually not into dramas I'm not quite sure what it is about the movie that attracts my interest, but I have a good feeling about it.
I can hardly contain my excitement, so I just won't bother. Suffice to say that Aural Planet
have made their excellent album Lightflow
freely downloadable! If you're into ambient, electronic and/or deep trance music give this a listen. Even if not, at least spend a couple of minutes listening to Pipe Life
(track 2) - you might be surprised.
I bought the album back in 2001, and now you can get this excellent music for free. What more could you wish for?
On a completely seperate note, check out the Demovibes collections - excellent demo music fully compiled for your streaming pleasure.
Feelings are often paradoxical in nature. Sometimes the result is called hypocrisy, sometimes merely confusion or stupidity. Being something of a software evangelist I always try to convince people to switch to greener pastures, although my ideas of what is better are not always consistent with what is commonly accepted. For example, I would not try to persuade someone to use Linux, because although the OS appeals to my sense of geekiness and my inherent attraction to free, communal efforts (read: open source), my experience with Linux has all but discouraged me from using (and certainly recommending) the system. That said, when I find something I like and appreciate I certainly stick by it and try to evangelize it to the best of my abilities.
So why was I utterly pissed off when, clicking on this link via a blog post I read using RSSOwl (ironically, another great open source program), I was presented with a large "Please update your web browser!" box right at the top of the website urging me to "upgrade" to Firefox/Safari/Opera/whatever?
I'll tell you why. Because in-your-face evangelism pisses me off. Ilya, a friend of mine, introduced me to Firefox when it was still Firebird 0.5 alpha, and I've been using it ever since. I've been telling about it to everyone who'd listen; I've recommended it to friends, family, colleagues and even just random people I have occassionaly found myself talking tech with. Back in May, when I remade my personal website into a blog, I've designed it for CSS compliance and tested with Firefox first, IE second (and found quite a few incompatibilities in IE in the process). I've placed a "Take Back the Web" icon right under the navbar, in hope that perhaps a casual IE user would stumble upon it and wonder what it's all about. But I don't nag, or at least try very hard not to. I consider people who visit my website as guests, and just as I wouldn't shove my goddamn tree-hugging, vegetarian, free-love, energy-conservation way of life* under your nose if you came to visit my house I wouldn't want you to feel uncomfortable when you enter my website. Which ToastyTech did.
My open-source hippie friends, do us all a favor and take it easy. This sort of thing will not win people over to your cause; at most they'll just get pissed off and avoid your sites altogether. A regular joe stumbling onto spreadfirefox.com (or, for that matter, slashdot) would be just as likely to return to it as Luke would to the "wretched hive of scum and villainy" that is Mos-Eisley.
* In case you were wondering, I'm no tree-hugging hippie, I'm not a vegetarian, my love is an equal-trade business and I drive a benzine-powered vehicle the same as everyone else. But I care.
So I have to update a bunch of documents, primarily that 6mb pile of text, graphs and objects spanning about 110 pages I mentioned last time
. My last experience working on it with Writer (from the OpenOffice.org 2.0 suite
) was a blast, so despite the bigger assignment I figured that it would be a good learning experience.
The template the document was originally based off of is apparently
very ill-conceived because, upon further examination, I noticed some
issues that had nothing to do with the document import (for example,
the headers were completely handcoded - no autotext or field usage
etc.) In the process of reworking parts of the template, namely the
table of contents and headers, I had to learn a bit about Writer and
would like to share some insights.
First of all, unlike Word (I use 2003), there's no "edit header"
mode; you differentiate between the header and the rest of the page by
looking at the box outlines (gray by default). When you edit the page
header in Word it actually changes editing mode: the rest of the page
is grayed out and it's very obvious that you're editing the header
itself. I'm not sure which approach I favor better, although I am
inclined to go with Word (because it makes it that much more obvious
what you're doing at any given time). That said, the Writer interface
for fields is more powerful, or at the very least far more intuitive,
than Word's. The interface for working with headers is also much more
powerful than in Word, although it did take me a little while to get
the hang of it; I had to get over some preconceptions from years of
working with Word [since version 6 on Windows 3.1!] and spend a couple
of minutes using OpenOffice's sparse but surprisingly effective help.
Writer lets you associate each page with a particular "Page Style" and,
consecutively, each Page Style with its own Header and Footer. Not only
that, it lets you use define (per Page Style) a different header/footer
for odd/even pages (in case you're authoring a double-sided printed
document). Once you get the hang of it, defining and using headers is a
Editing headers in OpenOffice (left) vs. Microsoft Word (right)
Creating and using indexes and tables (in the classic sense, not
graphical tables) with Writer is a lot more powerful than in Word; it
gives you a somewhat less-than-intuitive but extremely powerful GUI for
setting the structure of each entry in the table/index. I used this
feature for creating a Table of Contents in the document; being the
tidy tight-ass that I usually am the document has a very clearly
defined outline (same concept as in Word: headings, body text etc.)
which made for an extremely easy transition into a table of contents.
The process is easier in Word - just add the Outlining toolbar to your
layout and click on Update TOC:
It's not really any more complicated in Writer, just slightly less
intuitive. From the menu select Insert->Indexes and
Tables->Indexes and Tables, choose Table of Contents and you're
done. When it comes to customizing the table of contents, though, Word
is practically useless; in fact, it took me a couple of minutes of
going over menus just to come to the conclusion that I can't remember
how to access the customization dialog. While on the subject, Word
manages to obfuscate an amazing number of tools, power tools and
necessary functionality behind a convoluted system of toolbars, menus,
wizards and dialogs to the point where it's impossible to find what
you're looking for. Writer to Word is (not nearly, but getting there)
what Firefox is to
Internet Explorer as far as usability is concerned: immediately
lightweight, does what you want out of the box and when you DO need
something nontrivial it's much easier to find (Insert->Header as
opposed to View->Header and Footer, for example. Why the hell would
I look for something like that in View?). Formatting in general is much
more convenient in Writer; for example, you can very easily select a
section of text and set it to default formatting with Ctrl+0, which you
could theoretically do with Word, but only after spending a lot of time
customizing it. There's no easy way to do it out of the box without a
lot of unnecessary and inconvenient fiddling with the mouse. It would
be interesting to examine Office 12, supposedly Microsoft went to great
lengths to improve usability.
But I digress. Back to table of contents: unlike Word, the default
Table of Contents in Writer does not hyperlink to the various sections
of the document. In light of the immediacy of the floating Navigator
toolbox in Writer (which Word sorely lacks) it is simply unnecessary.
However, since the document will eventually be exported to Word this
was necessary. It took another few minutes of searching, but ultimately
the answer was completely obvious: right-click the Table of Contents,
click on Edit Index/Table and simply customize the structure of the
entries via the Entries tab. The process could use some improvement,
though: there is no way to change the structure for more than one level
at a time which is quite frustrating, and modifications to the
structure are not intuitive (for example, I couldn't figure out why the
hyperlinks wouldn't show, and then figured that I probably need to also
insert an "end hyperlink" tag to the structure. This would completely
baffle a non-technical end-user).
Customizing an index/table with Writer: powerful but not intuitive
So far, though, the experience has been a resoundingly positive one.
There's always room for improvement, but if at version 2.0
OpenOffice.org has already managed to supersede Word as my favorite
word processor Microsoft have some serious competition on their hands.
As part of an ongoing OpenGL implementation project, I was tasked with implementing the texture environment functionality into the pipeline (particularly the per-fragment functions with GL_COMBINE
). To that end I had to read a few sections of the OpenGL 1.5 specification
document, and let me tell you: having never used OpenGL, getting into the "GL state of mind" is no easy task to begin with, but made far worse when the specifications are horribly written.
To begin with, there is absolutely no reason why in 2005 a standard that is still widely used should be published solely as a document intended for printing. Acrobat's shortcomings aside, trying to use (let alone implement!) a non-hyperlinked specification of an API is the worst thing in terms of usability I've had to endure in recent years (and yes, I was indeed around when you could hardly get any API spec let alone in print. I don't think it matters). Even Borland knew the importance of hyperlinked help with their excellent IDEs of the early '90s. Why is it that so late into the game I still run across things like the spec for TexEnv2D, which describes only some of the function's arguments and then proceeds to tell you that "the other parameters match the corresponding parameters of TexImage3D"? I can only imagine the consternation of someone trying to figured out the spec from a book having to flip all the way to the index at the end to see that the TexEnv3D function appears on pages 91, 126, 128, 131-133, 137, 140, 151, 155, 210 and 217 (the function definition is at page 126, by the way.)
Hey, SGI! I have a four-letter acronym for you. H-T-M-L. It's been here for a while and is just as portable as PDF (and certainly more lightweight.)
Technical issues aside, the spec itself is simply incomplete; there is no obvious place which tells you where, for example, you have to set the OPERANDn_RGB properties; in fact, if you followed the spec to the letter, the people using your implementation would not be able to set these properties at all because the spec for the TexEnv functions explicitly specifies the possible properties, and those properties are not among them. You have to make educated guesses (it does makes sense that you'd set the texture unit state from TexEnv), do "reverse-lookup" in the state tables at the very end and try to figure out from the get function which set function is responsible for the property or dig up the MESA sources and try to figure out how they did it (because it's most likely to be the right way of doing things. I would go as far as to say that MESA serves as an unofficial reference for the OpenGL API). Ideally you would do a combination of the above just to make sure that you are compliant, but the spec will not be there to help you.
Finally, the spec makes problematic assumptions about your background. I think it's a little naïve to assume that anyone who reads the OpenGL background has a strong background in OpenGL programming, or in developing 3D engines. I actually do have some background in 3D engine development and it still took me a few hours going over the chapter again and again (and trying to infer meanings from code examples on newsgroups) to understand precisely what "Cp and Ap are the components resulting from the previous texture environment" means. In retrospect it seems obvious, particularly in light of some clues littered about, that they were referring to the result of the function on the previous texture unit, however that would only be really obvious to someone in the "GL state of mind," which at the time I was not. Tricky bits of logic should be better explained, examples (and particularly visual aids such as screenshots!) should be given. But the OpenGL spec has absolutely none of that.
So bottom line, specs are absolutely necessary for APIs; make sure you have people who proofread them, and put the developers that are most customer-savvy on the job. It would be the single worst mistake you can make to put a brilliant, productive and solitary developer on the task because you would frustrate them beyond belief and the end-result would be of considerably inferiour quality.
I've updated the remote logging framework
with a bugfix; if you're using it (or curious to see how it works/what it can be used for) feel free to download it and have a look.
I've also started hacking away at the PostXING v2.0 sources in my spare time, which unfortunately is very sparse at the moment. If anyone has tricks on how to get through HEDVA (differential/integral mathematics, A.K.A infinitesemal calculus outside the Technion...) successfully without commiting every waking moment, do share.
So I got to see a bunch more movies lately (right now it's the only
thing keeping me sane in the face of the dreaded Technion HEDVA/1t
course). Here's a brief review on each:
- Ridley Scott's Kingdom of Heaven is a rather belated attempt to capitalize on the "psuedo-historical epos" trend of the last few years which was ironically started by Scott's own Gladiator (in case you were wondering, Braveheart
was not a little too early for its own good, having come out in 1995).
Synopsis: Balian, the son of Lord Godfrey, is knighted, takes up the
task of defending Jerusalem from the forces of Saladin and ends up
saving the day etc. Throw in a bunch of clichés about love, what it
takes to be a humane leader back in the crusades and some generic
morality crap and you've got a seriously badly written film. In its
defense it does feature some superb photography, OK action and a huge
cast consisting of some favourite actors of mine: Orlando Bloom (who
finally appars capable of acting), Alexander Siddig (of DS9
fame), Brendan Gleeson, Jeremy Irons, Edward Norton (who does not
appear visually), David Thewlis and finally Liam Neeson, who isn't
actually on my list but does deserve a mention. Too bad the movie just
- Nicolas Cage's latest movie Lord of War
was an absolute blast. It is an amasingly cynical, mostly funny and
quite surprising satire of what makes third world countries wage war,
as well as what makes greedy people tick. It doesn't make any excuses
for the clichés it employs, and in my opinion it hits the spot
precisely: some messages simply do not come across until you bang them
into someone's head with an allegorical hammer. My only issue with it
is that it fails to keep the satire simply as that, and culminates in a
verbal political message which is an exercise in redundancy.
- Instead of making a long point I'll skip to the very end with a summary of The Exorcism of Emily Rose:
good acting (particularly by Laura Linney and Tom Wilkinson),
reasonable dialog, crappy predictable storyline and no boobs at all. In
short, a movie not worth your time; if you're interested in the
legal/judicial aspects do yourself a favour and go watch Law &
Order, it's what they do.
- I've heard a lot of conflicting opinions on I, Robot. Maddox went as far as to say:
Here's how I would have changed this film: start out with a
shot of Will Smith in a grocery store buying a 6 pack of Dos Equis
beer, except instead of paying, the cashier is a Dos Equis marketing
rep who hands Smith a thick wad of bills. Next shot: Smith finishes the
last of the beer, walks over to Isaac Asimov's grave and lets loose.
Why not? Same message, none of the bullshit.
I won't deny that this movie has some serious issues (particularly with product placements; here it was even worse than The Island, if that's even possible) but I would take an opposite view to Maddox's: I enjoyed the movie immensely. Having read the book
quite recently I find that the only place where the movie deviated
completely from what is detailed in the stories (because I, Robot is
not a single coherent storyline, rather comprised of several short
tales) is in the depiction of Susan Calvin's character, who is actually
very true-to-form in the beginning of the movie. Regardless, the movie
features rather imaginative photography, some great action sequences, a
plot which ultimately doesn't suck and some of the funniest dialogue
I've heard in years (the only competition comes from the underrated Constantine). Bottom line? Recommended.