12.27.2009

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.

11.11.2009

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.

10.13.2009

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.

10.12.2009

Cygwin + Interpreters(Jline) + Carriage return = solved!

I love cygwin. Not only is having every a bash shell and unix utility on windows awesome(grep, less, tail, awk, cut, pipe, sed, du, df, ls, ln, curl, sort, head, vi, X-Server, etc...) but using rxvt or xterm as a replacement to windows cmd window is awesome.

However when I use some command line interpreters such as a groovy shell, maven cli, spring roo, and others, my carriage return doesn't work. When I hit enter, the cursor goes to the next line but the command is not executed. This has been bothering me for months and yesterday I finally found the answer.

The core of the problem is with JLine, a command line API that many Java based interpreters use. Jline queries the environment to see what OS you are running and uses that for the expected end of line input. Because the OS is windows but the terminal is xterm, cygwin (rxvt at least) will not send the command Jline is expecting to signal end of line. Therefore, you can't actually execute anything in the interpreter.

So after searching for a solution over and over I finally stumbled upon this issue. Thank god for JIRA! It ultimately led me to this Jline defect.

So in order to save you a lot of trouble, all you have to do is add the following to your jvm args:
-Djline.terminal=jline.UnixTerminal


If you are doing this for maven CLI, then you need to add the -D argument to your MAVEN_OPTS because Maven will execute the process for you.

I didn't need to use the stty commands as recommended but I only fixed my maven-cli plugin (which is awesome btw). Maybe someone could explain what the stty commands are for and when or why you'd need them.

So hopefully this will save some cygwin users some time and frustration.

10.03.2009

What we do know

To the contrary of my previous post, I thought I would say what we do know. Without further ado, What we do know (an abbreviated list...well, hopefully)

  • We know that its hard to keep an architecture simple
  • We know that if you have a solution or tool in place that has a 'large impact for replacement' - boy oh boy, did you either eff up the use of the tool or did you purchase one sh1tburger of a tool to start with
  • We know that if you want your employees / team / co-workers to be engaged and highly productive, you have to allow them to be engaged and highly productive.
Perhaps I will dive into this in more detail in future posts.

10.02.2009

What we don't know

You know those conversations you have in your head that always come across sounding so awesome? Well, here is the start of one that I had in my head, and a conversation that I want to have but you know, it might not be the best for work....

Command-and-control-director: 'You don't know my world. I've worked for 10 years to make my world just right, you can't change it. You don't know the implications of the changes you are suggesting and how it would impact the company.'

Me: 'You're absolutely right. I have no ides of the implications. And on top of that, I have no desire to know or even hear the implications.'

By no means do I claim that this is an original thought - sometimes it is prior knowledge that blinds us from seeing and understanding other opportunities. Today, for example, my 3-year old daughter wanted to take off her shoes and socks and go stand on some wet rocks in this rock pond at an arboretum. It was 50 degrees out and breezy so I tried to convince her otherwise. But she was persistent and I let her. She loved it, she played in there happily skipping around for 30 minutes.

The pond water was heated.

I was basing my decision on prior knowledge. It was cold out and breezy, therefore this shallow water will be cold. Did I stick my hand in the water to test it? No, I knew it was cold.

The pond was heated.



And so we see this in large organizations now. People of high rank that have been around for a long time - they have solved the problems of their world. They have all the experience and the knowledge. When someone challenges them - well, that challenger couldn't possibly understand the cost of such a decision and if they had, they wouldn't be making such outlandish comments. What complicates this situation more is when this type of mentality is tolerated. It leads to a stagnant flow and ultimately to a company unable to change.

Change is difficult for anyone, let alone a company or a large company at that. At the Agile 2009 conference this year in Chicago, JB Rainsberger had an amazingly profound session where he talked about his lessons learned in 10 years doing XP. There he talked about the Satir Interaction model. In my best attempt to abbreviate it and not minimize its impact, it is understanding the other persons perception while you are interacting with them. Pretty hard to do, I suggest everyone try it.

The example I gave at the start of this post is real. How should one deal with this scenario? Yeah, the way I mentioned sounded awesome in my head. But I'm not convinced it is the best. Perhaps it is the difficulty of having that director's perception, but I really believe that he wants empirical data. Change is hard for him to value because he doesn't have metrics and historic examples in his world that he can call up...and that's fine. That's what he needs, and ultimately you have to believe that he wants to do what is best. But that's what he needs and what he knows. Given that, how should I address the situation? Probably with no response. Keep doing the skunk works, show the value in the change until it is too big to ignore, and then help him think it was his idea.

In the theme of this blog set - that man is not a maven. But that shouldn't stop the mavens from progressing along. They just need a better salesperson. And if you can't find that salesperson at your current location, then you find it somewhere else.

In summary - sometimes the best thing to know is that you don't want to know. You just might find out the pond is heated.

9.29.2009

What The Software Maven is all about


Are you in a state of weltschmerz due to dealing with the proponents of accidental complexity that prevent us Software Mavens from enjoying our craft? Welcome home.

Here, we use the term Maven as described by Malcom Gladwell in The Tipping Point. Since wikipedia does such an excellent job paraphrasing it I'll quote:

Mavens are "information specialists", or "people we rely upon to connect us with new information." They accumulate knowledge, especially about the marketplace, and know how to share it with others. Gladwell cites Mark Alpert as a prototypical Maven who is "almost pathologically helpful", further adding, "he can't help himself". In this vein, Alpert himself concedes, "A Maven is someone who wants to solve other people's problems, generally by solving his own". According to Gladwell, Mavens start "word-of-mouth epidemics" due to their knowledge, social skills, and ability to communicate. As Gladwell states, "Mavens are really information brokers, sharing and trading what they know".


Unfortunately, as a Software Maven, we rarely get the level of respect deserved. Pathologically helpful? That really only means we fall victim to the sycophants who praise our ideas to benefit from our grunt work. "What a great idea. It just needs my two cents before I reply-all and become a member of this movement." This can be a manager, a shoddy architect or head of the fabulous committee. They will typically want to take the simplicity of your solution, the simplicity you worked so hard to boil the problem down to, and introduce a little overhead, called process, so it's ready for the enterprise.

Would you like an auto complete widget with that sir? Super size implied!

Us poor Mavens are left in the dust because we've concentrated more on solving the problems than how to market and promote our own ideas. Especially if the idea is too simple. While it should be ideal, the non-Mavens tend to gravitate towards more complex and elaborate ideas because it makes them sound smarter. Kiss K.I.S.S. goodbye! These same people also tend to blindly gravitate toward "proven technology" because it's safe. The pencil is proven technology, but it wasn't safe for the companies that fell behind the computer bandwagon.

So with this blog I'm striving to achieve a community of what I'm coining Software Mavens so it can serve as a connector for the people who like us, have a real passion for the field. Because it's not just a job, it's a craft.

9.13.2009

Running tests from a Maven test-jar in your build

So one of the less frequently used features of Maven is that it allows you to package and deploy the test classes and resources to the repository. While the documentation suggests it's to reuse the tests, you can only use these as a standard dependency, not to re-execute them.

Well I was recently challenged with the task of re-executing the tests. I won't discuss the motivation behind the request as I'm not certain it's worthwhile. For now let's just assume you've been asked to do this too. I'll save you some time and share some of the things I discovered when trying to accomplish this.

So obviously we'll need to have the test-jar in the repository (see link above). We'll then need to pull it down and have surefire to execute it. The problem is that surefire does not have a "test jarfile" goal. So we'll need to leverage the unpack goal of the dependency mojo. Here is the xml for that:

<build>
<plugins>
...
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-dependency-plugin</artifactid>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactitems>
<artifactitem>
<groupid>com.hirn</groupid>
<artifactid>projecta</artifactid>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
<outputdirectory>${project.build.directory}/additionaltests/projecta/</outputdirectory>
</artifactitem>
</artifactitems>
</configuration>
</execution>
</executions>
</plugin>
...



I'm assuming some basic Maven knowledge here but please comment if you have more questions about how this is configured. There are a couple personal selections worth discussing here.

The first is the outputDirectory within the artifactItems section. It may be tempting to unzip into src/test/java so that surefire will just execute the tests as a normal part of the cycle. This isn't good though because you could potentially clobber a test that already exists there. You can't create a separate directory within /src/test/java either because the package names wouldn't be correct anymore. I choose to use ${project.build.directory}/additionalTests/ (aka target) so that things get cleaned up naturally. It's also important to unzip each artifactItem into a separate folder to avoid possible namespace collisions.

The second is when to execute the goal. Process test resources seemed like a natural selection here, even though it's slightly against purist Maven lingo as the "resources" directory non class files. Another option could be to use the pre-integration-test. Just as long as it's before the phase we configure surefire actually execute the tests.

Since we extracted the executable .class files to a separate directory, we need to tell surefire when and what to execute. Here's one example:


<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>project-a-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<testClassesDirectory>${project.build.directory}/additionaltests/projecta</testClassesDirectory>
<reportsDirectory>${project.build.directory}/surefire-reports/projecta</reportsDirectory>
</configuration>
</execution>
</executions>
</plugin>



Pretty straightforward. You have to make sure the phase is declared after the phase where the dependency is unpacked and point it to corresponding directory. The other piece to consider is that you don't overwrite the surefire report produced from running the rest of the tests. I couldn't find a way to aggregate the the report but wither or not you want to is personal preference. Would you even want your CI or reporting tool to track the success of executing these tests? Probably not, but you certainly don't want to affect the output of the tests within the projects.

You can download an example of this to see it in action. Just `mvn install` projecta and then do the same for projectb. You'll see the test run from projecta all over again.

Why I had to do this seemed to be pretty special case. My situation was driven by a peculiar scenario. There was a project A with dependencies A->B->C where A has a defect due to code that lives in C. Rather than create a new B, we just want to touch C and modify A such that A->B,A-C'.

One way to look at it is that there's no code change in B so why build it? The alternative is to say why not? Not only is rebuilding cheap (or should be), version numbers are free and it communicates to other projects using B that they need to upgrade to B'.

So if you have a good reason for executing tests from a deployed test-jar, I'd like to hear it. The whole time I was doing this it felt unnatural. I've never had to do this in over two years of extensive Maven use. The thing I love about Maven is that if it doesn't work automatically, you probably shouldn't be doing it. If this were truly useful, there would be a surefire:execute-jar goal.

9.02.2009

JQuery vs. Prototype

Well thank you Michael for my first comment. Michael Minella had posted this article in response to a comment I made about telling Prototype I was never coming home after being with JQuery. I thought Glenn made a nice fair argument that Prototype is NOT dead and JQuery isn't such a god send that we should never look at it again.

I'm still not coming home.

Without going into specific differences between the two (I think there are plenty of articles on that), what I personally enjoyed about JQuery was the almost configuration based approach to instrumenting events on the DOM elements, thus keeping all of the JavaScript in one place. Sure I learned after the fact that you can do it in Prototype too but JQuery kinda prescribes it with the $(document).ready() function. So I thank JQuery for opening my eyes to this style of instrumenting DOM elements.

Many people seem to use performance in this debate. I never noticed Prototype to be "slow" unless benchmarked against JQuery (slickspeed). But 1ms vs. 6ms? Come on it's the web! Where else do developers get so say to hell with shaving milliseconds? Most of my performance concern is server side where you are saving seconds or preventing a complete meltdown during peak hours. Sure if I were building an ACID compliant DB in JavaScript I might profile my JavaScript it but for making a <div> wiggle, the differnce in imprecivable. So any points about JQuery performance hold little water with me.

If performance were the primary concern, I would have prefered Dojo over Prototype. I'm sure Dojo's excellent in its own ways but the syntax always felt more geared towards developers instead of designers . When I'm knee deep in content, I prefer to keep my designer hat on. JQuery and Prototype/Scriptaculous both seem to keep me in my happy place, which is especially necessary for me when doing any front end development.

When it comes down to it, the tangible reason I now prefer JQuery was its suggestion that one should instrument elements in the ready() function, which in turn keeps event based function calls out of the HTML. That little trick was enough to make me really enjoy JQuery and I haven’t missed anything that would make me come home. Honestly, I wouldn't mind using either or at this point. They really are pretty similar as far as what you can get done and community support, even though JQuery seems to have the momentum at this stage in the game.

So, I’m sorry Prototype. I’ll never forget the awesome times we shared . Should we meet again, don’t be surprised if I pull out some tricks I learned while away.

8.21.2009

Off to vacation

Not to disappoint my numerous followers, but I'll be traveling for the next two weeks in South America. So there probably won't be any activity, nor will I be able to return e-mails or respond to comments.

Do stay tuned though.

8.19.2009

Neal Ford Keynote - Quite entertaining

Here's a link to an awesome keynote speech delivered by someone who I'm a big fan of, Neal Ford.

Relax! It's hosted on this German site so no I'm not trying to give you spyware. Then again if your browser can infect your computer because of visiting a site you probably deserve it.

I really liked this presentation. A lot of this stuff really hit home with me. The O'REALLYS Accidental Complexity book was terrific. I had to hear the term "NextGen" all year last year. Blowhard Jamboree? Brilliant. It's just great.

I had a stronger than usual dose of the daily wtf at work and this presentation actually prevented me from hitting the bottle immediately at 5pm. Perhaps the serenity it was able to grant me could save some other livers... or marriages.

Everyone should stop occasionally to ask themselves, WWNFD?

What is this blog for?

After many moons of considering it, I done went and set me up a blog. I though about doing something nifty and original, but when it comes to blogging it's really about the content isn't it? Thus the canned blogger site suits my needs well and what an opportunity to rip off some nice design!

In my petty amount of time as a software developer I've managed to expose myself to quite the laundry list of languages, libraries, servers, engines, middlewares, theories, methodologies... It's a laundry list of laundry lists.

So without further ado... This is my blog, Software Maven. Wikipedia defines maven as:
a trusted expert in a particular field, who seeks to pass knowledge on to others. The word maven comes from the Hebrew, via Yiddish, and means one who understands, based on an accumulation of knowledge.
I'm not proclaiming myself as "trusted expert". I don't even trust myself. The accumulation part sure rings true. I love to dive deep into whatever I'm working on and plan to return here to share it with whoever is willing to read.

No guarantees on what the actual content will be. As of now integration testing seems to consume most of my non-project time. Specifically I'm talking GreenPepper and Selenium. But who knows? I may just instead talk about how I slept with JQuery and told Prototype I'm never coming home.

Thanks for coming. Hope to see you again!