Jeff Mesnil’s Weblog

Spaces & Expose in Mac OS X 10.5.3

June 10th, 2008

As explained by John Gruber, Apple has improved Spaces support in Mac OS X 10.5.3 but there are still some broken features.

When I’m reordering my windows, instinctively, I want to activate Spaces then use Expose All Windows feature to rearrange them. But this does not work: I have to first use Expose then Spaces.

Before 10.5.3, it was not possible to use Expose when Spaces was active. Now, we can activate Spaces and then display All Windows in Expose using the screen corners or the keyboard’s function keys:

spaces.jpg

However it still does not work using mouse keys.
As for Expose Application Windows, it does not work at all when activating Spaces.

The behaviour I’m expecting from Spaces & Expose is to be able to switch between Expose features (All Windows and Application Windows) and Spaces in any order using either screen corners, function keys or mouse keys.

Maybe I’ll have this behaviour in Snow Leopard

Review of JavaScript: The Good Parts

May 27th, 2008

I admit: I don’t like JavaScript.

I have written and maintained very few scripts and it was a frustrating experience to have them working on several browsers.
However this was many moons ago and I wanted to reevaluate JavaScript after using it in unexpected places (i.e. outside of the browser) like in CouchDB View API or Eclipse Monkey (I already wrote about JMX scripts using Eclipse Monkey).

I was looking for a good book on JavaScript, the language. There are many many books on JavaScript but they focus mainly on JavaScript in the browser and spend thousands pages describing the DOM (please, Messrs. the editors, save the Amazon forest and just print some links to the online DOM documentation…).
I wanted a concise book about writing simple and maintainable code. I also wanted to learn more about the weird syntax constructions spotted when reading non-trivial bits of code, such as processing.js or CouchDB View’s map/reduce.

I bought “JavaScript: The Good Parts” on the strength of the author’s chapter in “Beautiful Code” and I was not disappointed.
This is exactly the kind of book I’m looking forward to when learning a programming language. It is short (100 pages + 50 pages of appendixes including JSON description) but dense, the sample code are small and meaningful (even the done to death fibonacci and factorial functions used here to explain memoization).
The book does not lose space describing extensively the whole language. It focuses on the subset which is good and proven and do not talk about the edges or the parts which are better forgotten. It really shows how to write code which is both readable, maintainable and elegant.
I’m sure I’ll come back to this book every time I read JavaScript code using some peculiarities of the language that I don’t understand.

After reading this book, I’ve got a better understanding of JavaScript and now sees the good (and even beautiful) parts of it. I have a better appreciation for its prototype-based design even if it is hindered by a class-based syntax.
I also find it frustrating that the JavaScript standard library is so useless (no I/O to communicate with the rest of the world). Of course, the library is richer when the code is to run in the browser or on Rhino (gaining access to the whole Java platform) but, by itself, the standard library is very poor compared to what comes bundled with Python or Ruby.

These are critics of the language. For the book, I’ve got nothing but praises. I recommend it to any programmer wanting to learn more about what is good in JavaScript.

One advice about the code examples: it is much simpler to use Spidermonkey or Rhino than the web browser to run the different scripts and experiment with them interactively.

How to include JavaScript engine in Apple’s Java 6 VM

May 14th, 2008

After complaining in my previous post, here is a more constructive guide to use JavaScript with Apple’s Java 6 VM:

  1. Download JSR 223’s engines
  2. Copy jsr223-engines/javascript/build/js-engine.jar to /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/
  3. Download Rhino
  4. Copy rhino1_7R1/js.jar to /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/

You can now use a “JavaScript” engine from Apple’s Java 6 VM:

public class ScriptTest {
    public static void main(String[] args) throws Exception {
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("JavaScript");
        engine.eval("print('hello, world!')");
    }
}

jrunscript is also working:

$ cd /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/
$ ./jrunscript 
rhino-nonjdk> print("hello, world");
hello, world
rhino-nonjdk>

No JavaScript in Java 6 on Mac OS X

May 14th, 2008

I had an idea about using JavaScript from Java 6 and I wanted to give it a try on my MacBook.
No such luck: Apple has recently released Java 6 for Mac OS X Leopard but somehow it does not include Rhino, the Mozilla’s JavaScript engine bundled in Sun Java 6 release.

Instead they provided only one engine for AppleScript but frankly:

Who cares?

public class ScriptTest {
    public static void main(String[] args) throws Exception {
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("AppleScript");
        engine.eval("tell application \"Finder\"\n display dialog \"Who cares?\"\n end tell");
    }
}

Nuff said…

Tribute to Jim Gray

April 26th, 2008

Jim Gray

I can’t say it better than Pat Helland:

Being at a conference like HPTS was very entertaining as I could look from across the room and see Jim march methodically through all the attendees, many he’d known for years and some he was just meeting. I would smile because it was obvious they were getting the same kindness and curiosity that I so enjoyed. I knew they would benefit from that attention.

That is exactly what I felt when I met Jim Gray at HPTS’03. He made a strong and lasting impression on me with his amazing ability to explain complex things in simple terms.

I met a lot of so-called architects or experts who seem to take pride in being hard to understand (after all, if they could be understood by mere mortals, they wouldn’t be experts…)

Jim Gray is the exact opposite:

When strangers approached Jim, he had an uncanny ability to assess what they could understand and the level at which to explain the problem. I’ve seen him take the most complex issues and dissect them into a framing that allowed a lay person to understand the gist of the problem and then, separately, dig int the deepest and subtlest nuances with another more versed in the topic.

I really feel priviledged to have met Jim Gray.