magpiebrain

Sam Newman's site, a Consultant at ThoughtWorks

Posts by samnewman

As this blog has attracted more and more visitors each month, the number of comments I’ve been receiving has also been on the increase. Every now and then one of my threads generates some extremely interesting feedback, and it was starting to get annoying that I couldn’t reference these comments directly. What I really wanted was the ability to link directly to a comment.

A quick look through the Movable Type documentation, and I found details for the @MTCommentID@ tag. Simply put when placed inside an @MTComments@ tag (or in my case “@MTSimpleComments@(Plugin which will print comments and trackbacks in the same listing.)”:http://mt-plugins.org/archives/entry/simplecomments.php) it will print the ID for a comment. It is then a simple matter to create an HTML anchor for that specific comment like so:

" />

In of itself this isn’t terribly useful – I need to look at the source of the page to get the anchor name, and then have to create the link by hand. So I’ve also added a comment permalink, using the following code – again within the @MTComments@ tag:

#"
title="Permalink to this comment">Permalink

So, when I next get an interesting post, I can link right to it, and so can anyone else.

_Updated_: I posted more on this subject in “Comment Permalinks revisited”:http://www.magpiebrain.com/archives/000223.html.

Matt Riable has encountered a performance issue with his JUnit tests, and is “advocating the use of static data(Make your JUnit Tests run faster when using Spring)”:http://raibledesigns.com/page/rd?anchor=make_your_junit_tests_run to construct his Spring @ApplicationContext@. I think in this specific instance he might be justified in his choice (I’m nothing if not pragmatic) but I am always extremely cautious in allowing the use of a shared environment between tests.

Lets look at the crux of Matt’s problem – by the book you should define the environment for a test within @setUp()@, and should clear it up in @tearDown@. @setUp@ is called before each @test@ call, and @tearDown@ after, in order to isolate each test from the other. In Matt’s case, the @setUp@ call is quite slow – the creation of his @ApplicationContext@ involves file IO and XML parsing, not the fastest of processes. So why is @setUp@ called prior to each test? Let’s look at a very simple example:



public ExampleTest extends TestCase {
  private SharedObject sharedObject;

  public void setUp() {
    sharedObject = new SharedObject();
  }

  public void testOne() {
    //run some test using sharedObject
  }

  public void testTwo() {
    //run some test using sharedObject
  }
}

Imagine if @setUp()@ is only called one for the whole @testCase@ – what if @testOne@ or @testTwo@ change the state of @sharedObject@? If @testOne@ is run first, then @testTwo@ will be reliant on the state of @sharedObject@ manipulated by @testOne@ – can you be sure @testTwo@ will still work if you run it first? Many of us run our JUnit tests directly in our IDE, and we have no control over the order in which tests are run. By sharing potentially mutable data between tests we are exposing ourselves to the possibility of variable results based on the order in which tests are run.

Now I’m not advocating the notion that shared data should never be used – for example I cannot see a problem sharing immutable data between tests. However think very carefully about sharing any data which has the capacity to be altered by one of the tests – its important to balance the benefits of instantiating Objects once for all of the tests against the potential risk of poluting the state of one test with the operations of another.

I was playing around with the Regular Expression support in Java 1.4, with a view to repeating my earlier tutorials on the use of sed for text manipulation (this time with Java), when I can across a rather strange problem. Imagine my input is a multi-line string, part of which looks like this:

|          Serial          |
|        1234567890        |

I want to match the serial number, which in this case is 1234567890. First off, I want to match the title itself (I cannot just assume any numbers are serial numbers) but I also have to match the numbers themselves. The code to match the string I want to extract the number from looks like this:



String input = "|          Serial          |n|        1234567890        |";
Pattern p = Pattern.compile("Serial(?s).*[0-9]+");
Matcher m = p.matcher(input);

while(m.find()) {
  System.out.println("Matched String " + m.group());
}


Note: The use of the embedded (?s) tag forces the . to match line terminators – by default it doesn’t unless this flag or DOTALL is used.

Put simply the pattern reads “Match the work serial, followed by any characters until you get to a list of numbers and stop there. Sure enough, running this gives the following result:


Found match Serial          |
|        1234567890

Next I group the numbers being matched using ‘(‘ and ‘)’. This gives me grouping exactly as with sed – I can now index these matching groups, using m.group(index):



  String input = "|          Serial          |n|         1234567890        |";
  Pattern p = Pattern.compile("Serial(?s).*([0-9]+)");
  Matcher m = p.matcher(input);

  while(m.find()) {
    System.out.println("Found match: " + m.group());
    System.out.println("Found serial number: " + m.group(1));
  }


But this gives the following output:


Found match: Serial          |
|        1234567890
Found serial number: 0

For some reason the grouping is only matching the last number, not the whole list. I can’t for the life of me work out why…. Oh well, expect some tutorials on the use of regular expressions soon.

_Updated_: ditched all the dashes as they screwed up the formatting.

_Updated_: Fixed the second code fragment

“Paper prototypes”:http://www-106.ibm.com/developerworks/library/us-paper/?dwzone=usability are a great tool for quickly designing and demonstrating GUI. Sometimes however the interactions can be a little hard to see – in which case a GUI-prototype can be a boon. Problems can come however from knocking up these dummy interfaces – management and users can get the idea that the product itself is nearly done, or they may start obsessing on little UI idiosyncrasies that aren’t really the point of the exercise. Ken Arnold’s “Napkin Look and Feel”:http://napkinlaf.sourceforge.net/ is an attempt to give coded interfaces a paper-prototype feel – so users get a clear idea that this is a rough draft and nothing more. The webstart demo sows the SwingSet demo using the new look and feel, and it seems to work very well.

File Under…

Ideas for a new .com website now the bubble is expanding again

Synopsis

Site rates things based on their evil nature

Evil List

* Getters
* Setters
* GOTO’s
* Sun/Microsoft settlement
* Renaming Patterns
* Long Commutes

Not Evil List

* Expose
* Battlefield Vietnam
* Scripting Languages
* Categorising people as Dwarves, Elves, Pirates or Ninjas

Pending filing

* Groovy
* Egoware
* Extreme Programming
* Lotus Notes

_Update_: Both “Mark Pilgrim(Interoperability)”:http://diveintomark.org/archives/2004/04/06/interoperability and “Russell Beattie(Real Player 10: Evil or Not?)”:http://www.russellbeattie.com/notebook/1007374.html are also categorising things as evil or not.

**Project proposal**: An IM client that synchronises seamlessly with a contact list stored in an enterprise social network system (think: MS Exchange (webdav?), Confluence).

**Initial thoughts**: Use Jabber

**Project Abstraction**: Generic notification mechanism which could be used to send email, SMS, IM. Useable by CruiseControl/DamageControl/Confluence/IM client etc.

**Rational**: Certainly a need for this at work. Is there desire enough to do it?

_Update_: Also think friendster/orkut integration. I’m thinking a server with modular contact discovery mechanism, with client abstraction. Suport for multiple IM protocols or just use Jabber? YAGNI – use Jabber. I should really stop engaging in design by blog.

_Update_: Look at Jain – “JSR 187(JSR 187: JAINTM Instant Messaging)”:http://www.jcp.org/en/jsr/detail?id=187.

A bustle of activity. Sweat. Testosterone. A small amount of oestrogen. Comically small hockey sticks. Ego. A distinct lack of pizzas. Such is “GeekNight”:http://geeknight.thoughtworks.com/index.php/GeekNightLondon in London. Who knows if anything’s actually going to get done?

So, in a room of bright people, do you yourself feel inspired? Intimidated? Is it wrong to feel just plain bored? There is a strange background buzz generated when one is genuinely uninterested in what’s going on. It filters out anything else which might distract you from the task at hand – even if said task is being bored. Let’s imagine you actually had something you wanted to do other than stare into space. Where better to be than in the midst of busy discussion which leaves you cold – and environment in which you can be confident that you yourself will be left to your own devices, where you can go unnoticed.

Dave Winer makes some “interesting points(The baby squirrels grow up)”:http://blogs.law.harvard.edu/crimson1/babySquirrelsGrowUp concerning the “recent furore(Jay Allen – The TypeKey FAQ)”:http://www.jayallen.org/journey/2004/03/the_typekey_faq surrounding some of the recent announcements made by “SixApart”:http://www.sixapart.com/ concerning features forthcoming in new versions of MovableType. He identifies SixApart as a company at a major milestone in its development – its shift from becoming a company that is know primarily for producing free software to a company producing commercial software.

This shift in focus brings about an inevitable change in priorities:

Basically Six Apart has been at a fork for some time, on one fork are the paying customers, and the other fork is the “community” that has carried them along. I recognize some of them as early UserLand people, and I recognize the attitude as that of software believers. These are good people, they report bugs diligently, cheer you when you add a new feature or fix a problem. They are the salt of the earth. You need to have people like this around to make good software.

But you also need the people who pay the bills, and eventually their needs conflict, and you have to a make choice, and if you’re running a business, as Six Apart is, you have to go with paying the bills. That leaves a bunch of people behind, and they are angry (justifiably) as they decide whether to stay or go.

It would be better if the users could factor this into their thinking and not hate so much and also not love so much. Software is not a miracle, it’s a lot of hard work, and it’s expensive hard work. And the funny thing is that as the anger escalates, the work gets harder, and you end up in a spiral.

I’ve seen this in action in a few situations. Some handled the transition to a full-on commcerial body very badly (see the whole Smoothwall debacle and the resulting IpCop fork), others a little better (JBoss) and select few very well (MySql). On the one hand without the original early adopters, these companies wouldn’t be in a position to be developing commercial software (or providing commercial services) in the first place – on the other hand very few of these users will be paying for development. Keeping both camps happy is something of a balancing act, and I wish SixApart all the luck in the world as they attempt to walk this particular tightrope.

My new role has started in earnest today, with me being packed off to a client site. Most of the day was spent tinkering with my nice shinny new laptop (ohh – wifi and bluetooth!), learning how to use Lotus Notes (ohh – really slow mail client!), and trying to remember about 50 peoples names. I’ve also been issued with an “RSA SecurID”:http://www.rsasecurity.com/products/securid/ token, which has had me enthralled since I recieved it. The device generates random numbers for use with accessing my companies intranet when off site – I’ll post more on the device later.

I’m aware that I’ve not published much information on my spring-rcp work, and that’s because I haven’t done much at all. Hopefully this weekend will give me a chance to take stock and see what needs to be done.