magpiebrain

Sam Newman's site, a Consultant at ThoughtWorks

Posts from the ‘Java’ category

Introduction

With my sojourn at my current client due to come to an end at Christmas, I’ve started a period of documenting some of the things I’ve learnt. As I’ve “mentioned before(magpiebrain – There are some things you just don’t want to learn)”:http://www.magpiebrain.com/archives/2004/11/18/lessons , not everything I’ve learnt has been pleasant, but it’s all be informative. One of the most valuable experiences has been my first exposure to Weblogic. Previously I’d worked at smaller clients, and as such had only really used JBoss, so a chance to use what is considered by many to be the best of the “big” J2EE containers was welcome.

In general, I was fairly impressed with Weblogic. Yes it costs a huge amount of money. No, it isn’t perfect. But it does have some excellent features, especially impressive being it’s cluster management. So, for posterity’s sake (and for the sake of my own poor short term memory) I thought I’d introduce some Weblogic clustering concepts – domains, admin servers, node managers, managed instances and of course, clusters.
Continue reading…

Introduction

As you may remember, I’ve been struggling with a tricky build at my current client. Whilst many of the problems have been around how we’ve used the tools available to us (well, Ant), I realised that Ant itself might just not be up to the job. Once a build becomes non-trivial, you inevitably want to start using it as a program, something Ant itself is not really good at.

“SCons”:http://www.scons.org/ is a build API form python. Being based on a proper programming API the promise of testable build processes, nice syntax (no more ghastly constructs just to do the build equivalent of an @if@) and above all a system more intuitive to the average programmer than Ant is.

When looking to adopt any open source tool it has to prove itself to fairly quickly – in the case of SCons I set it a few challenges and see how it stacked up.
Continue reading…

I’m currently working on a project with a relatively large (~2000 line) Ant build file, with several supplemental files. The first thing that’s struck me, is that something about the nature of Ant itself makes people treat it very differently from the code it’s building. Rules concerning consistency, testing, maintainability and even common sense seem to go out the window. Whilst it’s true that Ant doesn’t go out of its way to help us – there is little tool support and the XML syntax is fundamentally unsuited to a program (which is really what an Ant file is) – if developers engaged their brain a little more, they’d make life a little easier for everybody.

I’m going to revisit some of the problems with Ant at a later date, but today I’d like to focus on one particular annoyance – the use of the full stop in naming of targets and properties.
Continue reading…

“FreeMind”:http://freemind.sourceforge.net/ is a pretty good open source “mind mapping(Wikipedia – Mind mapping)”:http://en.wikipedia.org/wiki/Mind_mapping tool, which we’ve been using to capture the efforts of various bits of brainstorming, as well as keep track of ever evolving processes. One of the processes we’ve detailed using FreeMind has been our build process – during which I was struck by just how good FreeMind could be at actually modelling an “ant”:http://jakarta.apache.org/ant build structure. High level tasks (such as @deploy@) can be easily broken down into smaller dependent tasks (@compile@, @copyToServer@ etc).
Continue reading…

Act 1: In support of the pessimist

==

Fred:
So, I’ve made this thing for you
Bob:
Cool! What’s that tube for – and why the electrodes?
Fred:
Don’t worry about that, have a play…
Bob:
Cool, now – what does this do? Oh, and if I poke a stick there, put my finger there, then stick my tongue in the power socket…*ouch*!
Fred:
Dammit! That’s not how you’re supposed to use it! I’ll never get that out of the carpet now….

==
Continue reading…

Simple code that works is only considered a bad thing by programmers who either don’t care about maintainability, or like to hide their inadequacies behind complex solutions.

During a pairing session today, we spotted some duplicated code and a period of refactoring ensued. The code in question related to some simple DB queries – the code for getting a connection, returning results and cleaning up was duplicated, with only the query and the exact part of the result set required being duplicated. We already had some code which could be used to remove this duplication – previously someone had written a DB visitor which was being used internally in a test class.

Extracting the visitor code out into a class in its own right was trivial. What was not was replacing the repeated code. After 10 minutes of head-scratching we had to ask ourselves the question “is this still refactoring”?

Let’s look at what we had done – we’d extracted out our visitor code to make it an object. The existing code using the visitor still worked. We couldn’t get other code using our visitor happily quickly. We decided to leave it and move on – the rational being that refactoring should be something quick you do in the normal test-code-refactor process. If you can achieve a quick win that improves code outside the scope of what you are working on, then great – but when improving code outside the purview of your current task takes too long, it feels like going off at a tangent.
Continue reading…

A largely unenjoyable couple of hours was spent tracking down a nasty little issue surrounding classpaths in cygwin. First a little background. On Windows, if you want to specify a classpath, @java@ expects it to be a series of semi-colon separated paths, like so:

set CLASSPATH=c:libsome.jar;c:classes;.;

On Unix, @java@ expects a colon separated list:

export CLASSPATH=/usr/lib/some.jar:/home/export/myarea/;.

I’m playing around with using a shell script to run my app on windows, however I’m using cygwin as I hate writing bat files. This is a bit of a problem however – cygwin expects Unix format paths, but we’re still running a Windows version of @java@. Once I’d worked out that this is what was causing the strange ClassNotFoundExceptions, a quick google turned up @cygpath@, which can translate from Windows to UNIX paths (and vice versa). So, when invoking @java@ in my shell script I just changed:


java -classpath $MYCLASSPATH org.package.MyClass

to:


java -classpath `cygpath --path --windows $MYCLASSPATH` org.package.MyClass

Next up, I can change my script to work on Unix by conditionally invoking @cygpath@ only if I’m running in a cygwin bash shell.

No posts from me in a while which has mostly been down to playing sys admin at my current client – more on this in a while no doubt. In lieu of anything of greater interest, I thought I’d remind you of two upcoming events for your calendar, if you happen to be in London in the next couple of weeks.

Firstly, the monthly “Java meetup(London Java Meetup – 23 August 2004)”:http://web1.2020media.com/j/jez/javanicuscom/londonjava/ will be on the 23rd of August. I’m hoping for something a little more laid back than last months mammoth affair as I hardly got to talk to anyone. No real topic, but expect talk on Java, beer, blogging and state machines.

Running both this and next Wednesday, is Geek Night London. More of a techy affair than the Java meetup – and non-Java specific too, it involves a bunch of us working on Open Source stuff, talking about it, and normally eating pizza. I’ll be working on either “JBehave”:http://jbehave.codehaus.org/ or “DamageControl”:http://damagecontrol.codehaus.org/ depending on how I feel. If you want to pop by for either this or next week, then stick your name down “on the Wiki”:http://geeknight.thoughtworks.com/index.php/GeekNightLondon.

I’m hoping to have another successful GeekNight tonight. It’ll be more development focused I expect – I’ll be working on a UI for JBehave (with a view to creating an IDEA plugin) and no-doubt others will be doing development they’d appreciate help with. If you fancy coming along, pop over to the wiki and “put your name down”:http://geeknight.thoughtworks.com/index.php/GeekNightLondon28July2004. More details can be found “here”:http://geeknight.thoughtworks.com/index.php/GeekNightLondon.