Vesper Sync Diary #4 - In Another Country

Web services don’t just appear out of the foam like Aphrodite from the sea — they have to be written. Though I was tempted to run a server on a Mac and write the backend in Objective-C, I decided to do what normal people do: use a scripting language. JavaScript.

Here are the main features of JavaScript country — what I’ve seen so far, anyway. (You may know all this already. If so, skip it. This is written for people like me who are mainly Cocoa developers.)

This examples illustrates one of the parts of JavaScript I find weird. You can create a dictionary like this: {foo : 'bar'} where foo isn’t a defined variable.

And then you can refer to d.foo and d['foo'] but not to d[foo].

What happens if foo is a defined variable?

> foo = "xyz"'xyz'> d = {foo : "bar"}{ foo: 'bar' }

This makes me nervous.

Another weird thing is ===, which bypasses type coercion. x === y means that x and y are equal and the same type. (Most of the time you probably want ===, for safety’s sake.)

A third weird thing: const is not yet part of the official language. (Though some implementations have added it.) This freaks me out.

There’s plenty to like about JavaScript, and I do like it. It certainly saves typing (compared to Objective-C; but then, what doesn’t?). Everything is a var. Function parameters are untyped. It has the usual advantages of scripting languages (which are also the usual disadvantages).

You can even script Mac apps and do Cocoa-ish things — see Gus’s JSTalk.

Mocha

I recently spent a few days adding unit tests to Vesper. (It would take another week to get caught-up.) Even though some things are hard or impossible to test — does that animation look right? — it’s still worth it for the low-level code. (It’s so much easier to concentrate on that awesome animation code if you know the app’s foundation is solid and bug-free.)

The good thing about server-side JavaScript is that, in theory, it’s all testable. It’s all low-level code: no UI, no animations, nothing the user actually sees.

One of the frustrations with XCTest is that you have to do special things (run the runloop) to handle asynchronous tests. (I haven’t even tried yet.) Mocha handles asynchronous tests easily.

It even provides color-coded output, which I like.

Text Editors

I live in Xcode, like most Cocoa developers. My editor for everything else is BBEdit.

But last night I wondered if there might be another editor that’s particularly stellar for JavaScript development. I tried three.

Sublime Text lasted about a minute. It appears to be wonderfully powerful — but it’s also not Mac-like. The first thing I did was open a file and select some text. Dead give-away right there. Then I checked out the preferences. Ah. No. Not for me, though I appreciate that many people love it.

TextMate 2 alpha is a Mac app. But there were deal-stoppers there too. (Deal-stoppers for me. This is all personal taste.) I didn’t like having to double-click in the file list to open a file. I especially didn’t like that I couldn’t find an easy way to edit the color schemes. (I like syntax coloring, but can’t stand syntax-bolding and syntax-italicizing.)

I like Chocolat. It’s very much a Mac app. The file list works via single-click. I could turn off syntax-bolding and syntax-italicizing. It has some nice features, too — my favorite so far is the always-visible symbols list.

Chocolat also looks better than the other text editors. It’s cleaner. (It’s weird to care about that, since I’m mostly just looking at text. But it means the app has fewer things to distract from the text.)

Chocolat isn’t without issues, though, and I have 14 days left to decide whether or not to buy it. (It’s $49, a totally fair price for a development tool.)