Tuesday, October 30, 2007

Pair Programming : Compatibility of a Pair Really Matters

I've been a practitioner and supporter of Agile methodologies for a few years now and most of the time I think it's great. TDD/BDD (Test-Driven Development/Behaviour-Driven Development) and Pair Programming are import tools in one's Agile tool set.

Recently I've been pairing in Java with some very intelligent guys from a Ruby and C++ background. This obviously made for some very interesting pairing. Being primarily from a Java background myself (having left C++ in the dust over 5 years ago) I've become accustomed to certain niceties in Java. A single class with a single purpose, meaningful method and variables names, refactoring, IDE support and most importantly testing/specing code before writing it are some of the more important ones.

These concepts blend very well with someone with a Ruby background mainly because they use some or all of these concepts and have other great concepts that Java could adopt. Unsurprisingly, pairing with the Ruby guys was very productive and the code fairly well designed and implemented.

In the last week I've been pairing with someone from a pure C++ background and the results have been mixed. Pure C++ programmers are eager to come up with the "best" the solution to a problem immediately. No TDD/BDD, no testing/specing - just full steam ahead! I feel this is anti-agile, as you have preconceived notions about how the code should be written before even writing it. This leads to a somewhat haphazard "design" and hence complicates everything from this point onward. When TDDing/BDDing, we drive out a good design through tests/specs and by bypassing these steps we loose out on this benefit.

The other important difference I saw between pure C++ and C++/Ruby programmers was that it was more challenging to get the pure C++ programmer to write even the simplest test/spec. "Why do we need it?", "I know what the solutions is", "This is a waste of time" were some of the usual comments that one could hear floating around. These are all valid questions/statements. But it hinders more than helps when you have to constantly justify to someone why testing/specing is good. This definitely slows down any forward momentum. I feel that anyone doing pair programming should at least have a cursory understanding of the benefits and drawbacks of TDD/BDD.

Another facet of pure C++, namely writing the most efficient solution upfront is another hurdle to jump over when pairing. Premature optimization usually leads to very hard-to-maintain code. I find it very hard to get someone out of this mindset when programming in a language like Java. Long variables and method names look ridiculous to pure C++ programmers because this is not what they are used to. Soon it becomes a struggle. You want to name everything in the most readable way possible while the pure C++ programmer wants to name everything as terse as possible. You want to have more classes with a single purpose, they want to have less classes which were are compact as possible. You want to reduce complexity, C++ programmers are "used to" complexity and don't have problem with it. What to do, what to do?!

As with anything in life, there has to be some give and take. All taking and no giving does not make anyone happy...well....almost no one! :) So you have to make sacrifices (at the Java alter of goodness) and win wars and fore go battles. Corners get cut and your confidence in the code and that warm fuzzy feeling begins to dwindle.

So at the end of the day, the question is, how good is your solution when you have such forces competing in opposite directions? I would say less than optimal. Did we get a working solution ? Yes, definitely. Is it something I thought was great and easy to understand and maintain? Probably not. Was it something the pure C++ programmer thought was efficient and the most elegant solution? Probably not. So was this a win-win situation for the customer and programmers involved? Probably not.

So the point to my long rambling is this: The effectiveness of pair programming depends on who you are pairing with, their technical background, personality, work ethic and how much they like working in a "team". To get the best out of a pair I definitely feel that these factors should be considered before pairing together 2 individuals to solve any business problems.

Saturday, October 20, 2007

Ubuntu: Installing the latest JDK or JRE

In this tutorial I will show you how to install the latest JDK or JRE on your Ubuntu box. I am using JDK1.6 update 3 on Ubuntu 7.0.4 (64-bit) on an AMD64 CPU for this tutorial.

Commands are in bold and blue, paths are in bold while user input and program output are in green italics.

1. Check your current version of java with:
java -version

This should give you something similar to:
java version "1.4.2" gij (GNU libgcj) version 4.1.2 (Ubuntu 4.1.2-0ubuntu5) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you have the default Ubuntu JRE installed.


2. Download the latest bin file for the java version you require (for linux) from Sun. (Ensure you get the correct bit version for your operating system (32 or 64)). I used Jdk1.6 update 3 for 64-bit linux running on an amd64 cpu. (jdk-6u3-linux-amd64.bin)

3. I usually install all shared software under /opt. Copy the downloaded bin file into /opt with:
cp Desktop/jdk-6u3-linux-amd64.bin /opt

assuming you downloaded the file to your desktop. If not use the correct path to your bin file in the above copy statement.

4. Make the bin file executable with the following:
sudo chmod 777 jdk-6u3-linux-amd64.bin

Enter your user's password when prompted. Check that the above command succeeded with:
ls -l jdk-6u3-linux-amd64.bin

The output should be similar to the following:
-rwxrwxrwx 1 root root 62140783 2007-10-20 01:03 jdk-6u3-linux-amd64.bin

We are interested in the last x in the list of privilege which specifies that all users can execute the bin file.

5. Run the bin file as sudo:
sudo ./jdk-6u3-linux-amd64.bin

This should bring up Sun's documentation with a --More-- displayed at the bottom.



Use the enter key to navigate to the bottom of the document. When asked whether to accept the conditions type:
yes




This will extract the bin file into the /opt directory, creating a jdk1.6.0_03 directory. If you did get permission errors while running the bin file ensure that you ran the bin file with sudo and that you are in the admin group of the machine on which you are installing java.

6. Create a symbolic link to the installed java version with the following from the /opt directory:
sudo ln -s jdk1.6.0_03 jdk16

This will create a symbolic link to the jdk1.6.0_03 directory through the jdk16 directory. A sybolic link is similar to a shortcut in Windows. It provides an alias to directory. The benefit of this is that if you install the next latest version of java you can simply update the symbolic link to that version and all your programs that refer to jdk16 will work with the latest version of java.

Verify that the symbolic link has been created with following from /opt:
ls -l

The jdk16 -> jdk1.6.0_03 signifies the symbolic link.
lrwxrwxrwx 1 root root 11 2007-10-20 01:05 jdk16 -> jdk1.6.0_03

7. Now we need to update PATH and JAVA_HOME variables for your user. Edit the .profile file found in your home directory (home/your_user) with a text editor such as vi or gedit:
vi ~/.profile or
gedit ~/.profile

(~ denotes your home directory)

Add the following lines to the bottom of this file:

export PATH=/opt/jdk16/bin:$PATH
export JAVA_HOME=/opt/jdk16

save and close the file. The .profile file is run when you log into the system. So the next time you login the PATH and JAVA_HOME variables will be set appropriately.

8. Logout of your user and log back in. You can do this in the GUI or simply type:
logout
if you are connecting through a terminal.

9. Log back in with your user.

Verify that the PATH is set to the jdk bin directory by typing the following:
env | grep PATH

This should give you something like:
PATH=/opt/jdk16/bin:/usr/local/sbin:/usr/local/bin

Make sure the /opt/jdk16/bin is the first path entry.

Verify the JAVA_HOME variable with the following:
env | grep JAVA_HOME

this should give you the following:
JAVA_HOME=/opt/jdk16

Now verify the java version with:
java -version

You should get something similar to the following:
java version "1.6.0_03" Java(TM) SE Runtime Environment (build 1.6.0_03-b05) Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode)

10. Congratulations, you have now installed the latest version of java! :)

Monday, October 15, 2007

How Wacky can Windows Get?

Yeah, don't answer that. I was recently copying some files from my digital camera and got this surprisingly astute message:



Unfortunately, I won't be alive for another 21860 days (59 years) until 321 MB is copied from my memory card, well maybe... What to do? What to do? :P

Sunday, October 7, 2007

Ubuntu: How do I find out my Ubuntu version?

Type lsb_release -a at a command prompt. This will give you information about the version of Ubuntu that is running plus it's code name etc. Type uname -a get information about whether you are running 32-bit or 64-bit Ubuntu.


This shows information about the 64-bit (or x86_64) Ubuntu 7.0.4 (Fiesty).



This shows information about the 32-bit (or 686) Ubuntu 6.10 (Edgy).

Saturday, October 6, 2007

Welcome

Welcome to the Babylon Candle! The "Babylon Candle" is a concept I "borrowed" from the movie Stardust. A Babylon Candle allows the owner to transport him/herself anywhere in the world just by focusing on that location. So it doesn't make much sense for a blog name, but it does sound cool! :)

This blog will focus mainly on development related articles using Java, Windows (Shock! Horror!) and Ubuntu. Being a mostly windows programmer I moved to Ubuntu around 6 months ago. The learning curve has been pretty steep, but I'm moving all my machines to Ubuntu one by one. I hope to blog some general how-to's with Ubuntu specially for that windows user who has made the recent move.

- Sanj