Point of Use

December 22nd, 2007

When we moved from C to C++, we were overjoyed that we no longer had to declare all of our variables at the top of the function.

do_something() {
  int num = 0;
  int another_num = 0;
  num = get_a_num();
  another_num = get_a_num();
}

We could instead declare them near the point of use, when needed.

do_something() {
  int num = 0;
  num = get_a_num();
  int another_num = 0;
  another_num = get_a_num();
}

Ultimately, the rule intends to make things visible to the smallest necessary scope. While technically “scope” is an entire block, actual scope for a given statement consists only of that statement and those that follow. Defining variables at the top of a block unnecessarily extends their scope beyond the actual needs.

That’s great for variables. What about expressions or statements or blocks of statements?

When we hack out straight code, perhaps a one-time chunk of Perl or Ruby or bash, we declare a statement exactly at its point of use. If we don’t name it, it’s lost in the ether, immediately out of scope again.

rm -Rf path/to/stuff
mkdir other/path/to/stuff
cc -o google google.c

We climb up into the world of “engineering” and we start to create functions, or classes and methods. We give names to a chunk of statements and increase the visible scope of this code.

def turn_on_sprinkler()
  call_sprinkler_webservice( :on )
end

But have we just moved our declarations too high, like our variable declarations in C at the top of the block?

We follow a rule that if you use the result of an expression more than once, you should stuff it into a variable. A local variable. Not a global variable. More than likely not an instance variable.

How about if you use a statement more than once, you stuff it into a named block. A local named block. Not a global named block. More than likely not a method on a class.

notify = Proc.new{|person,message|
  person.email.send( message )
  person.sms.send( message )
}

notify.call( person.wife, "I'll be home late" )
notify.call( person.mistress, "Motel 6 in 10" )

Unless the functionality is required at any higher scope, declaring and defining named blocks locally prevents pollution of the namespaces.

With languages such as Ruby, instance methods can be defined upon instances that need them, instead of upon every instance of a given class.

def ship_via_cargo_container(item={})
  class << item
    def cube
      (self[:height]||1) * (self[:width]||1) * (self[:length]||1)
    end
  end

  freight_cost  = item.cube * 100.dollars
  handling_cost = item.cube * 10.dollars * 2
end

In effect, this view is one of macros. When it’s convenient to create a short-hand notation, or a micro-DSL, do it where it has minimal impact on the rest of the system.

It could be argued that interpreters and compilers are not prepared to see and optimize for these types of blocks. The Java world surely keeps debating closures. I have no idea the impact on Ruby interpretation when you’re constantly defining new methods on individual objects. But then again, there was a time we feared the overhead of managing objects instead of simply free functions and structs.

Musical duldrums

December 20th, 2007

There are times that I realize I haven’t directed my own music choices for a while. Maybe I’ve been traveling, spending all day on the phone, or simply driving down the road with the radio inadvertently tuned to KRAP-FM.

And I find my motivation waning, my creativity lacking, and my general happiness in deficit. Music matters to me. But even then, I’ll have trouble finding the right music to listen to. Somehow the 26.5 days of music jammed into iTunes just is not sufficient. The online streams seem off.

But then there are days like today, when my wife introduced me to José González. This man sings exactly the right way for today. Plus the video has a creepy pigman.


A moment too late

December 18th, 2007

Ever learned of something just a fraction too late behind “everyone else”, causing an immediate disregard for that thing?

For me, the incident I remember most was the release of Nirvana’s Nevermind album. I prided myself on knowing cool weird bands, then boom, everyone was listening to Nirvana, and I’d somehow completely missed the boat. Not wanting to be a “me too” I ended up never purchasing any Nirvana CDs ever. Of course, now I remember Kurt fondly when I hear Smells Like Teen Spirit on the oldies radio channel (”the greatest hits of the 70s, 80s and 90s, with less talk!”).

I feel like something similar may be happening with Spock.com. I don’t know if they’ve somehow suddenly infiltrated my social group, or if they just have a particularly wicked viral campaign (auto-sending invites to your whole address book, like Plaxo did once upon a time). But somehow, I’ve gotten a dozen invites to Spock in the past week.

I’d looked at Spock a while back. And I didn’t get it.

It did not seem particularly accurate, precise or useful. And now everyone I know is inviting me to it.

And I still don’t get it.

Some new services have a gentle roll-out, where you build anticipation, hoping to get invited (ie, Dopplr, GMail). Others seem to have a polarizing roll-out. You either immediately buy-in or immediately become a detractor.

I’m not sure what the difference is, really.

But you can stop inviting me to Spock.

Trip Report: EuroTour ‘07

December 17th, 2007

As noted earlier, Rebecca and I flew off to Europe last week for a little holiday, JavaPolis, and a week of JBoss.org team meetings.

With the winds behind us, we managed to make it to Schiphol airport in a record 6.5hrs from Newark. Not bad at all.

Met up with James Cobb, the kick-ass .org brand-manager/designer at the airport. We managed to keep each other walking around and awake all day to stave off horrible jet lag.

The wife and I stayed a night in Amsterdam before taking the train to the lovely Centraal Station area of Antwerp. If you’re looking for the ambiance of a Motel 6 with the convenience and bouquet of being beside the Greyhound Station, this is the place for you!

Once in Antwerp, we hooked back up with James, and met, for the first time, the Fabulous Five from Poland: Przemek, Ryseik, Adam, Tomek and Pawel (left to right). Mark Newton was present for a few days, but had to return to Switzerland early, unfortunately.

We ate a lot of frites. And waffles.

The Polish developers attended a lot of the conference talks, and we as a team had some great whiteboarding/brainmapping sessions about the future direction of JBoss.org-NG, as we’re calling it (more blogs to follow on that topic).

Somewhere along the way, the guys goaded me into doing the Java Black Belt competition at the Cap-Gemini booth. I managed to make it to the finals, and ultimately won a PlayStation 3. Unfortunately, it was a PAL-based Region-2 PS3, which is decidedly incompatible with my Region-1 NTSC lifestyle choices. It’s now living in Poland, along with a Nintendo Wii that Adam won.

I chatted up Crazy Bob and learned that we’d both lost our hats during the trip. A man without his hat is a sad sad thing. Luckily, I did manage to procure another. Also luckily, I have more hair than the other Bob.

I met Vincent Massol, Stan Silvert and Julien Viet for the first time. I met Emmanual Bernard, Max Andersen, and a host of other JBossers yet again.

During the entire trip, I managed to get yelled at a lot (hat shopkeeper, hotel matron, inn keeper, bar maid) and had that Alecia Keys song injected into my skull everywhere I went.

Overall, a success!

Java and Waffles

December 6th, 2007

In about 24 hours I’ll be jetting towards Antwerp, Belgium to attend JavaPolis. I’ll also be meeting most of my team for the first time, as the development stars from Poland wing their way westward.

JBoss has a booth, and a bundle of core developers (and management) will either be attending or speaking.

Mustache? Oui!

November 28th, 2007

As Movember winds down, I decided to trim my Douglas Coupland/Generation X/Singles goatee into something with more character. Like last year.

I’m sporting either a French or John Waters mo’ now. I’m pretty sure this isn’t my wife’s favorite look. But, my body, my choice.

And yes, the mustache itself forces me to make that face. I think it may be sentient or at least possesses occult powers.

Like falling out of a tree

November 14th, 2007

Wandered the yard with the camera this afternoon for a few minutes.

Maple (unknown variety):

English Ivy, on Maple trunk:

Maple (unknown variety):

Fallen Maple leaf:

JBoss Innovation Awards

November 14th, 2007

Once again, we’ll announce winners of the Innovation Awards at JBoss World in February.

While there’s other opportunities for the projects at JBoss to get the nod for their innovation, the Innovation Awards are a chance for you, the users of JBoss projects, to get some glory. That glory includes a free pass to the conference, a VIP dinner, and some special attention during the conference.

What’s interesting about what you’re doing? There’s 8 different categories, surely you fit into at least one.

  1. Joint Red Hat/JBoss Deployment: Everyone deploys their Java stuff on Linux. If that’s JBossAS and RHEL for you, you’re ready to rock.
  2. SOA Implementation: Are you using JBossESB, Drools, JBoss WebServices, jBPM?
  3. Increased ROI: Ask your CIO/CFO.
  4. Ecosystem: The whole ecosystem around Seam/JSF could be ripe for an award here.
  5. Emerging Technologies: Have you been doing Seam with Groovy?
  6. Migration: Have you ditched your app-server from one of the Other Guys lately?
  7. Business Process Automation: Did you implement jBPM or Drools?
  8. User Experience: Did you produce a slick UI using Portal, RichFaces and AJAX?

The Innovation Awards are a chance to highlight the good work your team has been doing. You’ve got until the end of the month to send us your story using the simple form at the bottom of this page.

Hat full of Java

November 8th, 2007

Red Hat and Sun recently signed some agreements around open-source Java projects and access to the Java TCK. This all goes towards the OpenJDK, and ultimately, having an open and officially recognized JDK on Fedora.

Contrast that to Apple, who some people think is pulling back and away from Java.

For more information about these agreements, see this interview with Sacha Labourey. He explains the expected impact and benefits of these arrangements.

Mos before Foes

November 8th, 2007

Every year there is a time that men can put aside their differences, stop their fighting, and do some good.

This important time of year is Movember.

Grow a mustache and help raise awareness for men’s health issues.

Last year, I cheated, by simply shaving down an existing beard into a mustache. This year, I started clean-shaven (a day late, even). So far, I’m just stubbly, but will probably shave this weekend to reveal the mustache within.

Have fun with facial hair!

« Previous - Next »