Archives for October 2007

Apple crumble

As most of my friends know my resolve not to buy some Apple related thing that I want rarely lasts 24hrs and never the week. Last time round it was a Mac mini. As it happens it was fortuitous that I did buy it because it bridged the gap while I waited for my new MacBookPro and is now doing sterling service as a media centre and development server.

This time round it's Leopard. I had decided to wait for my friend Bethlet who is visiting the UK in November (yay!) to bring a copy over for me, thus avoiding Apple's I live in the UK tax. Then a few days ago the crumbling began as I read John Siracusa's review and got all dreamy about CoreAnimation and it's kin. Many others came forward to tempt me.

However... be shocked... I have, against all odds, held out. I'm still planning to wait for November for Leopard and might still hold off on 10.5.1 before installing. Could I be less bleeding edge?

On the other hand maybe I'll go break my credit card on an iPod touch tomorrow ;-)

31/10/2007 23:18 by Matt Mower | Permalink | comments:

Scripting a better 'cd' and then some

This is a somewhat long winded tale about how I came up with a way to type gprails expr and have a bunch of iTerm tabs open in a project folder matching expr with each tab starting one of mongrel, textmate, tailing of different logs, script/console, and so on. Skip to the end if you just want the script...

I don't know about you but I sometimes think I am collecting programming projects. I have folders and folders of them, for different languages, frameworks, backup copies, open source stuff, branches, what a mess.

So like my Rails projects are in:

/Users/matt/Projects/rails/myproject

or

/Users/matt/Projects/rails/project/branch

but some of them are related to my current company and they are in:

/Users/matt/Projects/topsecret/project

with Ruby stuff in:

/Users/matt/Projects/ruby/apps/project

and so on.

Most of my current activity is related to developing a Rails application. Every time I start work I go through a routine like this:

  • Open iTerm
  • cd to the project folder
  • start TextMate
  • start Diffly
  • start mongrel
  • open a new tab
  • cd to the project folder
  • clear the logs
  • start a tail on the development log
  • open a new tab
  • cd to the project folder
  • start a tail on the request log
  • open a new tab
  • cd to the project folder
  • ....

All those cd's get old fast even with copy & paste.

I've tried various solutions based on aliases, scripting find (this was difficult because find seemingly has no way of halting after the first match), and hard coding paths. All were workable but messy and frustrating. What I wanted was a cd command that would know about the structure of my projects folder and just do the right thing.

A couple of days ago I caved and wrote a ruby script that first indexes my project folders to a specified depth ( weeding out useless stuff like ".svn" folders and so forth) and then searches for a specified substring. If more than one match was found it presents a list of matches and allows me to select the one I want.

Then I hit another snag. There was no way for this ruby process to affect the working directory of the terminal that owned it. I considered writing a shell script to take the output of the ruby script but this wouldn't work if you needed to print out the list of matches to choose from.

That's when Defiler suggested I try scripting iTerm with RubyOSA. It was a neat idea, have the Ruby script using an AppleEvent to tell iTerm to write the "cd" command into the terminal. Except that the terminal would be running a ruby process which would eat the input. Bah!

Still, it was a good idea, and I could live with opening a new tab I guess. So I consulted the Script Dictionary for iTerm and came up with an AppleScript that opened a new terminal tab and changed to a specified directory. Nearly home.

Except RubyOSA absolutely would not play ball with iTerm. Or vice verca. According to RubyOSA all the cool methods for finding the current terminal, making new sessions, and so on were in a class OSAITermApplication but the only thing I could get a reference to was OSAIterm and there appeared to be no way to get from one to the other.

Then Has pointed me at Ruby Appscript which is another bridge to AppleScript that works hard to make even difficult apps like iTerm behave normally w.r.t. AppleScript. He gave me a simple demo and I was able to extend that to do what I needed.

Now I had a script which I called gp for (Goto Project) that would, based on a search expression, open a new tab in the correct folder. Or, if more than folder matched, present me with the choices, let me choose, then open a new tab in the correct folder. Then I added a parameter to say how many new tabs to open so I could get all 5 that I needed at once. This was cool.

Then it occurred to me, why stop at opening a terminal? Now I had a means to run any command in a terminal window I could have it do everything. So I added a simple scripting facility. Here is my rails script:

mate .; diffly .; mongrel_rails start
rake log:clear; tail -f log/development.log
tail -f log/request.log
ruby script/console
irb
#

Each line is executed in it's own terminal. This opens the project source in Textmate, opens the current svn diff in Diffly, starts mongrel, clears the developer log and opens the two logs I care about, then gives me a console and an irb session, plus a spare terminal in the right directory.

Scripts live in a .gp folder in the projects folder alongside the index of project folders. I modified gp to check on the filename used to run it and automatically run a script based on the prefix so:

ln -s /Users/matt/bin/gp /Users/matt/bin/gprails

means I can type:

gprails myproject

and have it do all of the above in the right folder for myproject. I'll probably write a script for working with Cocoa projects too.

I've no idea if this is of any interest or use to anyone else but it's a nice solution for me and if you're interested in scripting iTerm it might be a good place to start from. My 'gp' script is here.

If you decide to play with it you'll want to change where it looks for projects unless you use ~/Projects like I do. Also the first time you run it it will build the index of project folders and write a default rails script for you but you'll want to modify that script unless you use the exact same combination of commands that I do.

Enjoy.

31/10/2007 20:13 by Matt Mower | Permalink | comments:
More about:

I see spots

I had been holding out for 10.5.1 before going to Leopard but, after reading John Siracusa's excellent review for Ars Technica, I'm rethinking that. I may pay the I live in the UK tax and buy Leopard tomorrow.

Although I have run several of the seeds over the last few months I've never installed Leopard as my day-to-day OS. Siracusa paints a compelling feature of, across the board, improvements to the core OS with few if any new bugs.

His most savage broadside is reserved for the visual changes to Leopard mostly around the dock and menubar. I agree with both but I've disliked the dock more or less since the day I started using MacOSX and, for that reason, have never bothered much with it, settling instead on the Finder sidebar and Quicksilver for most of my navigational needs.

For example I never bothered putting folders in the dock. For the same reason the stacks, and their problems, are a non-event for me.

Now that I can be sure the dock won't be a hideous eyesore on my screen I am content. I am sure that there will be enough complaint about the menubar that an option to remove translucency will appear before too long. I love Siracusa's sentiment though:

"Don't force me to use the Dock, and I promise I'll stop actively hating it."

Amen to that. Legalizaling Dock replacements would be a great step forward in my opinion. Oh, another gem from that review:

"Apparently the super-secret technology that enables adjustable grid spacing has finally been rediscovered at Apple, presumably in a huge warehouse filled with identical-looking crates of classic Mac OS technology. "

What I'm looking forward to is getting stuck into the new XCode, Interface Builder, and Cocoa frameworks. I've held off starting any new MacOSX projects until I can use and target Leopard. I'm also looking forward to having the more refined experience with improvements to the terminal, the bundled ruby (including DTrace probes!), and so forth.

Yes I guess my resolve is crumbling...

29/10/2007 13:13 by Matt Mower | Permalink | comments:
More about:

Our survey said...

I just watched two ad's for the Ron Paul 2008 presidential campaign for (I guess) the New Hampshire primary:

I watched the second ad first. Then I watched the first ad.

The first ad shows a lot of fake seeming (or very uncomfortable) folks "chatting casually about Ron and his policies" and is, because of this, somewhat grotesque.

The second ad, just Ron talking about his policies. You can't say much in about a minute but I think that what he says makes sense. What's also noticable is that the only thing he says about his fellow candidates is that there are some. He spends the rest of his time giving a brief precis of what he would do as president.

Ron: more of these types of ad. Either that or get more convincing people to talk about how they'll vote for you.

29/10/2007 10:32 by Matt Mower | Permalink | comments:
More about:

I love the sound of the Ocean Waves

I just registered an app called OceanWaves by Katsura shareware. It cost me about £6 inc VAT.

It's a pink and brown noise generator with wave-like amplitude modulation. In other words it sounds like ocean waves breaking on a sandy beach. It's a sound that I love.

I've tried other software for generating background noise and OceanWaves is the best so far. So good in fact that it's become my constant companion the last ten days or so helping me stay in a flow state and working away on my current project.

One day I hope to have an office where I don't need a generator to hear the ocean. Until then, I recommend OceanWaves.

27/10/2007 22:59 by Matt Mower | Permalink | comments:
More about:

Much better

I probably won't be getting Leopard for a few days to a few weeks but when I do one of the things I wasn't looking forward to was the new dock.

I've tried it and I hate and despise every pixel of it. No need to rehash the arguments and if you like it, well... more power to you. But I'm overjoyed to find an item on Daring Filreball showing you how to get rid of the reflective, glassy, 3D horror:

defaults write com.apple.dock no-gass -boolean YES
killall Dock

This turns the dock into something of a hybrid of the Tiger and Leopard docks. It loses the rubbish 3D effects and turns it into a kind of smoky glass translucent Tiger dock. The net effect is that it looks less hideous and the the running lights actually have enough contrast to show up.

All in all I'd say it's a huge improvement.

Update: Aha, reading a later item I see that the shipping Leopard already ditches the crappy 3D effects on the Dock when it's placed on the side of the screen (which I always do anyway).

26/10/2007 16:08 by Matt Mower | Permalink | comments:
More about:

Not interested... because

The Amazon store has come quite a long way and, these days, the "Matt's store" routinely offers me books I would quite like to buy. However it's still a long way from useful to me.

The reason is that it very often recommends me a slew of books that are similar to the books already in my pile of unread books. "I don't want more like them yet," I think. But I can't say "Not interested" to Amazon because they are interesting.

Similarly for many books like "Introduction to Algorithms." Well I have a whole bunch of algorithms books. The one you recommended isn't interesting but that doesn't mean I'm not interested in algorithms.

In short the two controls "I own it" and "Not interested" aren't discrete enough. I need to be able to say "Don't show me books like this for a few months" or "Not interested in this book but don't weight the category."

I have no idea how to feed this back to the right parties at Amazon so I record it here.

25/10/2007 12:02 by Matt Mower | Permalink | comments:
More about:

Nice video, but what is Seesmic?

Euan points to Lloyd Davis playing Uke on Loic's new app Seesmic.

Okay, I enjoyed the song, but I don't understand Seesmic. It seems to be YouTube minus any of the other stuff YouTube does. Is that the point? Are we back to "just the video" minimalism? It would, at least, be nice to see links to other stuff Lloyd has done.

22/10/2007 09:01 by Matt Mower | Permalink | comments:

When you have shot and killed a man

"When you have shot and killed a man you have in some measure clarified your attitude toward him. You have given a definite answer to a definite problem. For better or worse you have acted decisively. In a way, the next move is up to him." -- [R. A. Lafferty]

19/10/2007 16:51 by Matt Mower | Permalink | comments:

Getting the background right

Okay a little problem I am working on. I'd be grateful for advice about a good way to proceed. Here is the situation.

  • In our service we will have clients invoke a browser bookmarklet to send us some data.

  • This data will be processed by a 3rd party service that will, after some variable delay, come up with results.

  • While the client is waiting they should see some nice "Things are happening page"

  • When the results are available from the 3rd party service we need to massage them ready for the client.

  • The client's bookmarklet page then updates with the results.

In the old days I would have used Backgroundrb for this. But I'm using Rails 2.0PR and I've no idea if the old fella is compatible. Also I am told that even Ezra himself advises against using it.

When I started to think about it though I'm not sure Backgroundrb would have been the right approach. I mean, I don't really want threads hanging around for the 3rd party to respond and it's not necessary when the client is polling anyway. So we've redesigned the approach to have the 3rd party send results asynchronously. This eliminates a thread-bottleneck at our end.

Now the question becomes "Where do those results live?" Four alternatives have been suggested to me:

AppCast is, I think, loosely based on Amazon SQS but uses REST (via a Mongrel handler) as it's interface and ActiveRecord for handling messages.

There's a lot to like about this approach but AppCast is more or less completely undocumented and it's not clear to me that it's intended for use by anyone outside ActiveReload at this point. Also I'm not keen on using ActiveRecord/SQL.

ActiveMQ & RabbitMQ will probably do what I need but they also do a whole lot more that, right now, I don't think I do or will need. In essence what I am looking for is a distributed hash. Using a message queue seems like swatting a fly with a Buick. However they have the advantage of being actual products so I guess they install and run.

CouchDB is an Erlang based non-relational document database. It's essentially a hashtable server that offers replication. It's probably ideal for my purposes however it's totally alpha level software with lots of pictures of landmines and skull & cross-bones all over the place. I'd probably have to be crazy to be thinking about using it for a production service. If I was crazy like that I'd probably front it with a mongrel handler to do the client polling and 3rd party API callback.

Mnesia is an Erlang based distributed database. Being designed for always-on telecomms apps Mnesia is robust, production ready, software. Using something like Erlectricity I could probably use it from a Ruby mongrel handler.

All these approaches might work and might scale. But none appears as an obviously best solution.

All ideas, opinions, and suggestions welcome.

19/10/2007 13:12 by Matt Mower | Permalink | comments:
More about:

MacOSX: now with time travelling

You didn't realize did you? Didn't know that you don't have to wait for Leopard to get time travel with MacOSX...

The last week or so my new MacBook Pro has been traveling forward an hour into the future. But, it being me, instead of stock tips or racing results I get to turn up to karate an hour early.

Like a few minutes ago my clock in the menu bar was reading 11:47. Okay that's not good... now I have to rush to make my appointment at the gym. I can't remember exactly what time that is so I go grab my phone which has the appointment. But my phone, apparently having a better grasp on reality, tells me it's 10:47.

When I click "Open Date & Time" the clock immediately switches back to the right time. Just like it did yesterday afternoon, and again the day before. Here's my "date & time" configuration:

and "time zone":

As far as I can tell everything is configured right (I was using the US time servers and changed that to Euro, no difference) the clock just seems, whenever it feels like it, to skip forward an hour. Probably it resets itself when you open the preferences because it polls the time server again.

Does anyone have any idea why this is happening? How to stop it? It seems pretty trivial but, in practice, the clock on my laptop - being right in front of me - is the clock I depend upon most often (also for iCal alarms).

18/10/2007 11:00 by Matt Mower | Permalink | comments:
More about:

Well this sucks

So Leopard is available for pre-order in the US, from Amazon, for $109. According to xe.com that makes it about £53. Yet it isn't available for pre-order on Amazon UK (that I can see) and the price from the Apple Store is £85.

Why am I paying £32 (thats about $65) more for Leopard?!

Update: In comments Ben has pointed me to where Amazon UK are now selling Leopard for pre-order at a staggering discount of £5!

17/10/2007 11:55 by Matt Mower | Permalink | comments:
More about:

All ahead slow... very slow

The problem with big companies attempting to do this sort of thing is that they always make one fatal mistake: they think that they need to have upper management (or rather, any member of management) vet the ideas before greenlighting them.

The problem here is that innovation really just involves making lots of bets, essentially random ones, and then nurturing the ones that take off. Executives think they can somehow take a bunch of ideas, look over them, and somehow spot the winners. That's totally wrong. If any human being could do that, venture capital would be a zero-risk investment. The key thing that everyone misses is that NO ONE can predict what's going to work, and the only way to grow the next big thing is to just let your people have at it, failing 95% of the time (a failure rate unacceptable at large companies), and hitting a home run 5% of the time.

A comment by Davion on a thread about Yahoo being sunk by beauracracy.

16/10/2007 15:40 by Matt Mower | Permalink | comments:
More about:

I swear

Here is a Web2.0 service I would really like. You've seen Mango? Mango is an online service for helping you learn languages. It takes you back and forth between English and your choosen language with a built in pronounciation guide. It seems quite nice but it's not exactly what I want.

What I most want is an online service to teach me how to swear properly in foreign languages. I'm talking about everything from common cursing to real profanity -- the kind that can get you in to trouble in a bar or your mothers house (assuming your mother speaks Mandarin or Hindi).

It needs, like Mango, to have built-in pronounciation so that you get it right. A decent choice of languages would be a plus. Does such a service exist already?

15/10/2007 19:19 by Matt Mower | Permalink | comments:
More about:

Take no prisoners

Here is a video of a lethal apache gunship attack from BattleSeen.com which is a new video sharing site for the military.

In the video clip you clearly see the gunship target and pour down devastating fire, one by one, on three infrared figures designated as insurgents. At the end they deliberately finish off a man who can be seen writhing on the ground after an earlier burst of fire. I would say it was a miracle he survived that first burst but it seems inappropriate given what happens to him a few seconds later.

The video is chiling. The "ho hum" tone of the gunnery as they wait for movement and then unleash the apache's cannon. The devastation that follows the fractional burst of 30mm cannon rounds. The eerie sight of people living and dying in a world of heat imagery.

I've no reason to believe these were not insurgents. I've no idea of the legal position with regards to deliberately executing a wounded combatant but I suppose the argument is that you can't tell if he's writhing towards a weapon that could bring you down. I can't judge those in the Apache because I guess that in their world they did what they had to. Life is different in leafy Woodlands Park.

But this alien world of death leaves me wondering... what the hell are we doing there? The moral question of whether to shoot a wounded man doesn't come up with you aren't sat in an Apache helicopter in a war zone.

15/10/2007 17:18 by Matt Mower | Permalink | comments:
More about:

Where did I put that list?

While Paolo was on a secret mission to Woodlands Park last week he mentioned a movie, The Prestige, to me. Released in 2006 I'd never heard of it although it's got a star-studded cast and an 8.4 rating on IMDB.

Anyway I kept the browser window open to remind me to put a note to watch it somewhere. I think this is one reason people like Netflix so much. You have somewhere to put a list of movies you want to watch. Hmm... oh well. This blog post will have to do for now.

15/10/2007 14:37 by Matt Mower | Permalink | comments:
More about:

A little black light lights up black to let you know you've done it

About a month or so, maybe a little longer, the handbrake light on my dashboard started to flicker. It was a little bit annoying. This carried on for a few weeks. I asked my Dad (an electronic, radio, and software engineer of many years standing) what he thought. "Oh it's probably a faulty microswitch."

It carried on flickering for a while then, a couple of weeks back it stopped flickering and just stayed on all the time. "The microswitch has finally given out." I thought. It was less irritating, it was easier to ignore a light that was on all the time than a light that flickered.

Yesterday when I went out in the morning I noticed my breaks were rather spongy. However I was wearing shoes that I don't usual drive in. "Probably these shoes are making it hard for me to press the break pedal." I thought.

Yesterday afternoon as I went to pick Paolo up from the airport I noticed that, even in my normal shoes, my brakes were still rather spongy. This is not good. You don't want to be on the M25 without good breaks. I told my Dad about this and borrowed his car for the journey. "Maybe it will be better tommorrow." I thought.

Tomorrow became today and my brakes still aren't working very well. I phoned the garage who were quite happy for me to bring it in to look at.

As I was talking to Paolo I heard myself saying "You know, it's funny but my hand brake light was acting a bit weird a few weeks ago flickering and then coming on all the time. I wonder if that's something to do with my brakes?"

Of course we go out and check and I have *no* brake fluid at all and it turns out, if you read the little guide thingy that comes with the car, that it is the "Handbrake and brake fluid level low light."

I note it didn't say anything about microswitches!

12/10/2007 21:31 by Matt Mower | Permalink | comments:
More about:

Jaiku purchased... who?

I do love the way every founder of a company acquired by Google writes some puff piece about how they:

look forward to working with our new overlordsfriends at Google over the coming months to expand in ways we hope you’ll find interesting and useful. Our engineers are excited to be working together and enthusiastic developers lead to great innovation. We look forward to accomplishing great things together

Translation: We just fed ourselves to the beast for a shiny nickel apiece and we couldn't be happier. I think Uncov puts it best:

Chances are, Jaiku will end up forgotten, just like Dodgeball. Good, it's the first step to wiping this shit off my internet.

Cheers to the Jaiku people, though. Someone's got to make a buck off this crap.

Amen.

10/10/2007 12:16 by Matt Mower | Permalink | comments:
More about:

Victorian England is alive and well in China today

Watch this.

10/10/2007 12:03 by Matt Mower | Permalink | comments:
More about:

Definitely in the long tail

Congratulations to Kevin Burton on releasing Tailrank 2.5. I must admit that, although I have been reading Kevin's blog for some time I've never paid much attention to Tailrank (I'm not a big user of Technorati or Techmeme either for that matter).

Anyway being the good little self-obsessed blogger that I am I fed my blog to Tailrank's blog-specific meme tracker (available on the tools page). I was quite expecting to get a "We've never heard of you" response but, in fact, it did come up with something:

Which was a post I wrote about requiring politicians to make a legal declaration of having read and understood a bill before they can vote on it (with consequences for cheats) and, now I think about it, it did get a few links.

I'm also reminded that I still think this is a good idea. So I wrote another letter to my MP about it.

05/10/2007 09:41 by Matt Mower | Permalink | comments:

Mailtrap

Rails comes with a useful library for generating emails called ActionMailer. ActionMailer has three delivery modes test, sendmail, and SMTP.

SMTP is what, by and large, everybody uses in production but who wants to setup a local SMTP server for development work? I mean you don't really want send the mail, just to know it would have been delivered. Even thinking about sendmail makes me shudder and the test delivery method just sticks the things in an array that you then need to deal with. That's fine in a test case but you don't want code for that in your app.

So what do you do? Well yesterday I mocked up the simplest, dumbest, Ruby SMTP server you can imagine. It's called Mailtrap and that's exactly what it does. It speaks just enough SMTP to allow ActionMailer to make a connection and send it a message. Mailtrap writes the message into a file for you (and you can tail -f the file if you're interested in seeing it).

Mailtrap has, essentially, zero configuration. By default it creates an SMTP server on localhost port 2525 that writes messages into /var/tmp/mailtrap.log. If you're happy with the default you can be up and running with:

  sudo gem install -y mailtrap
  mailtrap start

then just configure your ActionMailer for development (using RAILS_ROOT/config/environment/development.rb) settings as:

ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :domain => "mydomain.net",
  :address => "localhost",
  :port => 2525,
}

and you're good to go.

By default Mailtrap runs as a daemon so, when you're done with it, use:

mailtrap stop

to have it exit. If you want more control you can change the host, port, directory to write to, and so on as well as overriding daemonization. Check out the various config options in the docs.

Mailtrap was written specifically to talk just enough SMTP to allow ActionMailer to send it a message. I have no idea whether it's pidgeon-SMTP is usable for any other purpose. YMMV.

Released under an MIT license and with the assistance of Daemons, Trollop, Hoe, and Rubyforge.

04/10/2007 11:28 by Matt Mower | Permalink | comments:
More about:

This Britain is NOT on board thank you very much

From Seymour Hersch's piece about the American administrations plans for Iran:

During a secure videoconference that took place early this summer, the President told Ryan Crocker, the U.S. Ambassador to Iraq, that he was thinking of hitting Iranian targets across the border and that the British “were on board.” At that point, Secretary of State Condoleezza Rice interjected that there was a need to proceed carefully, because of the ongoing diplomatic track. Bush ended by instructing Crocker to tell Iran to stop interfering in Iraq or it would face American retribution.

Let me say right now that this Britain is "not on board." And I don't know anybody else who is. I hope that Brown realises that, if he takes Blairs path, if gets us into more international hot water on Bushes behalf he won't be long in that office he has coveted so assiduously.

04/10/2007 09:10 by Matt Mower | Permalink | comments:
More about:

Getting to grips with Nu

Some thoughts about my experiences with Nu so far

  • Learn to love Cmd+I.

Nu comes with a bundle for TextMate that makes a stab at helping you with indentation. But it really doesn't work well enough yet to not be irritating (for example hitting tab often leaves you at an akward indentation level with respect to the rest of your code). I'm trying to condition myself to write the code wherever it is then hit Cmd+I to reformat as I go. But it's hard.

  • Enjoy Cmd+R.

I was going to Terminal.app starting a Nush session and using (load "mystub") to test my code. I've since realised that Cmd+R will feed the current file to Nush and dump the output in a new TextMate window. Good enough for pottering about with.

  • Cmd+Shift+B was made for this.

Something that I used to enjoy when editing Java code in IDEA was the ability to select the current expression scope and then widen the selection by scopes. So from expression, to containing expression, to method, to class and so on.

When you're editing Ruby in TextMate you look for this but it doesn't work and either TextMate can't do it or my macro-fu isn't good enough.

When editing Nu code the Edit | Select | Enclosing Brackets bound to Cmd+Shift+B does exactly what you'd hope. It selects, successively nested, scopes by their brackets.

* Fantastic! *

  • Don't forget valueForKey:

Nu is based on Objective-C and Cocoa. Cocoa key-value coding defines valueForKey: as a way of accessing either a named accessor or, if none is defined, an instance value. You can use it for poking about in your Nu defined classes, e.g.:

(puts ($bc valueForKey: "stopWords"))
  • Overloading - and + seems like bad karma

Personally I am quite happy with imethod and cmethod for defining instance and class methods respectively. I've never been much of a one for overloading operators like this.

  • It ain't your momma's Lisp

Lisp diehards are going to object to:

(self someMethod: argument)

because it puts the function second in the argument list. Whereas a Lisp method call would look like:

(someMethod: self argument)

Giving functions and method different, and potentially confusing, calling conventions. As someone who values consistency in a programming language I have some sympathy with this argument.

The Nu convention will feel familiar to Objective-C programmers (which is the whole point) and Cocoa names its methods in a particular way. So for example:

(transform scaleXBy:scale yBy:scale)

would have to end up as:

(scaleXBy:yBy: transform scale scale)

and:

(@progressBar performSelectorOnMainThread:"setObjectValue:"
    withObject:progress
    waitUntilDone:NO)

becomes:

(performSelectorOnMainThread:withObject:waitUntilDone:
    @progressBar
    "setObjectValue"
    progress
    NO)

I'm not convinced that this would be a win. I think the jury is still out on this one.

  • I am uncomfortable with the List/NSArray divide

In most Lisps you have (list 1 2 3) and that's all you need. Nu has such lists made by cons'ing NuCells. But Cocoa comes with NSArray and NSMutableArray and they are not the same things. When should I use one or the other?

I think this will be addressed as the documentation improves and a standard library emerges.

  • I have no idea why I would want the ivars operator

According to the docs it "adds dynamic instance variables to a class" via an NSMutableDictionary. To the class? Or to instances of the class? How do I add those instances? Why would I use this and not (ivar)?

I have no clue

02/10/2007 23:43 by Matt Mower | Permalink | comments:
More about:

A Nu way to reduce, reuse, and recycle code

Tim Burks, the author of [RubyObjC], has now publicly released Nu and here:

Nu is an interpreted object-oriented language. It uses a Lisp-style grammar, but is semantically closer to Ruby than to Lisp. Nu is written in Objective-C and is designed to take full advantange of the Objective-C runtime and the many mature class libraries written in Objective-C. Nu code can fully interoperate with code written in Objective-C; messages can be sent to and from objects with no concern for whether those messages are implemented in Objective-C or Nu.

The closest analogue to what Nu does is probably something like F-Script which is a Smalltalkish approach where Nu takes a Lispish approach. Nu being written in Objective-C has the feel of being on home turf where something like Ruby-Cocoa you feel a bit like an alien intruder.

Nu is still very new (the release is version 0.1) but I have been over the documentation, examples, and the interpreter source code I'm impressed with where it's at. The sample applications are a cool demo of Nu's capabilities although we're still waiting for the first public Nu application.

Here is an example (from Nu's stdlib) of some Nu code:

(class NSString
    ;; Create a copy of a string with leading whitespace removed.
    (imethod (id) strip is
        (set i 0)
        (while (and (< i (self length))
                  (or (eq (self characterAtIndex:i) SPACE)
                       (eq (self characterAtIndex:i) TAB)))
                  (set i (+ i 1)))
        (self substringFromIndex:i))

Although the syntax will be alien, Ruby programmers will instantly note "Ah, re-opening a class to add a method to it" and it's no surprise, given Tim's previous work, that Nu is heavily influenced by Ruby. Even to the extent of:

% (set laws "Asimov defined #{(+ 1 1 1)} laws of Robotics")
% (puts laws)
Asimov defined 3 laws of Robotics

Ruby-style string interpolation which is very nice. There is also a templating system in the distribution.

And of course Nu gives you the ability to reuse the entire Cocoa framework and any code written in Objective-C. That's quite a lot of re-use right there.

Should you use Nu? That depends on a lot of things.

First off Nu is interpreted. Tim's comments about "harnessing the power of C" were more about being able to leverage C so easily because Nu is based on Objective-C which is based on C. They weren't meant to imply C level performance. Indeed, as of now, I'd expect Nu to be comparitively slow both because it's interpreted and because it's immature.

Then there are the (((((()))))). I'm editing Nu code in TextMate and, while Nu does come with a bundle which includes a reformat command I find it an akward environment to write Nu code in. Maybe it will grow on me. If you are allergic to brackets then Nu probably isn't for you.

And Nu is, well..., new. We're already discussing the syntax on the list and an example of the kind of issue to be considered was raised on Reddit yesterday:

(array count)

This calls the count method on the array object.
That is: the function being called is the second argument.
WHAT THE HELL?

I know what he's trying to do:
he's trying to take Obj-C's message-call syntax of

[object name: argument]

And shoehorn this into an s-expression format.

Nu's attempt to be "Lisp re-interpreted in the context of Objective-C" is going to throw these things up. Only time will tell whether the choices Tim has made have been the right ones and how the language will evolve in response to wider use and feedback.

This is one of the exciting things about a new language but I guess it also means you should expect a bumpy ride.

Although I'm pushed for time to work on it right now I am planning my next Cocoa application. I had intended to use Ruby-Cocoa to add a layer of interpreted goodness but I'm now rethinking that in terms of an Objective-C core enhanced by Nu.

(p.s. I'm hanging around in #nu on irc.freenode.net if anyone wants to chat about Nu).

02/10/2007 09:08 by Matt Mower | Permalink | comments:
More about: