Sunday, 2 May 2010

Apple's vision of an 'open' web

Apple are certainly 'thinking different' when it comes to the definition of 'open'. In their spat with Adobe regarding Flash on Apple's mobile products, Steve Jobs responded almost convincingly about why Flash isn't on the Apple mobile product line. The primary reason? Openness. Flash is a closed platform, whereas JavaScript, CSS and HTML 5 are all open.

The 'but' here comes from the HTML 5 part, which includes a <video> tag that essentially renders Flash video obsolete, with decode and render available natively in the browser, rather than through a plugin. The standards committee overseeing HTML 5 still hasn't agreed on what format that video should be delivered in. The de-facto standard of h264, a high-quality, industry-driven standard that's nevertheless mired in patent and licensing issues that are really sticky. Or Xiph's Theora, which has been designed to avoid using techniques covered by patents, and is available royalty-free (which most of us think of when we think 'free').

When it comes to browser support, the big three unsurprisingly lend their weight to h264. Mozilla's Firefox—distinct from the others in being the only organisation that's an actual browser company and also non-profit—throws its weight behind Theora, with that crazy idea that participating in the web shouldn't involve licensing fees just to access it.

Of the corporations, Google has interestingly promised to open source the VP8 codec and, since they own YouTube, could theoretically swing the balance by offering VP8 support in Chrome and VP8 YouTube videos, especially if Firefox supported the same.

But, back to Apple.

Steve Jobs reckons that there's no such thing as a free video codec. Furthermore, he issues a threat to Xiph over Theora (without including useful specifics, which relegates it to FUD).

So Steve: get a grip. The i-whatever ecosystem is locked down tight, and you're free to do that to whatever extent your customers are willing to put up with, but don't hide behind a wall of righteousness when dissing other technologies. Your 'open' arguments are empty with a platform and environment that is increasingly developer hostile.

As for me, I've owned a G4 PowerBook and am typing this on a two year old Macbook Pro. With each statement from Jobs regarding criticism of his closed platform, I find it increasingly unlikely that I'll buy a third. So hey, Apple marketing-types: your CEO's statements are costing you a £1500 sale, and most likely not just from me.

Edit:

Apparently Apple once believed in a royalty-free Web, too. However, despite the original having lived here on apple.com for years, it's recently been pulled.

Thankfully, George Orwell's Memory Holes are a difficult thing to accomplish with an open Web.

Hat-tip to ZeroGravitas on Hacker News for the info (and to Create on the comments page for the Memory Hole reference).

Thursday, 8 April 2010

Simple File Renaming in Emacs

I stumbled across this tip while browsing reddit/emacs. In summary, it allows for the possibility of having a 'write file' (C-x C-w) variant that deletes the original file, essentially performing a simple rename without having to invoke dired or fire up a shell.

Putting on my Emacs cap, I came up with something similar, shorter and (debatably) more 'emacs-y':


(defadvice write-file (around write-file-possibly-rename activate)
(let ((old-filename (buffer-file-name)))
ad-do-it
(and current-prefix-arg
old-filename
(not (string-equal old-filename (buffer-file-name)))
(delete-file old-filename))))


defadvice allows you to hook a new function up to an existing one, to be invoked either before, after or around it (around advice invokes the original function with its original arguments with ad-do-it, and can do that zero or more times). This form of advice is what hits the spot for this task. Subsequently, when write-file is called, this advice intercepts it, captures the current filename and then invokes the old behaviour. After the write has happened, it checks to see whether or not it should delete the old file, and does so if the preconditions are met.

This preserves the existing C-x C-w behaviour, creating a completely new copy of your file if you choose a different name. Invoked as C-u C-x C-w, however, it deletes the old filename, performing the same rename with less code and less duplication of the existing file-writing plumbing.

Gordon's Pledges?

Gordon Brown pledges 'five more years' as Prime Minister if Labour wins.

That's not a pledge, Gordon. That's a threat.

Sunday, 4 April 2010

Institutional Abuse is not "Petty Gossip"

Cardinal Angelo Sodano has said the Roman Catholic faithful will not be swayed by "petty gossip" about child sex-abuse allegations.

I find myself stunned.

The church faces far more than "petty gossip", at least as far as Giuseppe dalla Torre, head of the Vatican's tribunal, seems to be concerned, compelled as he was to remind us that the pope cannot be called to trial because he enjoys immunity as head of state. And yet here we have one of the most senior members of the Catholic church dismissing repeated charges of the most disgusting violations of trust and abuse as "petty".

Nothing quite reveals a man-made god as much as the dismissal of "petty" concerns.

Saturday, 3 April 2010

PS3 System Update 3.21

Sony appear to be breaking new ground with the PS3: the only games console that loses features with firmware 'upgrades'. Yes, that's right: version 3.21 drops support for the 'Install Other OS' feature. This is almost on-par with the decision to drop software emulation of the Playstation 2, cutting off those large libraries of games that long-time users of Sony's console series have built up.

The best part of it is being held hostage: you can't use the Playstation Network with anything but the latest firmware, so those who stubbornly refuse to upgrade will find themselves stuck with local-only access.

Way to go, Sony! Really making your customers feel valued here.

Thankfully, George Hotz, who is similarly bemused has some advice: don't update. He's already hacked the PS3, and is looking to get a 3.21 firmware that doesn't lose the feature.

The strange thing is, he's the one that Sony will think is out of order.

Wednesday, 10 February 2010

Determining the Function Name of a CODE Ref in Perl

One of the great things about Perl that it inherits from functional programming is the ability to treat functions as data. You can create an function and assign it to a scalar reference. You can take a reference to an existing, named function and do the same. You're then free to pass that reference around, to be invoked later (the latter case is similar to function pointers in C, but the former is very different as the created sub can make use of variables defined in its lexical scope as it forms a closure).

While defining an API to a service I've been writing, I suddenly encountered the need to be able to differentiate between references to named functions and references to anonymous subroutines. Quite simply, once I'd established a set of objects to operate on, a named routine should be invoked once for each, whereas an anonymous routine should be given the entire set to work with (this allowed a great deal of reuse within the existing codebase without limiting flexibility).

While I suspected that Perl might be able to do this, it seemed like it would be some serious magic. Data::Dumper displays sub { DUMMY } when printing CODE references, so it's largely opaque.

However, Perl comes with the B module, providing access to Perl's internals as it's running.


use B;

sub named_routine {}

my $named_ref = \&named_routine;
my $unnamed_ref = sub {};

printf "%s\n", B::svref_2object($named_ref)->GV->NAME;
printf "%s\n", B::svref_2object($unnamed_ref)->GV->NAME;


this yields:


named_routine
__ANON__


So, provided that you're willing to avoid calling your subroutines __ANON__, you've got a good indication of what your CODE reference actually points to.

Friday, 8 January 2010

Centring Emacs on Screen

Something I've wanted to do for a while that's nevertheless eluded me is how to centre Emacs on-screen when it launches. I'm a bit old fashioned and so like the default 80 character width, but I like as many rows as possible.

At first, with functions like (set-frame-height), (frame-pixel-height) and (display-pixel-height), it seems like it should be trivial, but the problem is that Emacs measures its frame height and width in characters, whereas the pixel functions (obviously) work in pixels.

The link comes in the from of (frame-char-height) and (frame-char-width), which give the height and width of an idividual character in pixels. Just evaluating the following expression should centre Emacs on your primary monitor:


(set-frame-height (selected-frame)
(floor (* 0.95 (/ (display-pixel-height)
(frame-char-height)))))
(set-frame-position (selected-frame)
(floor (/ (- (display-pixel-width) (frame-pixel-width))
2))
(floor (* 0.02 (display-pixel-height))))


If you like this (maybe after some tweaking), you can just stuff the instructions in your .emacs to get it every time.