Sunday, July 21, 2013

PEI Hacks


This post is intended for keen, junior developers who reside in a community that does not afford many opportunities such as user-groups, conferences, etc. (I'm thinking of small towns in Atlantic Canada, but the main theme applies elsewhere.)

Hey nerds: discover PEI Hacks, and sign up for the day-long hackathon on August 24.

No, really: sign up. It's free.

"Why?". I'm glad you inquired (see intro)...

TL;DR :

It'll be fun and rewarding. You'll meet neat people.

^(TL;DR) :

It will help shape your professional world-view, your sense of reality.

Since I've returned to the Maritimes, I've discovered a small segment of developers who are bright and ambitious, but don't have a lot of experience. Despite all the online resources, books, etc, at their disposal, their world-view ends at the boundaries of the current daytime, 40-hour gig.

That's professional suffocation. A word to the wise: break out of that rut. Never bound yourself as being an employee for Acme Corporation. Work for You Inc. (in spirit, not legally), and honour an agreement with Acme: 40+ hours work for salary, benefits, whatever.

To break the rut, engage with real people, at real events: conferences, user-groups, meet-ups, hackathons - anything. You'll learn a ton of material outside of your daytime focus. You'll be profoundly humbled by talent, and challenged to improve. Generally, you'll be a participating in a broader community, a citizen of the tech world.

Will any of this assist your daytime work? Maybe, but it doesn't matter: this is for You Inc.

Upshot :

Find a mentor and ask him/her about favourite conferences, user-groups, and real-life events. Oh, btw, you'll find some fabulous potential mentors at PEI Hacks. So, come on out and play!

Monday, February 11, 2013

A Simple Code Kata

Hello CtJ nation!

Yes, it's been a long time, but we're still here at CtJ HQ, reading, if not exactly writing. Hopefully, more to come on that front in the coming weeks.

For now, this post is in support of an upcoming session at the PEI Developers Meetup. We'll be implementing a simple Code Kata and possibly extending it in interesting ways.

The Kata

The idea is a simple card game. Ignoring the rules of Rack-O, check out its deck of cards: numbers, but no suits.

The game is described as follows:

Begin with the deck of cards numbered 1 to N.

Shuffle and deal cards evenly to P players and a "kitty". That is: partition N cards (face-down) into (P + 1) sets.

Gameplay for a round:

  • Show a card, face-up, from the kitty.
  • Players all submit a hidden card as a bid.
  • Once all bids are made, the cards are revealed.
  • Highest bid wins the card from the kitty, and its value is awarded as points to the player. 
The winner is decided by most points at the end of the game.  

Notes

I like this kata for many reasons. First, it scales nicely: we could write code for a single round, and eventually ramp up to a game server with concurrent players.

Also, it combines simplicity and variation: it is easy to write an algorithm that satisfies the rules; yet a winning strategy can be dynamic and surprisingly complex. (Thanks to Alex Stangl for an email conversation on this, some years back.)

Finally, we can imagine a "robot wars" scenario where solutions compete against one another. Neat-o.

Upshot

For PEI Devs, think about this problem for the upcoming meeting.

For all, I'm looking for name suggestions (since it is not the game Rack-O). The best I have is Frak-O...

Sunday, February 26, 2012

Funcito: wrap Java methods for FP libraries

On and off, I've been collaborating with my friend, Kevin Welker, on an open-source project: Funcito. This is really his baby, but it has been great fun to be involved (more to come in another post).

Executive Summary

From the FAQ, Funcito is a Java library that simplifies access to functional programming APIs by wrapping Java methods as the function-type objects defined in those libraries. It reduces boilerplate now, without waiting for changes in Java 8.

The syntax (and internals) is influenced by Mockito, the popular mocking framework. However, Funcito is not aimed at testing.

It supports specific interfaces in Google Guava, Functional Java, and Jedi-core. See the project page for details.

Example in straight Google Guava

Here is example code for using Google Guava, using a List of Song objects.

The setup is simply populating the list:


public void init() {
// List<Song> songs is a member
songs.add( new Song("Help!", "The Beatles", new BigDecimal(1.29) ) );
songs.add( new Song("You Had Time", "Ani DiFranco", new BigDecimal(0.99) ) );
songs.add( new Song("Shoot to Thrill", "AC/DC", new BigDecimal(0.89) ) );
songs.add( new Song("Back in Black", "AC/DC", new BigDecimal(0.89) ) );
songs.add( new Song("Indie Song", "Obscure Band", BigDecimal.ZERO ) );
songs.add( new Song("Demo Track", "College Jam", BigDecimal.ZERO ) );
}

Here is an example test, using a predicate method on Song, isFree(), to filter for free songs:

public Collection<Song> filterFreeSongs() {
// boilerplate alert!
Predicate<Song> isFreePredicate = new Predicate<Song>() {
public boolean apply(Song s) { return s.isFree(); }
};

Collection<Song> freeSongs = Collections2.filter(songs, isFreePredicate);

// size == 2 in example
return freeSongs;
}


Note the typical pattern to build a Predicate, even though the object is simply calling a boolean method. Funcito addresses precisely this issue.

Example with Funcito

Using the same setup, here is the same test using Funcito. Note the proxy object, CALLS_TO_SONG:

// member of class
// using static import of Funcito's callsTo
private Song CALLS_TO_SONG = callsTo(Song.class);

public Collection<Song> filterFreeSongs() {
// using static import of Funcito's predicateFor
Predicate<Song> isFreePredicate = predicateFor(CALLS_TO_SONG.isFree());

Collection<Song> freeSongs = Collections2.filter(songs, isFreePredicate);

// size == 2
return freeSongs;
}


Less boilerplate, with improved readability and a fluid syntax!

The Upshot

If you are using straight-up FP libraries in Java, and want to reduce some of the boilerplate, check out Funcito. It's lightweight with minimal dependencies (either CGLib or Javassist), and can help you wrap up simple Java methods.

Monday, November 14, 2011

Groovy Talk

I recently gave an "Intro to Groovy" talk for a local CIPS chapter.

It was a special evening: I returned to my alma mater, re-united with old friends, and met enthusiastic students.

I assumed the audience wasn't familiar with Java, and so the narrative was a high-level report of the blossoming ecosystem on the JVM over the past few years, with examples in Groovy. The material is available here.

My thanks to those who attended!

Saturday, November 12, 2011

Strange Loop Videos

This won't be news to most readers, but if, like me, you were not able to attend Strange Loop 2011: take heart. The videos are being released online at InfoQ. Here is the schedule.

The lineup is truly outstanding. For more about the conference, check out Weiqi Gao's review.

Tuesday, September 20, 2011

Blogger, OpenID, and Stack Exchange

I'm a big fan of Stack Exchange and have invested a fair amount of time on various accounts on there (mostly Stack Overflow, less on English and Music).

However, I have to admit that I do not keep up with their various escapades with OpenID. I hear about it on the podcast/blog, but I haven't paid much attention.

However, every now and then, it seems as though I can't get into my accounts via my Blogger URL. Not good.

Strictly speaking, I should research OpenID, Blogger's implementation thereof, and then study the trials and tribulations of Stack Exchange. Then, I could summarize it for you, dear reader, and we could reflect, philosophically, on the sharp corner-cases of the web while enjoying a beverage in a local pub.

This isn't one of those posts. This one is simply intended as a modest link-post of gratitude (aka "this worked for me!").

The Problem

When I visited a Stack Exchange site recently, I couldn't login via my Blogger URL, and may not have even been presented with the familiar login icon that I had been using.

One Solution

Follow the steps in this post on JMPinline, including creating a Google Profile and updating with the new links.

Presumably, Stack Exchange uses OpenID 2.0 now and this will upgrade your Blogger OpenID to that version.

Either way, I was immediately able to login to Stack Exchange. My sincere thanks to the original author!

HTH

Monday, September 5, 2011

Your Blog... Sucks

Hello CodeToJoy Nation!

Yes, yes, it has been too long since the last post. The internet has weighed in, and we have noticed.

Your friend and mine, Weiqi Gao, notes that "Nobody I know posts much any more".

The inimitable Nate Neff wrote to me with a succinct critique of my writings in the last year:

Your blog... sucks.

Well. On the evidence, assuming small, frequent updates are important (which is fair): guilty as charged.

However, I don't consider this blog defunct at all; in fact, I often talk about "the glory days" from a few years back.

I've been grappling with writing an annual retrospective, now that I have been pursuing a new chapter for over a year. The trick here is that challenges and triumphs have been much more on the soft side of software: team dynamics instead of technical innovation. I wrote an article along these lines for the NFJS magazine back in April. The article drew on years of experience, but the inspiration originated in my new world.

As I write this, I realize that I'll have to shelve that post and simply post smaller chunks. Stay tuned! I'm still here.