TVML explorations

So you looked at Apple’s very brief example of how to set up a TVML app. What’s next?

First, a side note: if you jump into TVML expecting a general UI framework, you’ll be disappointed. TVML is a toolkit for making backend-driven media players and storefronts that look basically like Apple’s. If you want to do anything else, you’ll probably want a native app.

This post is more about hosting TVML and TVJS than TVML itself. It looks at:

  • Communicating between native code and TVJS, including asynchronously
  • Not using the web for everything
  • How do you handle events in an XML page anyway?

Continue reading

Posted in Cocoa, Code | 1 Comment

Death to printf()

A couple of weeks ago, Jean-Francois Roy twote:

Actually, there’s a conceptually simple win: don’t let your format strings determine the byte-level interpretation of data. Especially without bounds.

I mean, duh. Who’d do something so obviously stupid? Well, unfortunately, the C standard library does, and its example has been followed all too many times. I contend that printf()-style formatting is broken and its use should be considered a bug.
Continue reading

Posted in Cocoa, Code | 1 Comment

Imitating Greateness: 16-bit Hack ALU Design in Minecraft

In the autumn of 2010, a video of a sixteen-bit ALU in Minecraft by theinternetftw went viral. A month later, I’d bought the game, played around with circuits a bit and published a detailed description of a functionally identical (but much smaller) ALU on the Minecraft forum – although not exactly in that order.

Due to changes in the Minecraft forum you can now only read the original thread if you’re logged in, and the formatting is messed up, so I’m reposting it here.

By functionally identical, I mean that my ALU has the same instruction set as theinternetftw’s – the Hack instruction set developed for the book The Elements of Computing Systems. I haven’t read the book, but there’s enough information available online to implement the ALU and most other components.

I didn’t copy any part of theinternetftw’s implementation, but I did use pre-existing XNOR gates and adders as noted in the text.

Minecraft is a moving target, but the ALU still works perfectly (and performs much better). If I built it today, I’d consider using repeaters for the data and control busses, but probably stick with torches because repeaters still aren’t implemented in Redstone Simulator. (Repeaters are simpler, and also give you a signal speed of 18 blocks per cycle if you use them well. Torches can do 17, but only 16 in tightly packed parallel busses.)

Some references:

Original posts follow. They’re largely unedited, so they reflect the evolution of the ALU.

Continue reading

Posted in Minecraft | Tagged , , | 2 Comments

Almost elegant cave man debugging

Recently, the Twitternets pointed me at Vincent Gable’s blog post, The Most Useful Objective-C Code I’ve Ever Written. It is indeed quite useful; given a semi-arbitrary expression, it prints out the value, using @encode() and macros to minimize drudgery.

Continue reading

Posted in Cocoa, Code | Tagged , | 8 Comments

Proposal: generics (and some other stuff) for Objective-C

Some time ago, Greg Parker asked the Twitternets what we’d like to see in a purely hypothetical Objective-C-without-the-C language. Someone — I believe it was Landon Fuller — pointed at an article about the Strongtalk type system for Smalltalk. I quite like the idea of Objective-C-without-the-C (i.e., a language that is native to the Objective-C object system and runtime without the baggage of C), but after reading that article I found myself asking why we couldn’t do something similar in Objective-C.

I don’t think my random musings have much influence on the design of the language, but if I don’t write it down nobody’s going to know how nuts I am, so here’s a semi-concrete proposal for contextual types and generics for Objective-C. Since anyone even mentioning generics in the vicinity of Objective-C will inevitably be flamed for trying to turn it into C++, this is followed by an aside entitled Why This is Not the Baby-eating Spawn of Bjarne Stroustrup. (Nothing personal, Bjarne.)

Continue reading

Posted in Cocoa, Code | Tagged , , , , , | 10 Comments

Multi-type Save Panel Controller

As a change of pace, I thought I’d post some code that doesn’t go out of its way to be bad.

JAMultiTypeSavePanelController is a class (abstracted from ImageIO Export for Acorn) to handle the case where you want to offer the user a choice of formats to save in.

Save panel
Continue reading

Posted in Cocoa, Code | 1 Comment

Wanted: a Right-Handed Keyboard

My current keyboard looks like this:

Left-handed keyboard: keypad on right, empty space on left.

(Well, roughly. It actually looks like this, but I couldn’t find a decent-resolution Swedish one.)

This was a sensible design for the right-handed majority when it was introduced, some time in the stone age. However, since then, something quite important has happened: the keyboard has been joined by another input device, which I suspect is used more than the keypad by most people who are not cursed with an Excel-dominated career.

Continue reading

Posted in Hardware | 5 Comments

Constant objects for fun and non-profit

The @"foo" operator for constant NSString objects in Objective-C is extremely convenient. Indeed, if it wasn’t there, programming with Cocoa would be a royal pain. Many of us have at various points wished there was equivalent syntax for NSNumbers, and possibly collections.

As an early Christmas present to fellow lovers of twisted, evil code that should never have seen the light of day under any circumstances whatsoever, I hereby present an implementation of the first half of that wish.

Continue reading

Posted in Cocoa, Code | Tagged | 3 Comments

Fun with the Objective-C Runtime

Ever since Leopard came out, I’ve wanted to do something useful with resolveInstanceMethod:. The opportunity has yet to present itself. However, I have done a couple of really silly things with it, which have until now languished in obscurity in the depths of So here they are. Continue reading

Posted in Cocoa, Code | Tagged | 4 Comments

Migratory Code

Of the two people I know of who have tried to get at some of my code releases in the past year, a full 50 % have given up and written a new implementation from scratch because downloading and opening a zip file is too much work (as is actually complaining to someone who can fix it). On top of that, some form of version control is good to have, and my local set-ups keep breaking when I do silly things like getting a new computer or installing a new OS. So now most of my released code lives at Google Code. Yay and stuff.

Specifically, the projects in question are:

For information about the various code bits and bobs, see here.

I fully expect that the next person who tries to grab some of my code will find it to onerous to dig through the subversion repo. To that person, my message is: tough.

Posted in Code | Tagged , , | Leave a comment