How I got into Ruby (You've got red on you)

At the inception of our project, my colleague and I had the opportunity to choose the technology stack. Since we were both Java peeps it seemed natural to start designing the app, a REST based service, using the new Spring 3.0 MVC stuff. We even started to watch some videos on Spring Roo to get it off the ground. The reality of our situation though is that we were developing one of many systems to the client. The other system is being developed in Ruby and the majority of developers at the client are also Ruby developers. Based on this, we decided that sticking with Ruby would be a better fit for the client.

There were two factors easing the discomfort of taking on a new technology to deliver a system on schedule. The first is the relatively simple nature of the application.  It's a REST service that does some simple checkout process with moderate performance requirements.  Nothing brutal. The other is having an extremely talented Rubiest on my team. Toby's been more than happy to help convert a Maven loving Java dude like me over to the crimson side. I knew with him around this was my best chance to build my first non-trivial Ruby system.

So far it's been a fun ride and after a few weeks it feels like I'm finally starting to breathe some air.  The syntax and conventions are starting to become familiar and the ability to navigate stack traces and documentation is improving.  Another great ancillary effect is that the functional and dynamic aspects of Ruby have been connecting some of the disjointed dots which surfaced during my brief studies in Clojure.

I do however miss terribly the luxuries that stricter syntax and strong typing enable, especially for tool support. Please refrain from the real coders don't need an IDE spiel. I miss strong refactoring support, especially because my newbie Ruby needs a lot of it.  Static analysis and code completion are also wonderful for learning new syntax and API's. Knowing which methods are available to call on a variable is nice. Being able to click through to the source code of that method or see the doc in a tool tip on hover is very nice.

But I'm always happy to learn even if it means re-learning how to learn.

I will be blogging some of the things I banged my head against in order to help others new to Ruby, allow current Rubiests to laugh at my newbieness now, and most importantly allow me to laugh at myself later! Stay tuned. 


Chicago Clojure Meetup

There's no doubt that I loves me some Clojure. Just listening to guys talk about though it honestly makes me feel like I never took a college comp sci course and I love it for that. Who would have known LISP would ultimately rule the world! Lispers, I guess.

When Michael Norton asked if I'd like to help out with the Chicago Clojure group I was quick to hop on board. Now, I'm no Phil Hagelberg, but few are? All I know is that playing around in FP land was a wonderful and eye opening experience after being nose to the grind in Java's OO for many years. I can't wait to get these rolling on a regular basis.

So sign up for for the group and bring your self down on May 19th. We are taking recommendation on topics so please suggest something or vote for what you want to hear about.

Plus, there will be pizza!

(I in no way guarntee the availability of pizza at the Chicago Clojure meetings). 

Time to dust this thing off.

So where have I been?

New job. New marital status. New layer of skin (after Jamaican Sun peeled off the first layer). Most exciting to you (my 2 followers (and Minella's RSS feed)). New languages! New technologies! All that jazz.

Since joining Thoughtworks (yay), I've been using a lot of Ruby. I've tried to do Ruby several times in the past but never had the opportunity to do anything non-trivial. The last time I tried to use Ruby was with Gunnar Morling's Sriptable DBUnit DataSet for the Maven/Cargo/Tomcat/H2/Selenium automated web test stack that I never blogged about.

So what I will be talking about in the near future is my experiences of turning to the world of Ruby, which has so far involved the battery of RSpec, Rack, Sinatra, Rake (yes Rake), Passenger, Bundler, Shotgun as well as MongoMapper since we are using MongoDB as our datastore. We needed to make use of geospatial indexing and  MongoDB did one hell of a job against PostGIS for our use case. Although I do love SQL and relational as well as multidimensional data modeling , my first No-SQL experience has been undeniably great.

Hopefully I'll find some time to pretty this generic template up as well. Stay tuned!


Top 10 reasons why Maven sucks...not!

I'm having a hard time understanding all the Maven bashing that takes place these days. Maven has been a real joy for me. It could be the simple fact that I can move from colleague to colleague's project without wondering what ant tasks are available or where the files are. It could be the fact I don't have to configure IDE's anymore, not even for downloading sources. It could be some of my favorite plug-ins. Maybe it's the 250,739 artifacts that are available in three lines of copy paste declaration. There's a lot to love.

I'll admit, it didn't make sense at first. It felt a little too large and I was leery of the potentially restrictive guidelines.  I was also very nervous to commit to the predefined life cycles and directory layout. Within a short period of time I learned a minimal pom provided more function than a minimal ant script and the conventions are actually what enable you to easily add more to the build. After an objective comparison to previous projects I've worked on I determined that while less flexible, Maven's life cycle is both adequate and consistent. Over a few years of use, adequate and consistent has proven to be far more valuable than unique or powerful. This is the build, not the software we're building.  There's plenty of business logic to make our systems complex.  The statement that alternative build tools are more powerful is also debatable.

Let me be clear, I'm not recommending we all use Maven or stop working on alternative tools. I am, however, asking that people give Maven a break. A lot of Maven criticism borders on ludicrous. We're all open source advocates (right?). If you dislike it, you know what to do. If you have a specific need, write a mojo (and share it, or don't). If you're going to speak out, offer constructive criticism. In the very least, try not to make your anti Maven rant based on a string of fallacies. I'm trying not to pick on any specific alternatives or individual, but let's walk though this one item by item:

10. maven corrupts – software, people.
Maven exposes circular dependencies and actually uses the checksums it generates. The software aspect isn't true. Maybe I'm a little corrupted, but I'd consider it more like being spoiled. There's also the expression that power corrupts and with a side note about absolute power. The availability for corruption seems to resonate more strongly with the thought of an entire programming language at your disposal. It's all up to how the power is used.
9. maven uses an archetype(appfuse) and expects that all your projects look like the apache projects – even those that are not webservers.
I'm not really sure what this means. I think Maven expects that your projects look like Maven projects. That's what the convention means. When I looked at appfuse projects, they looked like Maven projects to me but maybe it's a chicken and egg thing, which much like the riddle itself, doesn't have much incentive to solve.
8. maven has only four build stages – compile, test, install, package – if you have a requirement to automate performance testing you are out of luck
There are quite a bit of hooks in the build lifecycle. It was added later, but I believe you want integration test (with pre and post integration hooks). I use a fully automated functional test suite that deploys and fires up selenium. I heard Terracotta was using it to fire up two instances of Tomcat to test fail over scenarios. These aren't performance tests, but I'm sure it's achievable. 
7. maven requires you to have a standard directory structure that is 5 subdirectories deep – regardless of the fact that your project only has 10 java files.
src/main/java . Let's see that's 1,2,3. I think it's a good convention and so do several other alternatives.
6. tasks that are not implemented in maven have to be implemented in ant and need to be integrated with maven – a big nightmare.
The only situation where I've been forced to use Ant was to sign an applet jar to put into a war-file. That unfortunate situation was due to a defect we experienced jar:sign goal. After 10 minutes of trying to get it to work, we found a defect in a jira somewhere. To work around the issue we tossed in the Ant task from the original build script. Since then the maven-jarsigner-plugin has evolved and I'm pretty sure we could remove the ant-run task if we were into fixing what ain't broke.
With that said, it's stupidly simple to use ant-run. You don't even have to go download Ant, nor does the n'th machine that your build will run on have to download it.  Nightmare? I've spent more time setting ANT_HOME and configuring PATH variables.
5. maven encourages you to integrate via binaries – thus making continuous integration difficult
I've used Hudson and Bamboo extensively. Both have excellent facilities specific to Maven. I don't even understand what the alternative to binary integration is. I wish the complaint had a specific scenario for me give a valid counter point. 
4. every time maven builds it connects to the internet (to verify/update dependencies) – building your project without the internet is extremely hard.
Not true.  Maven grabs it once then it never needs the internet except once a day for snapshot, which is for your convenience and can also be disabled. Don't forget offline mode. And you really should take 5 minutes to setup Nexus for a little durability in the event of an internet outage.
Follow up question, how easy is doing anything without the internet? Specifically, how easy is executing code you don't have on your local machine without the internet?
3. maven manages the projects and subprojects implicitly (since there is convention and then there are overrides) – it makes debugging your build impossible.
You can always see the effecive-pom if you need to. It's not very hard to see exactly what overriding is going on.
2. maven manages the project dependencies in its own repository – called the .m2 repository – which is not part of your application folder – thus making it impossible to track and package development environments.
This repository is the local repo. It is not part of your application folder because you probably have more than one project that requires commons-logging.jar.  You can track which files make up your development environment pretty easily. You can also copy them to your development environment or package them for several different environments. Pretty flexible facilities in place for dependency management
1. maven always downloads the whole internet – to keep its dependencies up to date – even though you don’t want to.
Whole internet? At this point I'm trying hard not to reply with sarcasm. I'm not trying to attack the author, just disprove the points. And to address the point, 2.0.9 and up has predefined plug-in versions. They do not update on their own. Anything else it updates because you didn't tell it not to by specifying a version for your plug-ins.

This is the type of FUD you can easily find by doing a Google search for "Maven sucks". Here's why I believe it doesn't suck.

Maven's declarative model allows you to prepare structured data, the primary application of XML, to a system that knows how to do what you want. Very goal oriented. The primary motivation of Ant was to have platform independent scripts for Java which was platform independent. That's why at the time, Ant was hot sauce on fried chicken! The problem for me with scripting language based build systems is that most remain task oriented. Staying disconnected from the tasks required to complete a goal is a great gain in overall usability. Maven stays focused on the latter and offers the flexibility to tweak the tasks when necessary.

In addition to the lack of branch logic and variable declarations, the main gripe on XML is that it  is too verbose. But so is the documentation for an ENTIRE LANGUAGE!!! DSL subsets make it easier but there's still a learning curve, especially if someone gets clever. Learning Maven definitely does not happen immediately, but what you are learning is domain knowledge for the task at hand, build management. Every other build tool I've given the cursory glance to required I learn about its build process in addition to a full language or DSL. XML, for all of its lousiness, is ubiquitous and self describing. Lack of cleverness can be a good thing.

That might all be a moot point since polyglot maven is right around the corner. I'll probably stick to XML because I don't write XML, Eclipse does (so do many text editors, with syntax and error checking to boot). Still I am very interested in the project and using it as my primary excuse to get some Clojure in my life. I do have fearful thoughts regarding what tricks someone will put into their builds using these alternatives, but if it means more people are happy about Maven I'm all for it.

After all, why shouldn't Maven cater to those who crave the additional power. Let's not forget that it was created to help you, not make your life hell. There's an age old expression I learned from Gary Coleman at a young age regarding different strokes and world domination. Some people drive stick and others prefer automatic. I prefer automatic because it allows me to do other things like spam text messages instead of shifting. A manual transmission might just encourage me to speed off the road or get a traffic violation. There's a method to the madness of preventing someone from acting foolish. Think of that traffic law as a metaphor to prevent a rake script gone crazy. I personally feel that when Maven isn't making something easy, it's because it probably shouldn't be done in the first place, not in the build at least. For all other times, there's the gmaven plug-in, but I really really try not to make my colleagues go through the unfortunate pain of learning a new language just to execute my tests or create a custom jar file.  

Is the power of a Turing complete language really necessary to compile, execute tests, package and/or deploy your code?

So to wrap it up, I don't understand the hatred towards Maven. Some people act like it stole their prom date. I'm happy for alternatives like buildr and gradle and realize no matter how great any project is it will eventually be replaced.  I don't discourage people from trying or developing new tools, even though I would love to see those efforts put into Maven instead. Different strokes!  Opinions aside, it is and will forever be a tool that redefined build management and whatever tool replaces can only improve upon the baseline it has established.

But the inaccurate, almost childish Maven ranting has to come to an end! It's downright ungrateful and disrespectful to the people who have worked very hard to provide a free and open source option.  Newer alternatives greatly benefit from the groundwork laid by Maven in the first place including the repository or directory layout conventions. So in the least pay homage


Scala, the passion is finally starting to take hold.

I have to admit, I'm starting to warm up quite a bit to Scala. It was of interest to me but after I had seen Venkat Subramaniam's talk at the NFJS conference this year, I decided it was past time to pickup some books and start looking at it seriously.

Usually my biggest problem with moving away from Java is the tool support. This holds little water with those who still think simple text editors are the best way to code. Maybe I'm ruined by technology, but hovering over a method to see the javadoc or hitting F3 to view the source code takes the annoying out of learning new languages. Without this support, so much time is wasted on petty syntax errors and searching though api doc that could have come with trusty ctrl+space. Well it turns out the tool support for Scala in Eclipse and NetBeans was actually pretty good. The static typing (low ceremony static typing I might add) enables the editor to do some pretty nice type checking, code completion and syntax highlighting. This was a nice change over the dynamic languages I've been dabbling in.

After playing around with the simple examples in Ordesky's book, I skipped straight to the Swing chapters. I found the syntax to be nice and concise but the problem is that I can't compare it to Swing code I've written because I DO NOT WRITE GUI'S BY HAND. There's a product called NetBeans that works brilliantly for GUI design. Hopefully I'll get to use again before Oracle throws it under a bus. After that I tried looking into liftweb. That was a less than optimal experience due to the Maven archetypes being a cross between out of date and flat out broken. I had good luck with the mailing list but my GitHub ticket (which is one hunky piece of crap work in progress) was closed, probably because of my lousy issue title.

So after my "ok who cares about SwingBuilder", a flacid Lift-off with liftweb, and the lack of needing to build a highly concurrent HelloWorld with actors, I started to think that maybe I'll enjoy using Scala in the future but at this point there unfortunately wasn't a use for it in my daily life. Then I was put into a situation of prototyping something for someone which required handing in a fully functional application, in Java, and this is where the fondness began to grow.

The thing that drove me absolutely nuts was all of these high ceremony domain objects. 150 out of 450 total lines were public getters and setters. Sure eclipse generated them but I got so distracted by the noise. The worst part is you have to JavaDoc all of those too (or should). It also makes re-factoring more of a pain. What a waste of time! The other feature that I really wanted to leverage was fine grained access control. The problem dealt with moving vehicles based on received commands. It seemed natural to put turn and move commands on the vehicles which mutated their coordinates. I think my functional friends would recommend something that takes and returns a new rover but one step at a time for me dudes. I did have a command processor which processed the inbound commands and then executed them on the rover. It would have been nice to restrict access to the turn and move methods only to this command processor interface to prevent someone who doesn't know what they're doing from moving the vehicle off a cliff.

I used to hold design patterns close to my heart until I heard someone say design patterns only serve as workarounds to deficiencies in a language. The more I learn Scala the more I see these deficiencies in Java. I still don't and never will dislike Java, but I do think I'm going to start mixing a little Scala in with my everyday applications. At least for domain objects or objects that have a lot of member variables.

If you're in Chicago you should try to attend the Chicago Area Scala Enthusiasts(CASE) meetup that is hosed by Dean Wampler. Dean's a great presenter and top notch technologist. He covered ScalaCheck and ScalaTest this week and he also showed use of Simple Build Tool (SBT) which does some pretty nice tricks like continuous compilation and testing. It also wins points with me for supporting Maven dependency management.


Pimping Cygwin part I: Terminal Goodness

My inaugural experience with Linux as a desktop started with Gentoo in 2005. I used openbox as my windows manager. The extent of my GUX (graphical user experience) was right clicking the desktop to launch a terminal and off I went. The concept of putting a file or folder on the desktop wasn't there and I became quite fond of mv, mkdir and rm. Since then I've tried to use RHEL, Fedora, Solaris, and all the 'buntu's. Aside of the fact my games don't run and the drivers were always substandard, I was never happy with the experience of the interface. The only thing I ever miss about Linux is the shell. A big argument in the developer community on switching to Apple is the use of a real bash shell. I guess that's if you consider Terminal to be a real terminal. In the interest of not losing potential followers, I'll refrain from speaking on why I hate Apple. I'd entertain some comment discussion for anyone who questions my right to hate them but that's not the point of this blog. Instead, I'm here help you configure Cygwin for some Linux goodness on your Windows machine. I'm calling this part one because it would be a tremendously long post to detail everything great about Cygwin. Ultimately it's a terminal/shell I'm after so let's start off with how to get that working.

The first real problem with Cygwin is that by default it starts up in a DOS window. Come on Windows! Is a command line that supports line wrap copy/paste really that hard to provide? This can be a really bad first impression to the casual user who installs Cygwin. Thankfully, there's an rxvt implementation available for Cygwin, but making that useful isn't super straightforward either.

First, you have to remember to select it during the install process. Otherwise, it is not included. Then what you need to do is modify the cygwin.bat file (or create a new one) and have it launch RXVT and bash instead of whatever crap it does by default. That is a simple one liner batch file.
C:\Cygwin\bin\rxvt.exe -e /usr/bin/bash --login -i

The next thing to do is to make it pretty. This is what I have in my .Xdefaults file which should be in your cygwin ~(that's home you linux newbie):
Rxvt*geometry: 120x40
Rxvt*background: #000020
Rxvt*foreground: #ffffbf
Rxvt*scrollBar: True
Rxvt*scrollBar_right: True
Rxvt*font: Lucida Console-12
Rxvt*SaveLines: 2000
Rxvt*loginShell: True
! VIM-like colors
Rxvt*color0: #000000
Rxvt*color1: #FFFFFF
Rxvt*color2: #00A800
Rxvt*color3: #FFFF00
Rxvt*color4: #6090F8
Rxvt*color5: #A800A8
Rxvt*color6: #00A8A8
Rxvt*color7: #D8D8D8
Rxvt*color8: #000000
Rxvt*color9: #FFFFFF
Rxvt*color10: #00A800
Rxvt*color11: #FFFF00
Rxvt*color12: #6090F8
Rxvt*color13: #A800A8
Rxvt*color14: #00A8A8
Rxvt*color15: #D8D8D8

Last, but far from least, is fixing some keys and disabling that hideous beep. That's all part of the file also located at ~/.inputrc. Here is what I use.
"\e[3~": delete-char

# VT
"\e[1~": beginning-of-line
"\e[4~": end-of-line

# kvt
"\e[H": beginning-of-line
"\e[F": end-of-line

# rxvt and konsole (i.e. the KDE-app...)
"\e[7~": beginning-of-line
"\e[8~": end-of-line

# VT220
"\eOH": beginning-of-line
"\eOF": end-of-line

"\C-v": paste-from-clipboard

set meta-flag on
set convert-meta off
set input-meta on
set output-meta on
set bell-style visible

I'm not sure if you need all of those. I've copied this .inputrc file around for a couple years now. The good thing is that it's a standard .inputrc file and you can Google through many many years of how to configure it to your liking. Same goes for the .Xdefaults.

The last real thing to fix is the prompt. The default one is not very good. For any Linux user this should be simple but for those in need, try adding this to your .bashrc file, located conveniently at ~/.bashrc:
export PS1="\[\e[36;1m\]\u\[\e[32;1m\]:\w > \[\e[0m\]"

So there you have it. Bash goodness in Windows. Go ahead. Tail that logfile. Pipe it to grep. Use a for loop with find and sed to rename some files. Enjoy the beauty of symlinks (and laugh at junctions while you're at it, what a joke).

Please comment if something doesn't work so I can update the post. This is only what I can recall from memory after having done this so many times. I'm thinking about covering X for Part II of the series. SSH + X-forwarding works quite beautifully.

Now if only I could get Keynote and Textmate to run in Windows. I'd be in heaven! I need the polyglot OS.


CLI in web based applications

I was recently asked to do a prototype for migrating some, well, lets say not very recent user interfaces to a more web based view on them. The first test was to just make sure that a web based application could perform fast enough and we didn't need to go swing. For the record, I'm not a swing fan because of all the layout finagling and I sure don't like GWT doing all my work for me. Call me a purist or an idiot, your call.

I check out what the users want and come up with a nice thin app using JQuery on the front end communicating via REST services responding with JSON for the datasets. Pretty standard stuff. Nothing too revolutionary there. If you're not using REST, I'd recommend it but I can get on that soapbox later. What was interesting was the request that these workers prefer to use keyboard shortcuts. In essence, I was asked to make a web based application that didn't use a mouse. Pretty interesting and different than usual.

I toss together this prototype and demo it - first suggestion was could I make it so there was just a text box interface where users could type in shortcuts and then use key combinations to drive functionality.

The solution I ended up with uses the hotkeys plugin for jQuery -
It is crazy easy to use, here is binding the f4 key to execute whatever is typed in the text window:

$(document).bind('keydown', 'f4', function(){ executeCLI();});

function executeCLI()
var cliString = $("#prs_cli").val().trim();

//Process cliString, call more functions, etc

Its crazy simple to bind functions then to key combinations. You can even bind key combinations, i.e.

$(document).bind('keydown', 'ctrl+c', function(){ executeCopy();});

Why would anyone do this? At first I asked the same question. The mouse is there, use it. But then I started using the CLI interface for the web. Think about how faster you, the maven, are with CLI? Think about the experienced user being able to interact with web apps this way. Pretty cool and effective stuff.

So check out hotkeys and maybe think about some CLIs for your super users of your web apps.