Planet Linux Australia

Syndicate content
Planet Linux Australia - http://planet.linux.org.au
Updated: 1 hour 24 min ago

Andre Pang: Raganwald on Geek Attitude

Tue, 2014-07-08 05:26

Reg Braithwaite has said very eloquently something I’ve been meaning to express for a long time:

When someone says something outrageous, like “f*ck compilers and their false sense of security”, it is not important whether I happen to think that programming languages with strong, expressive type systems are valuable (hint: I do). What is important is to look at this statement and ask yourself: Is there just one thing in there, one kernel of wisdom that I can extract and use to be a better programmer?

I wrote about geek culture and criticism earlier, but Braithwaite knocks it up a notch and hammers the point home in a single paragraph. To use an analogy, being a good geek is like being a good partner in a relationship… step one: listen. Step two: empathise. (Step three: profit!)

Andre Pang: Quicksilver for Developers

Tue, 2014-07-08 05:26

If you are:

  1. a Mac OS X user,
  2. a coder, web developer, or hacker of some sort (C/C++, Cocoa, Python, Ruby, Web dude(tte),

I just found a mighty good use of Quicksilver that I wanted to share—getting at reference documentation when you’re coding. Now, I hit Cmd-Space to invoke Quicksilver, and then type in, say:

  • NSString to bring up the Cocoa Foundation documentation about the NSString class,
  • sscanf to bring up the sscanf(3) manpage, or
  • dict to bring up the Erlang dict module.

Nice, no?



Quicksilver uses a number of catalogs to create its big list of items that you can search. For example, there’s a Quicksilver plugin that catalogs applications on your hard disk, so that when you start typing iTun, Quicksilver searches the applications catalog to find iTunes. If you start typing in a person’s name, the Address Book plugin has catalogued your Address Book and will search on that.

The neat thing is, you can add your own custom catalogs pretty easily, by indexing text files and HTML files. Quicksilver comes with a File and Folder scanner plugin that you can use to index reference documentation. Adding a custom catalog is easy:

  1. go to Quicksilver’s Preferences,
  2. select the Catalog tab,
  3. select the Custom catalog type on the left-hand pane,
  4. click the + button and pick “File & Folder Scanner”,
  5. add the text/HTML file to be used as a catalog, and
  6. set the “Include Contents” pop-up button in the Inspector pane (the i button in the bottom-right hand corner) to HTML Links or Text Lines, as appropriate.

You probably want to also set Quicksilver to rescan your catalog once in a while: I’ve set mine to rescan every hour.

Here’s some example usage scenarios:

  • Cocoa developers: Add /Developer/ADC Reference Library/documentation/Cocoa/Reference/Foundation/ObjC_classic/index.html as a catalog to index the Foundation kit classes, and /Developer/ADC Reference Library/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/index.html to index the AppKit classes. Now, you can type any class name (such as NSString or NSWindow) at the Quicksilver prompt to immediately bring up the Cocoa documentation in your preferred Web browser.
  • UNIX developers: Install Bwana, which provides a kickass HTML version of your system’s manpages. (It dynamically generates them on demand, so don’t worry, it won’t take up another 100MB of space.) An an aside, Bwana’s the very first manpage viewer I’ve liked besides running man(1) itself in a shell. Run Bwana once and hit the Index button so it can index all the manpages. Add ~/Library/Caches/Bwana/manindex-.html to your Quicksilver catalog, and all of your manpages will now be indexed. Bam, type in printf at a Quicksilver prompt, and behold as all those formatting specifiers you forgot magically appear in your Web browser.
  • Erlang developers: Download the Erlang documentation and keep it somewhere on your local hard disk. Add the doc/index.html file as a catalog, and bam, type in dict to bring up the Erlang dict module functions in your Web browser.

Of course, this works for any HTML documentation, so whether you’re a Java, Python, Ruby, C++ weenie or whatever, just grab some HTML documentation and let Quicksilver index it for you. Bam! (With kudos to Zapp Brannigan, my hero.)

Andre Pang: Pushing the Limits

Tue, 2014-07-08 05:26

OK, this is both ridiculous and cool at the same time. I need to write code for Mac OS X, Windows and Linux for work, and I like to work offline at cafes since I actually tend to get more work done when I’m not on the Internet (totally amazing, I know). This presents two problems:

  1. I need a laptop that will run Windows, Mac OS X and Linux.
  2. I need to work offline when we use Subversion for our revision control system at work.

Solving problem #1 turns out to be quite easy: get a MacBook (Pro), and run Mac OS X on it. Our server runs fine on Darwin (Mac OS X’s UNIX layer), and I can always run Windows and Linux with Parallels Desktop if I need to.

For serious Windows coding and testing, though, I actually need to boot into real Windows from time to time (since the program I work on, cineSync, requires decent video card support, which Parallels doesn’t virtualise very well yet). Again, no problem: use Apple’s Boot Camp to boot into Windows XP. Ah, but our server requires a UNIX environment and won’t run under Windows! Again, no problem: just install coLinux, a not very well known but truly awesome port of the Linux kernel that runs as a process on Windows at blazing speeds (with full networking support!).

Problem #2 — working offline with Subversion — is also easily solved. Download and install svk, and bingo, you have a fully distributed Subversion repository. Hack offline, commit your changes offline, and push them back to the master repository when you’re back online. Done.

Where it starts to get stupid is when I want to:

  • check in changes locally to the SVK repository on my laptop when I’m on Mac OS X…
  • and use those changes from the Mac partition’s SVK repository while I’m booted in Windows.

Stumped, eh? Not quite! Simply:

  • purchase one copy of MacDrive 6, which lets you read Mac OS X’s HFS+ partitions from Windows XP,
  • install SVK for Windows, and
  • set the %SVKROOT% environment variable in Windows to point to my home directory on the Mac partition.

Boom! I get full access to my local SVK repository from Windows, can commit back to it, and push those changes back to our main Subversion server whenever I get my lazy cafe-loving arse back online. So now, I can code up and commit changes for both Windows and the Mac while accessing a local test server when I’m totally offline. Beautiful!

But, the thing is… I’m using svk — a distributed front-end to a non-distributed revision control system — on a MacBook Pro running Windows XP — a machine intended to run Mac OS X — while Windows is merrily accessing my Mac HFS+ partition, and oh yeah, I need to run our server in Linux, which is actually coLinux running in Windows… which is, again, running on Mac. If I said this a year ago, people would have given me a crazy look. (Then again, I suppose I’m saying it today and people still give me crazy looks.) Somehow, somewhere, I think this is somewhat toward the evil end of the scale.

Andre Pang: Parallels Desktop adds Boot Camp, native window support

Tue, 2014-07-08 05:26

Build 3036 of Parallels Desktop has been announced for all you Linux-on-Mac and Windows-on-Mac fans, and it comes with two very cool new features:

  • You can use your Windows XP Boot Camp partition directly in Parallels. No more disk-space-killing installs of Windows XP as a Parallels disk image alongside Boot Camp! This will save me a good 8GB or so of disk space, which is badly needed on a laptop. A side-effect of this is that it should speed up Parallels’s I/O performance, since it now uses a raw block device for its virtual disk access rather than simply using a large file on a partition.
  • Coherency: Shows Windows applications as if they were Mac ones. I’m guessing that Parallels can overtake Windows’s window manager and somehow displays the window as a native Aqua one. There are some pretty cool screenshots of this feature around.

There’s a ton of other cool new features as well. Delicious!

Andre Pang: Insights into AppleScript

Tue, 2014-07-08 05:26

I recently encountered a paper written by William Cook about a mysterious little programming language that even many programming languages researchers don’t know about: AppleScript. Yep, that’d be the humble, notoriously English-like Mac scripting language that’s renown to be slow and annoying more than anything else. The paper is a fascinating look at the history of AppleScript, and details many insights and innovations that were largely unknown. Here’s some things that I was pleasantly surprised about.

Cook had never used a Mac before he was employed to work on AppleScript: in fact, he had a very strong UNIX background, and had a great amount of experience with UNIX shell scripting. So, one can instantly dismiss the notion that whoever designed AppleScript had “no idea about the elegance of interoperating UNIX tools”: a remark that I’m sure many would have made about the language (myself included). Cook even remarks that Apple’s Automator tool, introduced in Mac OS 10.4 Tiger, was quite similar to UNIX pipes:

The most interesting thing about Automator is that each action has an input and an output, much like a command in a Unix pipe. The resulting model is quite intuitive and easy to use for simple automation tasks.

More on UNIX pipes, he writes that

the sed stream editor can create the customized text file, which is then piped into the mail command for delivery. This new script can be saved as a mail-merge command, which is now available for manual execution or invocation from other scripts.

He then continues with something seemingly obvious, but is nevertheless something I have never thought about UNIX scripts:

One appealing aspect of this model is its compositionality [emphasis mine]: users can create new commands that are invoked in the same way as built-in commands.”

Indeed! In a way, the ability to save executable shell scripts is the equivalent of writing a named function to denote function composition in a functional programming language: it enables that composed code to be re-used and re-executed. It’s no coincidence that the Haskell scripts used in Don Stewart’s h4sh project are semantically quite similar to their equivalent Bourne shell scripts, where Haskell’s laziness emulates the blocking nature of pipes.

More on UNIX: Cook later writes that

A second side effect of pervasive scripting is uniform access to all system data. With Unix, access to information in a machine is idiosyncratic, in the sense that one program was used to list print jobs, another to list users, another for files, and another for hardware configuration. I envisioned a way in which all these different kinds of information could be referenced uniformly… A uniform naming model allows every piece of information anywhere in the system, be it an application or the operating system, to be accessed and updated uniformly.

The uniform naming model sounds eerily familiar who had read Hans Reiser’s white paper about unified namespaces. Has the UNIX world recognised yet just how powerful a unified namespace can be? (For all the warts of the Windows registry, providing the one structure for manipulating configuration data can be a huge benefit.)

Cook was also quite aware of formal programming language theory and other advanced programming languages: his Ph.D thesis was in fact on “A Denotational Semantics of Inheritance”, and his biography includes papers on subtyping and F-bounded polymorphism. Scratch another urban myth that AppleScript was designed by someone who had no idea about programming language theory. He makes references to Self and Common LISP as design influences when talking about AppleScript’s design. However,

No formal semantics was created for the language, despite an awareness that such tools existed. One reason was that only one person on the team was familiar with these tools, so writing a formal semantics would not be an effective means of communication… Sketches of a formal semantics were developed, but the primary guidance for language design came from solving practical problems and user studies, rather than a-priori formal analysis.

(There’s some interesting notes regarding user studies later in this post.) Speaking of programming language influences,

HyperCard, originally released in 1987, was the most direct influence on AppleScript.

Ah, HyperCard… I still remember writing little programs on HyperCard stacks in high school programming camps when I was a young(er) lad. It’s undoubtedly one of the great programming environment gems of the late 80s (and was enormously accessible to kids at the same time), but that’s an entire story unto itself…

The Dylan programming language is also mentioned at one point, as part of an Apple project to create a new Macintosh development environment (named Family Farm). ICFPers will be familiar with Dylan since it’s consistently in the top places for the judge’s prize each year; if you’re not familiar with it, think of it as Common LISP with a saner syntax.

AppleScript also had a different approach to inter-appication messaging. Due to a design flaw in the classic MacOS, AppleScript had to package as much information into its inter-application data-passing as possible, because context switches between applications on early MacOS systems were very costly:

A fine-grained communication model, at the level of individual procedure or method calls between remote objects, would be far too slow… it would take several seconds to perform this script if every method call required a remote message and process switch. As a result, traditional RPC and CORBA were not appropriate… For many years I believed that COM and CORBA would beat the AppleScript communication model in the long run. However, COM and CORBA are now being overwhelmed by web services, which are loosely coupled and use large granularity objects.

Web Services, eh? Later in the paper, Cook mentions:

There may also be lessons from AppleScript for the design of web services. Both are loosely coupled and support large-granularity communication. Apple Events data descriptors are similar to XML, in that they describe arbitrary labeled tree structures without fixed semantics. AppleScript terminologies are similar to web service description language (WDSL) files. One difference is that AppleScript includes a standard query model for identifying remote objects. A similar approach could be useful for web services.

As for interesting programming language features,

AppleScript also supports objects and a simple transaction mechanism.

A transaction mechanism? Nice. When was the last time you saw a transaction mechanism built into a programming language (besides SQL)? Speaking of SQL and domain-specific languages, do you like embedded domain-specific languages, as is the vogue in the programming language research community these days? Well, AppleScript did it over a decade ago:

The AppleScript parser integrates the terminology of applications with its built-in language constructs. For example, when targeting the Microsoft Excel application, spreadsheet terms are known by the parser—nouns like cell and formula, and verbs like recalculate. The statement tell application “Excel” introduces a block in which the Excel terminology is available.

Plus, if you’ve ever toyed with the idea of a programming language that could be written with different syntaxes, AppleScript beat you to that idea as well (and actually implemented it, although see the caveat later in this note):

A dialect defines a presentation for the internal language. Dialects contain lexing and parsing tables, and printing routines. A script can be presented using any dialect—so a script written using the English dialect can be viewed in Japanese… Apple developed dialects for Japanese and French. A “professional” dialect which resembled Java was created but not released… There are numerous difficulties in parsing a programming language that resembles a natural language. For example, Japanese does not have explicit separation between words. This is not a problem for language keywords and names from the terminology, but special conventions were required to recognize user-defined identifiers. Other languages have complex conjugation and agreement rules, which are difficult to implement. Nonetheless, the internal representation of AppleScript and the terminology resources contain information to support these features. A terminology can define names as plural or masculine/feminine, and this information can be used by the custom parser in a dialect.

Jesus, support for masculine and feminine nouns in a programming language? Hell yeah, check this out:

How cool is that? Unfortunately, Apple dropped support for multiple dialects in 1998:

The experiment in designing a language that resembled natural languages (English and Japanese) was not successful. It was assume that scripts should be presented in “natural language” so that average people could read and write them. This lead to the invention of multi-token keywords and the ability to disambiguate tokens without spaces for Japanese Kanji. In the end the syntactic variations and flexibility did more to confuse programmers than help them out. The main problem is that AppleScript only appears to be a natural language on the surface. In fact is an artificial language, like any other programming language… It is very easy to read AppleScript, but quite hard to write it… When writing programs or scripts, users prefer a more conventional programming language structure. Later versions of AppleScript dropped support for dialects. In hindsight, we believe that AppleScript should have adopted the Programmerís Dialect that was developed but never shipped.

A sad end to a truly innovative language feature—even if the feature didn’t work out. I wonder how much more AppleScript would be respected by programmers if it did use a more conventional programming language syntax rather than being based on English. Cook seems to share these sentiments: he states in the closing paragraph to the paper that

Many of the current problems in AppleScript can be traced to the use of syntax based on natural language; however, the ability to create pluggable dialects may provide a solution in the future, by creating a new syntax based on more conventional programming language styles.

Indeed, it’s possible to write Perl and Python code right now to construct and send AppleEvents. Some of you will know that AppleScript is just one of the languages supported by the Open Scripting Architecture (OSA) present in Mac OS X. The story leading to this though, is rather interesting:

In February of 1992, just before the first AppleScript alpha release, Dave Winer convinced Apple management that having one scripting language would not be good for the Macintosh… Dave had created an alternative scripting language, called Frontier… when Dave complained that the impending release of AppleScript was interfering with his product, Apple decided the AppleScript should be opened up to multiple scripting languages. The AppleScript team modified the OSA APIs so that they could be implemented by multiple scripting systems, not just AppleScript… Frontier, created by Dave Winer, is a complete scripting and application development environment. It is also available as an Open Scripting component. Dave went on to participate in the design of web services and SOAP. Tcl, JavaScript, Python and Perl have also been packaged as Open Scripting components.

Well done, Dave!

As for AppleScript’s actual development, there’s an interesting reference to a SubEthaEdit/Gobby/Wiki-like tool that was used for their internal documentation:

The team made extensive use of a nearly collaborative document management/writing tool called Instant Update. It was used in a very wiki-like fashion, a living document constantly updated with the current design. Instant Update provides a shared space of multiple documents that could be viewed and edited simultaneously by any number of users. Each userís text was color-coded and time-stamped.

And also,

Mitch worked during the entire project to provide that documentation, and in the process managed to be a significant communication point for the entire team.

Interesting that their main documentation writer was the communication point for the team, no?

Finally, AppleScript went through usability testing, a practice practically unheard of for programming languages. (Perl 6’s apocalypses and exegeses are probably the closest thing that I know of to getting feedback from users, as opposed to the language designers or committee simply deciding on everything without feedback from their actual userbase!)

Following Appleís standard practice, we user-tested the language in a variety of ways. We identified novice users and asked them “what do you think this script does?” As an example, it turned out that the average user thought that after the command put x into y the variable x no longer retained its old value. The language was changed to use copy x into y instead.

Even more interesting:

We also conducted interviews and a round-table discussion about what kind of functionality users would like to see in the system.

The survey questions looked like this:

The other survey questions in the paper were even more interesting; I’ve omitted them in this article due to lack of space.

So, those were the interesting points that I picked up when I read the paper. I encourage you to read it if you’re interested in programming languages: AppleScript’s focus on pragmatics, ease of use for non-programmers, and its role in a very heavily-based GUI environment makes it a very interesting case study. Thankfully, many Mac OS X applications are now scriptable so that fluent users can automate them effectively with Automator, AppleScript, or even Perl, Python and Ruby and the UNIX shell these days.

Honestly, the more I discover about Apple’s development technologies, the more impressed I am with their technological prowess and know-how: Cocoa, Carbon, CoreFoundation, CoreVideo, QuickTime, vecLib and Accelerate, CoreAudio, CoreData, DiscRecording, SyncServices, Quartz, FSEvents, WebKit, Core Animation, IOKit… their developer frameworks are, for the most part, superbly architectured, layered, and implemented. I used to view AppleScript as a little hack that Apple brought to the table to satisfy the Mac OS X power users, but reading the paper has changed my opinion on that. I now view AppleScript in the same way as QuickTime: incredible architecture and power, with an outside interface that’s draconian and slightly evil because it’s been around and largely unchanged for 15 freaking years.

Andre Pang: On D&D and C++

Tue, 2014-07-08 05:26

Quoteth Manuel Chakravarty:

Dungeons and Dragons is the C++ of role-playing games.

Andre Pang: On Civil Debate

Tue, 2014-07-08 05:26

Compare the response given by David Heinemeier Hansson to Alex Payne in the recent Rails and scaling controversy, to Ingo Molnar’s response to Con Kolivas regarding the new Modular Schedule Core in Linux. Which community would you rather be part of based on this little sample?

(Somewhat ironic since it was Hansson himself that said “It’s no[t] the event that matters, but the reaction to it”, as well as being an evangelist for the It Just Doesn’t Matter principle.)

Andre Pang: Objective-C Internals

Tue, 2014-07-08 05:26


Just before I left Sydney, I gave one last talk at the revived Sydney Cocoaheads user group about Objective-C Internals. It’s similar to the presentation that I gave at fp-syd a few months ago about Objective-C and Mac OS X programming, but was tailored for a Mac audience rather than a functional programming audience. As a result, the Cocoaheads talk has a lot more detail on the object model, memory layout, and how message-sending works, and less info on higher-order messaging and language features (e.g. I didn’t talk about categories at all.)

If you’re a Mac coder, hopefully you’ll find something new in there. As always, drop me an email if you have any questions!

P.S. For all the voyeurs out there, the San Francisco move & Pixar are both going great! More news on that soon, too.

Andre Pang: Objective-C 2.0 Accessors & Memory Management

Tue, 2014-07-08 05:26

Quite often, you may have simple setter methods that need to do a just a tiny bit of work before or after setting an instance variable. For example, maybe you need to redraw something after setting the property of an object. So, instead of writing this:

[self setBackgroundColor:[NSColor blueColor]]; [view setBackgroundColor:[NSColor blueColor]];

You’d probably want to move the relevant code to your -setBackgroundColor: accessor instead:

- (void)setBackgroundColor:(NSColor*)color { // Assuming that _backgroundColor is the ivar you want to set if(_backgroundColor != color) { [_backgroundColor release]; _backgroundColor = [color retain]; // Update the view's background color to reflect the change [view setBackgroundColor:_backgroundColor]; } }

Then you can simply call -setBackgroundColor: and expect it all to work nicely:

// -setBackgroundColor: updates the view's background color // automatically now [self setBackgroundColor:[NSColor blueColor]];

(You could use Key-Value Observing to do this, but I generally avoid KVO for simple intra-class property dependencies like this. I don’t think the overhead of maintaining all the KVC dependencies and KVO-related methods is worth the cost.)

Of course, the above method requires that you write all that stupid boilerplate memory management code in the accessor. Instead of doing that, I tend to declare a private _backgroundColor property in the class, @synthesize a method for the private property, and then use the private property’s generated accessors instead:

@interface MyClass () // Declare a _private_ _backgroundColor property (thus the underscore // in front, and why it's declared in a class continuation rather than // in the public header) @property (copy, setter=_setBackgroundColor:) NSColor* _backgroundColor; @end // @implementation MyClass @synthesize _backgroundColor; - (NSColor*)backgroundColor { return [self _backgroundColor]; } - (void)setBackgroundColor:(NSColor*)color { // Use the private property to set the background colour, so it // handles the memory management bollocks [self _setBackgroundColor:color]; [view setBackgroundColor:[self _backgroundColor]]; } ... @end

With that technique, it’s possible to completely directly setting ivars, and thus avoid -retain and -release altogether. (You’ll still need to use -autorelease at various times, of course, but that’s reasonably rare.) We have some source code files that are well over 2000 lines of code without a single explicit [_ivar retain]; or [_ivar release]; call thanks to this technique. (Yeah, 2000 lines is also large and the class needs refactoring, but that’s another story.)

Of course, you could just use garbage collection which avoids 99% of the need for this bollocks:

- (void)setBackgroundColor:(NSColor*)color { // Yay GC! self->_backgroundColor = color; [view setBackgroundColor:self->_backgroundColor]; }

But plenty of us don’t have that luxury yet. (iPhone, ahem.)

Andre Pang: Objective-C Accessors

Tue, 2014-07-08 05:26

I like Objective-C. It’s a nice language. However, having to write accessor methods all day is boring, error-prone, and a pain in the ass:

- (NSFoo*) foo{ return foo;}- (void) setFoo:(NSFoo* newFoo){ [foo autorelease]; foo = [newFoo retain];}

I mean, c’mon. This is Objective-C we’re talking about, not Java or C++. However, until Objective-C 2.0’s property support hits the streets (which, unfortunately, will only be supported on Mac OS X 10.5 and later as far as I know), you really have to write these dumb-ass accessors to, well, access properties in your objects correctly. You don’t need to write accessors thanks to the magic of Cocoa’s Key-Value Coding, but it just feels wrong to access instance variables using strings as keys. I mean, ugh—one typo in the string and you’ve got yourself a problem. Death to dynamic typing when it’s totally unnecessary.

As such, I got totally fed up with this and wrote a little script to generate accessor methods. I’m normally not a fan of code generation, but in this case, the code generation’s actually designed to be one-shot, and it doesn’t alter the ever-picky build process. It’s meant to be used in Xcode, although you can run it via the commandline too if you like.

Given the following input:

int integerThing;NSString* _stringThing;IBOutlet NSWindow* window;

It will spit out the following:

#pragma mark Accessors- (int) integerThing;- (void) setIntegerThing:(int)anIntegerThing;- (NSString*) stringThing;- (void) setStringThing:(NSString*)aStringThing;- (NSWindow*) window;- (void) setWindow:(NSWindow*)aWindow;%%%{PBXSelection}%%%#pragma mark Accessors- (int) integerThing{ return integerThing;}- (void) setIntegerThing:(int)anIntegerThing{ integerThing = anIntegerThing;}- (NSString*) stringThing{ return _stringThing;}- (void) setStringThing:(NSString*)aStringThing{ [_stringThing autorelease]; _stringThing = [aStringThing copy];}- (NSWindow*) window{ return window;}- (void) setWindow:(NSWindow*)aWindow{ [window autorelease]; window = [aWindow retain];}

There’s a couple of dandy features in the script that I find useful, all of which are demonstrated in the above output:

  1. It will detect whether your instance variables start with a vowel, and write out anInteger instead of aInteger as the parameter names for the methods.
  2. It will copy rather than retain value classes such as NSStrings and NSNumbers, as God intended.
  3. For all you gumbies who prefix your instance variables with a leading underscore, it will correctly recognise that and not prefix your accessor methods with an underscore.1
  4. IBOutlet and a few other type qualifiers (__weak, __strong, volatile etc) are ignored correctly.
  5. It will emit Xcode-specific #pragma mark places to make the method navigator control a little more useful.
  6. It will emit Xcode-specific %%%{PBXSelection}%%% markers so that the accessor methods meant to go into your .m implementation file are automatically selected, ready for a cut-and-paste.

Download the objc-make-accessors script and throw it into your “~/Library/Application Support/Apple/Developer Tools/Scripts” folder. If you don’t have one yet:

mkdir -p ~/Library/"Application Support"/Apple/Developer Tools/Scripts/10-Scriptsln -sf "/Library/Application Support/Apple/Developer Tools/Scripts/10-User Scripts/99-resetMenu.sh" ~/Library/"Application Support"/Apple/Developer Tools/Scripts/10-Scripts/cp ~/Desktop/objc-make-accessors ~/Library/"Application Support"/Apple/Developer Tools/Scripts/10-Scripts/

Done. You should now have a Scripts menu in Xcode with a new menu item named “IVars to Accessor Methods”. Have fun.

1 Note that older versions of the Cocoa Coding Guidelines specified that prefixing instance variables with underscores is an Apple-only convention and you should not do this in your own classes. Now the guidelines just don’t mention anything about this issue, but I still dislike it because putting underscores every time you access an instance variable really lowers code readability.

Andre Pang: Neverwinter Nights 2 Is Here

Tue, 2014-07-08 05:26

Well, it seems that Neverwinter Nights 2, Obsidian1’s next kick-ass roll-playing game, is out in the USA. Unfortunately, it’s been delayed in Australia until November the 16th. Whaaaa? That’s… like… next year! Muaahaha, thankfully I’ve managed to wrangle some contacts and download the thing from Direct2Drive, so I’ve been gleefully playing it for the past few nights. Well, OK, make that the past few days, nights, and early mornings…

First impressions are good, although the game engine isn’t particularly medal-worthy: Obsidian could use some better game engines programmers, that’s for sure. It’s not in the same league as Oblivion, for instance. The user interface also isn’t quite up to NWN1 standards. However, the spell effects do look very pretty, and more importantly, the story looks quite promising, and possesses the same moral and ethical ambiguity that is the hallmark of Obsidian games. None of this bozo so-obvious black-and-white good-vs-evil crap. (Mind you, I’m playing a slightly evil character at the moment — slaughtering the Neverwinter City Watch might be somewhat evil… but it is so much fun. Besides, the Watch is weak and not doing its job, so I don’t see anything wrong with the Thieves’ Guild controlling the city streets since they actually have the resources to maintain peace and order better than the Watch. Just ensure the local shop keepers pay their taxes to the Guild and everyone’s happy… )

It also looks like an even more hackable game than the original NWN, although I’m unhappy with the toolset using the same dock-o-rama type of user interface that Visual Studio is famous for. Dockable windows are OK, but I still think it’s far inferior to using multiple windows and a decent window management tool such as Exposé. Still, it took me about 30 minutes to write some small chea… uhh, scripts, to help with some in-game things.

So far I’ve probably pumped about 20 to 30 hours into the game, and I think I’m about 3/4 of the way through Chapter One, with there being three chapters in total. If I don’t reply to any emails for the week or two, uhhh, I guess you know what I’ll be doing!

1 Obsidian are makers of the best computer role-playing games in existence, end of story. (None of this World of Warcraft or Final Fantasy VII crap, thank you very much.) If you disagree with me on this, that’s OK, I’m not really into Pokemon anyway.

Andre Pang: Welcome!

Tue, 2014-07-08 05:26

Welcome to the new-look Algorithm.com.au, redone from scratch. I’m now using RapidWeaver to do the web site rather than my 5-year-old installation of Movable Type; thank you MT, you served me well for that time! All my old blog entries have been imported across, although the URLs for the entries have all changed, sorry.

Apart from the obvious look’n’feel changes to the blog, I’ve finally put all my mixes online in the Music section, and added a small section on the code that I’ve released. (It’s not much code, so don’t be too disappointed when you visit there — but there’s lots more coming in the future!) So, have a look around if you’re bored, kill some time, and have the appropriate amount of fun.

Andre Pang: Yay, New Computing Books

Tue, 2014-07-08 05:26
So now that I'm back from my f*ck-off-awesome trips to Melbourne and New Zealand (more on that later when I get a chance to blaerg about it), I am greeted with the following lovely selection of books from amazon.com:







I guess I'll be doing some bedtime reading for the next few weeks. (Note that I'm not actually a games programmer by trade—nor really a C++ programmer these days—but games coding tends to have interesting constraints such as high performance and memory management, which encourages a much better understanding of lower-level problems.) I'm a little of the way through Refactoring to Patterns, and it's great so far.



In other news, I think these three books in a row fit the definition of Alanic rather well:







Seriously, I didn't move 'em next to each other or anything. I especially love it how Java in a Nutshell looks like it's about 1,000 pages. Nutshell my arse.

Andre Pang: Nettwerk Records vs RIAA

Tue, 2014-07-08 05:26

Canadia’s largest independent record label is litigating against the RIAA on behalf of consumers: schweet. (I personally like Nettwerk since they’re the home of some of my favourite artists: Sarah McLachlan, Dido, and the Barenaked Ladies.)

Andre Pang: Mutable State as Manual Memory Management

Tue, 2014-07-08 05:26

An engaging quote from Paul Johnson, from the January 9, 2007 issue of Haskell Weekly News:

Mutable state is actually another form of manual memory management: every time you over-write a value you are making a decision that the old value is now garbage, regardless of what other part of the program might have been using it.

My little theory: there is no reason to ever change the value of a variable except for efficiency. Instead, make a new immutable variable based on the old value, which gives you freedom to name your new variable to better describe what it does. My C and C++ code is littered with const almost everywhere, and it helps enormously when you look back at the code a month later to figure out what it’s doing.

And, just to throw in a little more Haskell evangelism from someone else who’s merrily had their brain reconfigured to to see the awe of the lambda calculus:

So far I’ve written about 300 LOC replacing about 1500 LOC of a system written in Perl… The thing that totally, utterly blows my mind is that I’ve done all this without any loops and using only 3 conditional statements. (One if and two case, if it matters. And I don’t mean this in the cheap sense that Haskell doesn’t have any looping constructs and so I’m writing recursive functions instead, which everyone knows is the same thing. There is no explicit recursion in my code. I’m just flabbergasted.

Andre Pang: Movable Type's Export File Format

Tue, 2014-07-08 05:26

Here are a short list of things that possess more elegance than Movable Type’s export file format:

  • XML,
  • SMTP,
  • the C string API,
  • the C multibyte string API (mbsinit, wcrtomb, mbsnrtowcs, etc),
  • the C++ grammar specification,
  • C++ template error messages,
  • the BIND zone file format,
  • Bourne shell parameter expansion involving spaces,
  • PHP,
  • CSV,
  • GNU libtool,
  • wGetGUI,
  • POSIX regular expressions,
  • MPEG-7,
  • the mplayer code base,
  • the Cisco VPN client,
  • the ld(1) manpage on the UNIX system of your choice,
  • the sudoers(5) manpage,
  • Makefiles generated by GNU autogoats,
  • Eric S. Raymond,
  • ICCCM,
  • pretty much everything.

Feel free to extend this list in the comments.

Andre Pang: Merry Christmas!

Tue, 2014-07-08 05:26

It’s been an introspective journey this year. But at least I have a new web site! Woo baby!

Here’s a public thank you to all my family and friends for always being so supportive, and all my workmates at Rising Sun Research and Rising Sun Pictures for a wonderful working environment and teaching me a ton about software development (as well as contributing so much to some awesome movies).

2007 is looking good already. See some of you kids at Linux.conf.au in January! (You are going, right? If not, why not?)

Merry Christmas everyone, and have a safe, relaxing and happy end-of-year holidays to bring in 2007!

Andre Pang: For the Mac Vim lovers

Tue, 2014-07-08 05:26

Do you like Mac OS X?

Do you like… Vim?

If so, your prayers may just have been answered: see the Vi Input Manager Plugin by Jason Corso. Vi-style key bindings in any Mac OS X text input area? Schyeah baby. As Jason says:

Right now, you should be thinking — “you mean the editor in XCode will behave like Vi?” Answer: Yes.

It’s open source too. Nice work Jason; let the hacking begin!

Andre Pang: Mac OS X Software List Updated

Tue, 2014-07-08 05:26
I've finally updated my Mac OS X software list to be Leopard-aware, for those of you new to Apple's shiny little operating system. Spotting the changes between the older version and newer one is left as an exercise for the reader :-). (Boy I'm glad to have TextExtras working with garbage-collected applications on Leopard!)

Andre Pang: Mac OS X Software for the Uninitiated

Tue, 2014-07-08 05:26

I have a lot of friends who’ve switched to Mac OS X from both Windows and Linux in the past few years. I think it’s a good computing platform (duh, otherwise I wouldn’t be using it), but of course it can take a while to find all those handy little bits of software that make life just a bit easier.

So, since I’m a lazy bastard and got sick of regurgitating my list of Mac OS X software to switcher friends in the past few years, I finally made a Mac OS X Resources page with a list of software that I personally use and think kicks ass. There’s also a (small) collection of hints and tips, including some coding tips for those moving across from Linux. (I’m aware that the coding tips really are quite sparse — I’ll hopefully find some time to expand that in the future.) I hope the resources page is useful for someone else out there: if you do find it useful, a very simple one-line email saying thanks is always appreciated! As Larry Wall would say, have the appropriate amount of fun.