Planet Linux Australia

Syndicate content
Planet Linux Australia - http://planet.linux.org.au
Updated: 50 min 20 sec ago

Andre Pang: Objective-C Accessors

Tue, 2014-07-08 04: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 04: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 04: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 04: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 04: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 04: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 04: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 04: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 04: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 04: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 04: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.

Andre Pang: Mac Developer Roundtable #11

Tue, 2014-07-08 04:26

The Mac Developer Network features an excellent series of podcasts aimed at both veteran Mac developers and those new to the platform who are interested in developing for the Mac. If you’re a current Mac coder and haven’t seen them yet, be sure to check them out. I’ve been listening to the podcasts for a long time, and they’re always both informative and entertaining. (Infotainment, baby.)

Well, in yet another case of “Wow, do I really sound like that?”, I became a guest on The Mac Developer Roundtable episode #11, along with Marcus Zarra, Jonathan Dann, Bill Dudney, and our always-eloquent and delightfully British host, Scotty. The primary topic was Xcode 3.1, but we also chatted about the iPhone NDA (c’mon Apple, lift it already!) and… Fortran. I think I even managed to sneak in the words “Haskell” and “Visual Studio” in there, which no doubt left the other show guests questioning my sanity. I do look forward to Fortran support in Xcode 4.0.

It was actually a small miracle that I managed to be on the show at all. Not only was the podcast recording scheduled at the ungodly time of 4am on a Saturday morning in Australian east-coast time, but I was also in transit from Sydney to the amazing alpine village of Dinner Plain the day before the recording took place. While Dinner Plain is a truly extraordinary village that boasts magnificent ski lodges and some of the best restaurants I’ve ever had the pleasure of eating at, it’s also rather… rural. The resident population is somewhere around 100, the supermarket doesn’t even sell a wine bottle opener that doesn’t suck, and Vodafone has zero phone reception there. So, it was to my great surprise that I could get ADSL hooked up to the lodge there, which was done an entire two days before the recording. Of course, since no ADSL installation ever goes smoothly, I was on the phone to iPrimus tech support1 at 10pm on Friday night, 6 hours before the recording was due to start. All that effort for the privilege of being able to drag my sleepy ass out of bed a few hours later, for the joy of talking to other Mac geeks about our beloved profession. But, I gotta say, being able to hold an international conference call over the Intertubes from a tiny little village at 4am in the morning, when snow is falling all around you… I do love technology.

Of course, since I haven’t actually listened to the episode yet, maybe it’s all a load of bollocks and I sound like a retarded hobbit on speed. Hopefully not, though. Enjoy!

1 Hey, I like Internode and Westnet as much as every other Australian tech geeks, but they didn’t service that area, unfortunately.

Andre Pang: The Designers of Lua on Concurrency

Tue, 2014-07-08 04:26

I came across the following quote about threads while reading The Evolution of Lua:

… we did not (and still do not) believe in the standard multithreading model, which is preemptive concurrency with shared memory: we still think that no one can write correct programs in a language where ‘a=a+1’ is not deterministic.

That is quite possibly the best one-line summary I have read about why shared-state concurrency is evil. Just say no!

Andre Pang: LittleSnapper and Mac Development Talky Talk

Tue, 2014-07-08 04:26

Four little announcements, all of them Mac-related:



First, myself and my comrades at Realmac Software are very proud to announce the release of LittleSnapper 1.0, our swiss-army-knife picture, screenshot and website organisation utility thingamijiggo. We’ve all worked hard on this for the past few months and sweated over a ton of details to try to make it a polished user experience and be a joy to use; we hope you agree. (You would not believe how long we spent figuring out how the blur and highlighting tools should work before they became their final incarnations, or how much pain was involved when we decided to add FTP and SFTP1 support late in the development cycle.) If you’re a Mac user, give it a whirl; it’s a hard program to describe because it has a lot of different workflows, but between the quick annotation tools, easy Web sharing with QuickSnapper/Flickr/SFTP1, website DOM snapping, and the iPhoto-like forget-about-what-folder-you-need-to-put-your-picture-in snapshot management, I’m sure you’ll find something useful for you in there. Hopefully our hard work can make life just a little easier for you!

1 FTP must die.



I blogged earlier that I was speaking at MacDev 2009 in April, but didn’t mention exactly what I was talking about. Well, the talk abstract’s up now:

One reason for Mac OS X’s success is Objective-C, combining the dynamism of a scripting language with the performance of a compiled language. However, how does Objective-C work its magic and what principles is it based upon? In this session, we explore the inner workings of the Objective-C runtime, and see how a little knowledge about programming language foundations—such as lambda calculus and type theory—can go a long way to tackling difficult topics in Cocoa such as error handling and concurrency. We’ll cover a broad range of areas such as garbage collection, blocks, and data structure design, with a focus on practical tips and techniques that can immediately improve your own code’s quality and maintainability.

So, two sections: first, low-level hackery of the Objective-C runtime. Second, a different kind of low-level hackery, and one that’s arguably far more important: understanding the essence of computation and programming languages, and why I fell in love with both Haskell & Objective-C, two languages at completely opposite ends of the planet.

I’d like to point out that while the MacDev registration fee seems fairly expensive at £399, keep in mind that covers your accommodation and also meals, which easily covers £100-£150. Scotty’s done a lot of organising so that you don’t have to. There’s also a Christmas special on at the moment where a few applications are included in the registration price; check the MacDev 2009 website for details.



If you’re an imsoniac and are having trouble sleeping, you’ll hopefully enjoy a recent Late Night Cocoa episode where I talk to Scotty about Garbage Collection. (Actually, you probably won’t enjoy it so much after you find out exactly how -retain & -release are implemented under-the-hood. The words CFBag and “lock” should hopefully scare you enough.) It’s a bit of a long episode at over an hour and a quarter long, but next time I’ll say “um” a bit less which should shorten it to about half an hour. Have fun. And use GC! (LittleSnapper and RapidWeaver both aren’t GC yet, but you bet your ass they will be for the next major versions.)



I’ve had a pretty long exodus away from the fp-syd user group since I was off getting drunk overseas for about four months. That, of course, meant that somehow my brain was rather misplaced when I arrived back in Sydney, so I decided to give a talk at fp-syd upon my return… on the same day that LittleSnapper 1.0 was due to be released, leaving pretty much no margin for error. Oops. I’ll glad to say that the gusto prevailed, and that both the talk seemed to go OK (well, I wasn’t booed off the stage anyway), and LittleSnapper was released on time. (Just; thanks Alan and Danny!) My talk there was similar to the one I gave at Galois in Portland earlier this year: a whirlwind tour of the Objective-C programming language and Mac OS X technologies for a functional programming audience. In particular:

  • basics of the runtime system,
  • higher-order messaging and its analogy to higher-order functions in functional languages,
  • some details on the engineering marvel that is the Objective-C garbage collector, and
  • (updated!) information on Blocks, LLVM and Clang, and a wee tiny bit of info on Grand Central Dispatch and OpenCL.

I’ve updated the talk with a few extra slides, since Apple have made a little more information to the public now. (In particular, brief information on Blocks, Grand Central Dispatch and OpenCL.) Enjoy all!

Andre Pang: Linux Audio and the Paradox of Choice

Tue, 2014-07-08 04:26

Mike Melanson—a primary author of the Linux Flash plugin, xine, ffmpeg, and a general crazy-good multimedia hacker—on the state of Linux Audio APIs:

There are 2 primary methods of sending audio data to a DAC under Linux: OSS and ALSA. OSS came first; ALSA supplanted OSS. Despite this, and as stated above, there are numerous different ways to do the DAC send. There are libraries and frameworks that live at a higher level than OSS and ALSA. In the end, they all just send the data out through OSS or ALSA.

The zaniest part is that some of these higher level libraries can call each other, sometimes in a circular manner. Library A supports sending audio through both OSS and ALSA, and library B does the same. But then library A also has a wrapper to send audio through library B and vice versa. For that matter, OSS and ALSA both have emulation layers for each other. I took the time to map out all of the various libraries that I know of that operate on Linux and are capable of nudging that PCM data out to a DAC:

Barry Schwartz would be shaking his head, methinks. And yes, I’m well aware of efforts to unify this mess. That doesn’t excuse that this jungle has been the state of Linux audio for the past ten years. I love the comments too: instead of admitting how dumbass this is, they give suggestions for using even more APIs (“try KDE4’s Phonon! That’ll fix everything!”)… totally missing the amusing irony, and also missing the point that Mike needs something that works on as many Linux distributions as possible.

Andre Pang: Justice Kirby on Code as Law

Tue, 2014-07-08 04:26

I found this short article about law and code on builderAU rather interesting. The money quotes are the first and last paragraphs:

Technology has outpaced the legal system’s ability to regulate its use in matters of privacy and fair use rights, said Kirby… “We are moving to a point in the world where more and more law will be expressed in its effective way, not in terms of statutes solidly enacted by the parliament… but in the technology itself—code,” said Kirby.

I think that’s a great quote, and it shows that Justice Kirby has a pretty solid understanding of what code is, how it interacts with law, and that the USA’s Digital Millennium Copyright Act (DMCA)—and Australia’s Digital Agenda Act—are dangerous things. (I do think that the builderAU article emphasis on Google and Yahoo being the two culprits seem odd, although it’s hard to say this without listening to Kirby’s original speech.) I’ve always been a fan of Justice Kirby, and it’s nice to know that somebody-on-high understands that code-as-law is a problem, and it’s a complex one.

Andre Pang: John Romero on Apple and NeXT

Tue, 2014-07-08 04:26

John Romero celebrates the ten-year anniversary of when Apple bought over NeXT:

We were building fat binaries of the tools for all 3 processors in the office - one .app file that had code for all 3 processors in it and executed the right code depending on which machine you ran it on. All our data was stored on a Novell 3.11 server and we constantly used the NeXTSTEP Novell gateway object to transparently copy our files to and from the server as if it was a local NTFS drive. This was back in 1993!

Indeed: even the most modern Windows and Linux development environments today still feel far inferior to the NeXT platforms in many ways. I’m thankful that the superb technology from NeXT lives on to this day: when anyone argues that the object-oriented paradigm has failed, Cocoa is living proof that it can work, and deliver an order-of-magnitude improvement in development productivity. It’s humbling to think that most of the libraries and frameworks that Mac OS X developers take for grated today existed a dozen years ago, before even Windows 95 was around. If you’re not convinced, watch Steve Jobs’s demo of NeXTSTEP version 3 running on a 50MHz cube — in 1991. Windows Presentation Foundation, Glade/GTK+ and Qt Designer look like stone-age tools compared to what NeXT had fifteen years ago.

Andre Pang: Jesus on E's MP4s

Tue, 2014-07-08 04:26

For all the oldskool Amiga demoscene folks out there, I’ve weirdly had a bit of nostalgia for the classic Jesus on E’s demo from 1992. It was was understandably not featured on Mindcandy Volume 2, although there are videos of it on the Web floating around. It’s somewhat amusing that the MPEG-4 video is around 120MB when the original version fit on two 880k disks.

So, I chopped up the MPEG-4 videos I found floating around on the Web, and exported the soundtrack to MPEG-4 audio files so I could throw them onto my iPod. The tracks are available at:

If you’re into oldskool techno and rave tracks from the ~1992 era, you can’t beat this stuff. (And if you don’t like oldskool techno and rave tracks, the soundtrack will probably send you completely insane). Have the appropriate amount of fun!

Andre Pang: Add Cmd-1 and Cmd-2 back to iTunes 7

Tue, 2014-07-08 04:26

iTunes 7.0 removed the Cmd-1 and Cmd-2 shortcuts to access the iTunes window and the equaliser, for whatever reason. You can add them back in via the Keyboard preference in System Preferences:

  • launch System Preferences,
  • go to the Keyboard & Mouse preference,
  • click on the Keyboard Shortcuts tab,
  • hit the + button, pick iTunes as the application, type in “Show Equalizer” as the menu title, and use Cmd-2 for the keyboard shortcut.
  • hit the + button, pick iTunes as the application, type in “Hide Equalizer” as the menu title, and use Cmd-2 for the keyboard shortcut.
  • hit the + button, pick iTunes as the application, type in “iTunes” as the menu title, and use Cmd-1 for the keyboard shortcut.

Done.

Andre Pang: It Gets Better

Tue, 2014-07-08 04:26

Pixar’s latest short film. I’m so proud and honoured to be working with such an amazing group of people.