The Source for Java Technology Collaboration
User: Password:



Ben Galbraith's Blog

Programming Archives


How I Learned to Love Domain-Specific Languages (in Three Parts)

Posted by javaben on November 16, 2005 at 08:14 PM | Permalink | Comments (20)

(cross-posted on Married... with children)

I've been watching the hype surrounding domain-specific languages (DSLs) with skepticism. At first I thought, "Why would I learn some custom syntax when I could use good old Java and XML?" And then, gradually, I saw the light.

Dave Thomas was the catalyst behind my change of heart. Over dinner a few years ago, he patiently explained to me why the Ruby community eschewed XML for YAML; that angle brackets and wearisome complexity make XML more pain than it's worth.

At the time, I sputtered various protests about how XML was a lingua franca, readily-understood, blah blah blah. But it got me thinking -- and the next time I edited an Ant build file, my discontent was a bit more pronounced than usual.

Shortly thereafter, James Duncan Davidson came out with his "I shudda used a scripting language" post (couldn't find a good link, sorry, but this fragment gives you an idea), and that got me thinking some more.

As the Rails machine started dominating the Ruby discussions, Dave's anti-XML chorus found a whole new host of supporters, this time advocating in addition to YAML the use of the value of domain-specific languages instead of general-purpose configuration files. About the same time, my friend Neal Ford started banging his own domain-specific language (a.k.a. language-oriented programming) drum.

"Hey," I started thinking, "maybe there's something to this 'XML bad, DSL good' meme."

The funny thing was that all throughout this time period, though I didn't realize it, I was already preferring a DSL to XML. RELAX NG (a blissfully simple alternative to W3C XML Schema) comes in both XML and DSL flavors, and I'd been preferring the DSL for months. Have a look, starting with the XML version:

<?xml version="1.0"?>
<element name="contents"
         xmlns="http://relaxng.org/ns/structure/1.0"
         ns="http://galbraiths.org/myns">
    <oneOrMore>
        <element name="section">
            <attribute name="name"/>
            <element name="content">
                <zeroOrMore>
                    <choice>
                        <text />
                        <element name="p">
                            <empty />
                        </element>
                    </choice>
                </zeroOrMore>
            </element>
        </element>
    </oneOrMore>
</element>

That doesn't look so bad -- and since it's RELAX NG, and not W3C XML Schema, it's actually somewhat intuitive.

Now, check out the DSL:

default namespace = "http://galbraiths.org/myns"
element contents {
    element section {
        attribute name { text },
        element content {
            (text |
             element p { empty })*
        }
    }+
}

I think the XML version is clearly more intuitive for those with no previous exposure to RELAX NG, but for those who spend a lot of time working in the domain, my own experience (and anecdotal evidence) shows that the DSL is the clear favorite. By the way, the RELAX NG "DSL" is known as the "Compact Syntax". Until recently, I never thought of it as a DSL, but, it sure is.

So gosh, I guess I prefer domain-specific languages to general-purpose XML, too.

(I'll talk a bit about creating and using DSLs in Part 2 of this blog entry, and in Part 3 I'll give some examples of how Java's Swing GUI toolkit can benefit from a DSL or two.)



My Ultimate Home Office

Posted by javaben on September 07, 2005 at 01:41 PM | Permalink | Comments (9)

Over the past few years, I've been doing a lot of consulting out of my home office, and the trend will continue for at least the next year. Recently I decided, "Hey, if I'm going to be spending a lot of time in here, I might as well spruce up the place a bit." Over the past few weeks, I've upgraded. Let me tell you what I've got, why I like it, and in some cases, why I still haven't found nirvana yet. Please -- comment on this entry and tell me about your setup. Well, unless you're James "Dual G5! 30" Apple LCD!" Strachan. ;-)

The Chair

I spend 10-20 hours a day at a computer. Bad habits have given me the beginning symptoms of repetitive stress injuries (RSI) in my arms, hands, and back. Comfort is real important to me. Enter the Perfect Chair:

The Perfect Chair

The minute I reclined about 45 degrees, it was heaven. I work most of my day reclined that way, and, when whimsy strikes, I recline back all the way for some... brainstorming. There were some other great up-right chairs out there, but I figured, hey, if I'm at home, I may as well flaunt the freedom it affords me. Try getting your boss to approve one of these for the cube, my friend!

The Computer(s)

With the perfect chair, I've got the most important element out of the way. Next question: what computer? Since I'm lucky enough to be developing in cross-platform languages, I can choose pretty much whatever. So I went with an Apple PowerBook. Which model? The 15", of course. 12" is too cramped, and the 17" is way too large.

The PowerBook

Ahh, nice. I love working on the Mac; the aesthetics of OS X and power of Unix are just great. Everything tends to work well together. Wonderful platform. And, wicked slow. So, when I need to actually get work done for people, I use a mutt PC that I built years ago and upgrade as it breaks (last incident was an AMD chip whose heat-sink fell off, frying itself in a few seconds). I always choose middle of the road components, and it always seems to run circles around whatever Mac laptop I'm using. Right now it's got a 2.8 GHz Pentium something-or-other, Intel motherboard, 1.5 GB RAM, nVidia 6600 AGP 8x 256 MB card (cheap but sufficient), and not much else.

The Keyboard

There are millions of folks who type on keyboards all day every day. Yet, I can't find just the right keyboard. The closest thing to perfection I've found is the old Microsoft Natural Pro keyboard. It's been discontinued for years, so I buy them on eBay when I need 'em. And I have a little stockpile.

The Keyboard

I love that keyboard. Why? It has the only True Keyboard Layout I've found in an ergonomic style (2x3 special key block between the main keys and numeric keypad, 1-on-3 arrow key layout, slashes in the right places, and so forth); it isn't wireless, so no batteries or radio interference to worry about (I'm always by my desk anyway); it's got programmable macro keys galore; it's got a built-in USB bus; and its got pretty good OS X drivers.

Apparently, I'm not the only admirer of this sucker; they don't go cheap in on-line auctions.

The Monitor

In a stupider move, I bought a 20" Apple LCD. I got it at a discount when I joined the ADC, but even still, it was overpriced. Dell makes a 24" LCD that suspiciously matches the specs of the Apple 23" LCD and sells it for $400 less than Apple's 23". Should have done that. Nevertheless, it's a great LCD, and nice-looking too.

The Monitor

Once you take the recliner plunge, you've got to make accomodations for your monitor. You see, the Perfect Chair can put your feet way above the bottom of any desk I've seen, so you can't just put the chair under your desk. I put my chair parallel to my desk, and I've got an Ergotron LX monitor arm that positions the monitor over me just where I like it as I recline.

The Arm

The downside of the arm is that it only tilts down 5 degrees. I need to find something that tilts down 45 degrees or more so I can position it directly above me; that should be fun.

The KVM

Two computers, one monitor -- enter the KVM (Keyboard-Video-Mouse) Switch. I've had some real bad experiences with these devices in the past, but all that's changed with my recent find: the Gefen SL Switcher.

The KVM Front

The KVM Back

It's a DVI/USB2 KVM siwtch that comes with a remote control! This sucker works like a champ with no signal quality problems. Can't recommend it enough.

The Software

Ugh, this is a whole separate blog entry. But let me tell you about my favorite two pieces of software. QuickSilver is *the* way to get around on a Mac. Check it out. I haven't used the Dock for ages. (Hint, QS does a lot more than app switching.)

QuickSilver

And for code grinding, IntelliJ IDEA still can't be beat. Worth every penny.

IDEA

What's Missing

I need to get an air mouse to get the Minority Report effect going, and frankly, there's not a good place for a conventional mouse in the reclining chair. I have a generic sound system (cheap Logitech surround sound system; cheap Logitech headphone/mic combo); I ought to upgrade to some THX-certified goodness and get a nice surround sound USB device for the PowerBook.

What else am I missing?

(Cross-posted on my personal blog, Married... with Children)



Finally... Interactive JavaDocs

Posted by javaben on August 10, 2004 at 09:06 AM | Permalink | Comments (10)

Over the past few weeks, I've watched with anticipation as Rick Ross and Matt Schmidt from Javalobby have put together jdocs.com, an on-line JavaDoc search engine. As the site has matured in recent days, I've enjoyed using it in place of my downloaded JavaDocs.

(Note that jdocs.com is built on the open-source project Ashkelon, a powerful JavaDoc indexing tool -- much more than a search engine bolted onto JavaDocs -- created by java.net's own Eitan Suez. I was treated to a demo of Ashkelon by Eitan several weeks ago and was very impressed, although saddened that the project is so little known.)

The killer feature of jdocs.com is the ability for developers to comment on individual JavaDoc entries. Having used this functionality on other sites to great positive effect before, I can't wait to start leaving comments of my own -- if nothing else for my own future use.

As other like-minded developers start leaving their own comments, jdocs.com may become a virtual hivemind of Java knowledge (apologies to my friend Howard), helping newbies discover, for example, that calling setLocationRelativeTo(null) is how you center a Window in AWT/Swing, or that you need to use a Transformer to save a DOM tree (ah, that intuitive W3C DOM API...).

Hopefully, as the site matures, comments will span versions of an API and the comments of superclasses will be visible in some natural way in the API of subclasses (or at least acknowledge their presence).

Some may view the on-line ads injected into the JavaDocs as a nuisance. I'm actually quite intrigued by the possibilities; this could evolve into an ideal platform for component vendors to hawk their wares, and for developers to more fully understand their options. Imagine querying the JavaDoc for JTree and seeing an ad for an alternative GUI tree component or any number of other similar scenarios.

I've already integrated jdocs.com with my IntelliJ IDEA projects and use it for my JavaDoc queries. Congratulations to Rick and Matt for one of the most exciting new community resources in a long time -- and keep the innovation coming!

P.S. The Javalobby folks aren't quite sure how much load the site's going to be under as the word gets out, so be kind over the next few days as they ramp it up.



Is an avalanche coming?

Posted by javaben on April 13, 2004 at 07:36 PM | Permalink | Comments (10)

Computers have undoubtedly and dramatically raised the productivity of businesses world-wide. Yet for all the increased profits that technology can inject into the bottom line, it has a nasty habit of turning around and grabbing fist-fulls of cash back out of the balance sheet (witness Microsoft's massive cash hoard).

No one's debating whether or not IT delivers more value than it consumes (at least, no one writing this blog), but for some executives, the high cost of enterprise software (and the required consultants, and the forced upgrades, and the unkept promises of vendors) has them searching for alternatives to the modern-day software industry.

The Wall Street Journal wrote an article on April 12, 2004 about a new software "co-op": Avalanche Corporate Technology. Its composed of a handful of large companies, including Best Buy, who have banded together to share each other's homegrown software assets -- for free. (There's a $30,000 annual membership fee).

Initially, the co-op's inventory of shared code isn't all that impressive (at least, from what I can see from the outside). But its the long-term vision of the group that grabbed my attention.

According to the WSJ, Avalanche sees a future where its members band together to write their own commercial-grade enterprise software (e.g., call center applications or even office suites) and giving the product to themselves for free.

I'm as skeptical as the next software engineer that a loosely organized band of hetergenous companies can effectively produce and support enterprise software, but I admit I'm intriguied by the Avalanche concept. I wonder -- is this the start of a significant (or at least notable) rebellion against the high margins, low quality, and upgrade tactics of the software industry? Or is it a naive and misguided attempt that will flame out sometime in 2005?

I also wonder why the companies involved don't just open-source their software. What controls/benefits/etc. does their co-op model give them over an open-source model? Or is the co-op and its up-front sign-up fee just a manifestation of Darl McBride's "nothing in this life should be free" attitude?

I'll be in Minnesota, Avalanche's turf, in a few weeks for the upcoming No Fluff Just Stuff software conference; I think I'll pay 'em a visit and see what these guys are up to.



Commoditization of Basic IT Infrastructure is a Bad Thing?

Posted by javaben on February 10, 2004 at 08:36 PM | Permalink | Comments (7)

I feel like I'm swimming upstream against a tide of derision from my peers, but unlike so many who disagreed with Jonathan Schwartz's recent article/editorial/advertisement on JDJ, I think what Jonathan said makes a lot of sense.

What company in the world wants to invest time and money in creating custom, one-off IT systems which are completely orthogonal to its core business efforts? The status quo of middleware is a hellish reality of integration tears and custom development nightmares.

I believe that Sun's vision of providing turnkey solutions to solve the basic business IT needs in a single, aggresively-priced solution is right on target with what today's IT organizations want.

I'd like to rebut some of the opinions expressed in opposition to Sun's strategy that I've read today:

  1. Sun is marginalizing J2EE. This misses the point entirely. Of course these standard services would be built on J2EE. Of course businesses will continue to use J2EE for those things that actually generate revenue. Will some programmers be out of work if standard IT infrastructure components gradually become commoditized and (gasp!) easy to configure and use? Probably. Will new jobs open up as more capital is freed to invest in revenue-generating projects? Yep. That's how the economy works, folks. Wouldn't you rather work on the sexier projects anyway?

  2. Jonathan Schwartz (and Sun) should get out in the real world and find out what companies really want. Ignoring that Sun execs spend a shocking amount of time flying around the world doing just that, is the average developer so out of touch with reality that they think their company actually wants to spend a ton of money developing and upgrading custom IT plumbing? Integrating product A with product B? Hiring high priced consultants to figure out how to wire application C and application D? CIOs (and their bosses) the world over want to spend less on IT plumbing, and more on product development.

  3. Another fadish attempt by Sun to save themselves from irrelevancy. Maybe, but give the company a chance to dust itself off and execute a new strategy after a hard post-bubble fall. Their strategy (make IT simple) is pretty consistent across hardware/software product lines, and sounds pretty compelling to the corporate world.

As a Director of Technology responsible for both the software development efforts that are the company's lifeblood as well as supporting our IT infrastructure, I can tell you where I'd rather spend my budget and manpower -- and its not on IT plumbing.

Some may think that Sun is on some kind of quixotic crusade and won't be able to execute on this vision. I don't know; wasn't too long ago Sun was on most folks' A-list. It's become fashionable to bash Sun. I know they've muddled through some misguided strategies in the past, but I say, give them a chance on this one.



Java in Your Stereo?

Posted by javaben on January 17, 2004 at 04:19 PM | Permalink | Comments (7)

For the past few weeks, I've been playing with MacSense's new HomePod device. The HomePod is a compact MP3 player with WiFi built-in, a scroll-wheel interface not unlike that of Apple's iPod, and peer-to-peer media streaming software developed by Gloo Labs.

Unfortunately, the HomePod user interface does not work like the iPod. After playing with it for a few days, the differences between the iPod and the HomePod really began to bother me and my wife. If the HomePod were like any of the other consumer electronic devices in our home, we'd just live with it. But in this case, I can take matters into my own hands: the HomePod runs Java!

I downloaded the source code to the HomePod, tweaked the interface code in a few hours, FTP'd the new class files to the device, rebooted, and shazam! The HomePod user interface now behaves just as the iPod. Cool! This is one of the first times I could take my career skills and actually do something useful around the house.

The HomePod isn't the first consumer device I've owned that allowed me to run Java on it -- I'm still recovering from the pains of MIDP 1.0 -- but it is the first Java device that I've enjoyed playing with. I think that enjoyment is related to the following factors:

  • The HomePod runs J2SE 1.3. I don't have to do HomePod development in a subset of the "real" Java that I'm used to working in (i.e., J2ME).
  • The HomePod exposes everything to developers. The HomePod's user interface, its networking code, the application that streams music from my servers to the HomePod, it's all in Java! How refreshing this is compared to today's Java-enabled cell phones which continue to expose a subset of handset functionality to Java developers. I can tweak this thing in every way imaginable. There are some components written in C (device drivers, audio codecs), but even in those cases, the source is still made available.

The advantage of owning a device I can modify became especially apparent to me when the Wall Street Journal's Walter Mossberg recently reviewed another WiFi streaming home MP3 player. While he generally gave the product high ratings, at the end of his review, he had a stinging criticism:

[This] system doesn't let you just select "All Tracks" and then play them randomly, as you can on an iPod portable player... [This feature's] omission is a real loss.
While I fixed the HomePod's lack of "iPod fidelty" in a hurry, if I had a closed-source media player like the one reviewed, I'd be stuck singing the blues with Walt.

After my glowing experience with the HomePod, you can bet I'll be shopping for more Java-powered open-source consumer devices in the future.





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds