Tuesday, April 12, 2005

Obie does Ruby

Obie writes a bang-up piece in praise of Ruby. Coming from ThoughtWorks, I know just where he's speaking from when he says:

The nubys that do not have OO programming experience are being helped by Ruby old-timers and the other significant group of developers streaming into the Rails community: senior Java developers looking for something better that what we have to deal with now.
Yes, I am one of those senior Java developers. And where did I first hear of Ruby? At ThoughtWorks. If a long-time, hard-core, high-end shop like ThoughtWorks is preaching Ruby to clients like some vanguard of the proletariat, then the revolution is well underway.

Houston Rubyist hoedown

I just got off the horn with the excellent Peter Suk (he of Ruby to Smalltalk VM porting fame) and found a place for the Houston Rubyists to roost: Tuesdays at The Stag's Head Pub in Shepherd Plaza at 2128 Portsmouth. Be there, or be like a static programming language.

UPDATE: Peter pointed out the wiki for his VM project. However, it's timing out for me.

UPDATE: Well, I didn't make it. My date rang long (a better excuse than many), so I owe Peter a decent draft.

Monday, April 11, 2005

Higher-Order Perl

Now here's an interesting book title, Higher-Order Perl. The description:

Higher-Order Perl is about functional programming techniques in Perl. It's about how to write functions that can modify and manufacture other functions.

That's worth my Amazon wishlist.

Saturday, April 09, 2005

Maven and JavaCC

I finally have a little time, so I'm writing a prototype build of PCGen using Maven as an alternative to the Ant build.

One piece to mind is DiceExpression.jj. I wrote it some time back to parse simple dice roll expressions such as 2d6+3. To wit, Maven provides a JavaCC plugin but the documentation is rather sparse. I can tease most of it out from the plugin.jelly for JavaCC, however a working example is always easier.

Happily, Howard Lewis Ship provides one ironically named Moving Away from Maven. Thank you, Howard.

Friday, April 08, 2005

Maven 2

Ah, yes. That favorite tool of many (especially Hani) is reappearing in a new incarnation. Maven 2: The Rewrite Simpler! Faster! Easier! All worthy goals. Of course, I have to try it.

Thursday, April 07, 2005

Ruby, continuations, the web and you

Amit Rathore at ThoughtWorks got me interested in using continuations in web applications. Gregor Hohpe did some interesting work there moving away from the call stack in program design.

Keeping in line with these approaches, I ran across a great link posted to the Ruby Talk mailing list: Continuations on the Web.

Ruby, unlike Java, has full native continuations and call/cc ala LISP. This makes for some really interesting code, mind-bending and very rewarding. For web programming, it moves you away from a messaging model to more traditional program flow: you get to code linearly, but the program is still multiplexed in the web way.

There is a great future for futures.


(I had trouble with the link. A bright spark suggested the wayback machine.)

Rubyists in Houston unite!

Rubyists in Houston unite!
You have nothing to lose except your chained method invocations!

Actually, this post is for those interested in getting together and discussing Ruby over beer and cool code. Please leave your contact information in the comments and I'll see if we can put something together.

Tuesday, April 05, 2005

Quick and dirty web server

I needed a quick and dirty web server on an XP box for a project at work without the fuss of setting up Apache et al. I found just the thing, the Abyss web server from Aprelium Technologies. No source, unfortunately, but I do not need source for my task. The configuration is 100% in simple, highly usable web pages, and it is rather more full featured that I need, but not so much so to get in the way. And the price is $0. Works for me.

Monday, April 04, 2005

Rails on Slashdot

Slashdot is have a content-rich discussion of Ruby on Rails compared to J2EE. There is rather low flamebaiting for such a discussion. Perhaps the kinder, gentler Ruby culture is seeping through.

And a pony?

Dark software humor picked up off the XP group on Yahoo!:

and a pony
Common usage: "I want faster compiles, more hardware, and a pony."
Meaning: "I know I'll never get any of these things so why not add a pony to the list just to make myself feel better?"

Also happens when management wants to squeeze a #12 bag of features in a #10 slot of schedule, a ripe moment for story cards and the planning game.

Saturday, April 02, 2005

Gentoo 2005.0 on my Dell Latitude D600

If this image is missing; Dell might have reorganized their site.

My cool purple Gentoo 2005.0 CDs came this week. I've been putting it off before because of spotty hardware support, but I'm ready with this release to try Gentoo Linux on my Dell Latitude D600. Happily, there are plenty of resources out there for me to use.

As I progress, I'll update this posting.


From the factory my Dell laptop was setup to boot from the hard drive, not the CD. So use F2 immediately at boot to change that in the BIOS. Thank you, Dell.


First thing I found, the hardware detection on the live CD is great! However, it does not run DHCP on my Intel Pro 2200BG wireless card. The ipw2200 kernel module loads, but DHCP will not set up networking. There was noise about firmware needed, but I do not want to go there. Would it trash my XP partition from networking?


Yah! The live CD includes /usr/bin/ntfsresize so I can avoid the expensive, commercial alternative — besides, their pages loads too slowly. Now I just have to figure out how to shrink my Windows XP installation so I have so disk space for Gentoo.

Friday, April 01, 2005

Playing with your balls in Ruby

Some bright spark (actually it was Ilmari Heikkinen) makes lit spheres in Ruby using OpenGL and GLUT. Shiny!

Study in elegance

Christian Neukirchen writes about implementing T in Ruby. In case you are not a LISP fan, T is a LISP dialect. It is the implementation that is so elegant: 20 lines of Ruby. And there is a corresponding simplicity of concepts, but surprising generality.

Wednesday, March 30, 2005

Windows INI files in Java

For reasons of cross-language compatibility, I have a set of user preferences stored in Windows INI formats. I'd like my Java applications to see these, so a quick Google search turned up an excellent solution. [ini4j] is a Java preferences API implementation using Windows INI files for backing store. Also, there is a simple, obvious API for direct handling of Ini two-level maps. And the whole jar comes in at a svelte 25k. Well done!

Chance meeting

While perusing Ruby Buzz I notice a post from Premshree Pillai about Yahoo's new Yahoo! 360°. It's a blog, a scrapbook, an address book and friend/connections web application aimed at those who's social life is online.

Oddly enough, I started chatting with Prem and found out he works for Yahoo! in Bangalore. I mentioned Yogi Kulkarni who was a top dog developer in our Bangalore office when I was at Dell in Austin (we had a 24-hour development cycle). Wouldn't you know — he knew Yogi! They met a PythonRuby meetup. Even on the other side of the globe six degrees of separation applies.

UPDATE: Oops, it was a Ruby meet, not a Python one.

Friday, March 25, 2005

Firefox and the acronym tag

I just stumbled on something cool with Firefox. Try using the acronym tag, thus:

<acronym title="Spell Out The Acronym Here">SOTAH</acronym>

And the associated stylesheet:

acronym {
  border-bottom: 1px dotted #222;
  cursor: help;
}

The result is YATLA. I especially like the mouse pointer change (at least on Windows).

Thanks to this page on ISBN bookmarklets.

McCallister on Rails

Clever Brian McCallister (all people named Brian are clever -- trust me) has a nice insight regarding Rails v Java: in the terminology of The Innovators Dilemma, Rails is a disruptive technology against the sustaining technology of Java. Honestly, I've never seen anything quite like Rails for setting up straight-forward web applications.

Sunday, March 20, 2005

And now for something different

I type too many serious posts. Where's the fun in that? Well, here's a bit of amusement -- Toogle: Toogle. Go try a search, although I am a little disappointed at binkley.

Thanks to why, the lucky stiff for mentioning this.

Wednesday, March 16, 2005

Ruby Quiz

A very nice site, Ruby Quiz, has a list of programming quizzes along with solutions and commentary. It is focused on Ruby, but the quizzes are written generically and pose nice problems in any modern programming language. Java and its ilk are bondage and discipline languages; Ruby and friends are dynamic languages. But the are both usable for these quizzes.

Monday, March 14, 2005

The excellent bsdiff utility

Colin Percival wrote the very excellent bsdiff utility which makes very size-efficient binary diffs. Starting from there, it is not too difficult to write a script for making binary diffs of directory trees, files and directories added, removed or changed. It is the binary counterpart to diff -Naur. I named it dar after tar. In a test run, I made a binary diff between 1.5.0 1.5.0_01 of the JREs included in the JDK. The dar file is 1.5Mb. A bzip2ed tar file of the whole JRE at maximum compression is 25Mb. Feeback welcome.

Wednesday, March 09, 2005

One of these things is not like the others

Are these not equivalent?

copy(new FileInputStream(new File(".")), System.out);
copy(new File(".").toURL().openStream(), System.out);

Oddly, they are not.

The first line throws a FileNotFoundException (misleading as the error message states . (Access is denied)), whereas the second copies a sorted file listing, one file name per line. I learn something new every day.

Tuesday, March 08, 2005

Editor for Ruby?

I'm considering taking the plunge and trying out Ruby in earnest[*], but lack of a editor is holding me back. Ideally, I'd like a refactoring browser akin to IntelliJ's excellent IDEA for Java.

There is Ruby Refactoring Browser, but it is version 0.0.3 and only for Emacs. Even so, I installed it but am disappointed by the lack of a ruby-mode.

So I solicit suggestions. Any Ruby on Rails fans with help?

* I like the name Ruby in earnest a lot more than Ant in anger. :-)

Friday, March 04, 2005

Half-bean serendipity

I was struggling to explain to a fellow ex-ThoughtWorker this pattern I had half-formed in my head. The problem was how to construct an immutable java.net.URI when I didn't have all the constructor arguments handy. I was vaguely describing some kind of clever factory that scoops up arguments over time, and spits out an URI when you press the create() button using the constructor which most closely matches the information provided.

Then while looking at clever defense of REST I saw the reference to the half-bean pattern. Serendipity! That is exactly the description I was looking for. I was describing the Half-Bean pattern: the getters were all in the immutable URI, and the setters all in the factory with a factory method to tie them together.

Thursday, March 03, 2005

When the Java three-part expression is not equivalent

What is wrong with this code?

return -1 == endIndex
    ? Collections.emptyMap()
    : makeMap(path.substring(endIndex + 1));

Here's a hint:

private static Map<String, String> makeMap(final String s) {
    final Map<String, String> map = new HashMap<String, String>();

    for (final String pair : split(s, ';')) {
        final int i = pair.indexOf('=');

        if (-1 == i)
            map.put(pair, null);
        else
            map.put(pair.substring(0, i), pair.substring(i + 1));
    }

    return map;
}

Ok, now do you see? What about now:

public Map<String, String> getServiceSpecifiers() {
    final String path = uri.getPath();
    // Ignore service specifier (e.g., ftp)
    final int endIndex = path.indexOf(';');

    return -1 == endIndex
        ? Collections.emptyMap()
        : makeMap(path.substring(endIndex + 1));
}

The return type is Map<String, String>, and Collections.emptyMap() is defined as:

public static final <K,V> Map<K,V> emptyMap() {
    return (Map<K,V>) EMPTY_MAP;
}

So what is really the matter? Last clue; this fixes the problem:

if (-1 == endIndex)
    return Collections.emptyMap();
else
    return makeMap(path.substring(endIndex + 1));

The problem is generics.

The compiler deduces the bounds correctly in return Collections.emptyMap() but not when in the three-part expression (X ? Y : Z). The compiler tries to harmonize the types when evaluating the expression, and this leads to picking the lowest bounds possible, Object rather than String. The expression is then returned, but now it no longer meets the bounds for the method and it is a syntax error.

The IF statement does not have the extra bounds deduction, so reduces the empty map to the bounds of the method exactly.

How annoying.

UPDATE: An anonymous commenter pointed out the correct Java syntax to pull this off:

return -1 == endIndex
    ? Collections.<String, String>emptyMap()
    : makeMap(path.substring(endIndex + 1));

My C++ blinders kept me from considering this possibility; I tried putting the generic specification in several other places in the statement instead, none of which worked. An interesting construction.

UPDATE: Paul Holser pointed out the right name for this construct: the ternary conditional operator.