magpiebrain

Sam Newman's site, a Consultant at ThoughtWorks

Posts from the ‘Uncategorized’ category

A “post(Test Driven Design vs. Design by Contract)”:http://creativekarma.com/more.php?id=80_0_1_0_M by Doug over at Creative Karma takes issue with the fact that I consider Test-Driven Development to be “quite similar(Test-Driven Development vs Design By Contract)”:http://www.magpiebrain.com/archives/000191.html to Design by Contract. After reading over the piece, I have to agree that at Doug is correct. What I meant to say is that you can almost consider TDD to be a subset (or variation of a subset) of Design by Contract.

What do I mean by that? Well, in TDD you start of with a goal. This goal tends to be fairly specific, but of course comes from a larger idea of what the system should do (most TDD texts seem to skip the part where these specific tasks actually come from, as I’ll do here). This is typically something like (to borrow Kent Beck’s example) “I need to be able to add 5 US dollars to 10 Euros and get a result of 20 Euros if the dollar to euro exchange rate is 1:2”. The developer then breaks this down into solvable tests, which lead to the code being implemented. Each little unit we are defining the tests that let us know the code is working – with Contract By Design you can define pre and post-conditions (this needs to be true before, this needs to be true afterwards). At this level the similarity between the two is clear. However Contract By Design goes far beyond this small scope, to define class invariants, loop invariants etc. I’m not saying one is better than the other, but I do feel they share some of the same benefits.

Doug finishes up thus:

Not only are unit tests black box, they also only test certain cases. A contract specifies the required behavior for every case, and any assertion associated with that contract verifies that the behavior is correct for every case that is encountered. That is what Bertrand Meyer was referring to when he said, “A test checks one case. A contract describes the abstract specification for all cases.”

I agree completely – and this is the point that Bertrand Meyer was making when he talked about systematic testing:

It was shown many years ago through a very simple argument that there’s no such thing as an exhaustive test, a test that exercises all possible cases. So we know we can’t have an exhaustive test, but we can have systematic tests that have a likelihood of exercising the cases that will fail. For example, if you have a parameter that must be between certain bounds, then you want to test the values close to bounds of the range. You want to test maybe the value in the middle, and maybe a few in-between. So we want to have tests that are systematic in that sense, and contracts help a lot generating such “systematic” tests.

Unit tests are not the same as a contract, they merely attempt to prove that the code satisfies the required contract. The better the tests, the more systematic they are, the more you have proved the contract fulfilled and that the code is of decent quality. One single test is not always enough for you to strike that taks of your todo list. No matter what your position is on this particular topic, I think we can all agree on these two points that Doug makes in summation, which I’ll reiterate here so I don’t forget them:

  • Testing cannot show the absence of defects, it can only show that defects are present.
  • We cannot test quality into a product, we have to design it in.

In Artima’s “third part(Contract-Driven Development – A Conversation with Bertrand Meyer, Part III)”:http://www.artima.com/intv/contestP.html of their interview with Bertrand Meyer, some interesting comparisons regarding Design by contract and Test Driven Development are made. Bertrand Meyer makes the point that the small units of work that get undertaken in a TDD cycle (write the test, run the test, refactor) and very specific tasks that are nothing more than testing/implementing parts of a wider contract. When I use TDD, I do in fact tend to write at the top of my todo list the overall task I’m trying to achieve, which I’ve realised is the contract itself. I do not think there is much difference between the TDD and Contract-Driven approaches, certainly they try and achieve the same goal – which in Bertrad’s own words is to “build software in which reliability is built in rather than achieved after the fact through debugging”, or as Kent Beck would say (to paraphrase) “Ask the computer if it works, don’t try and work it out for yourself”.
The differences between the two are simply down to scope. The scope of a contract can be as small as a single test for a trivial example – or it can be as large as several. Both approaches still require that the larger problem be broken down and solved, and be proven to work. It seems perhaps that yet again we have another virtually identical solution for the same problem.

I’ve been away for a while (due to a debauched weekend and an illness whose effect I doubtless exaggerated), so I thought a brief roundup was in order

* Matt Riable has posted an “interesting piece([DisplayTag] Changing a row’s CSS class based on values in the row. )”:http://raibledesigns.com/page/rd?anchor=displaytag_changing_a_row_s on getting the “Display Tag Library”:http://displaytag.sourceforge.net/ to style rows based on table values.
* Simon’s posted an “overview of JRules(JRules – A brief overview)”:http://www.redhillconsulting.com.au/blogs/simon/archives/000132.html on the JRules business engine. It doesn’t seem as flexible as Drools, but is interesting due to its support for the ILog Rule Language (support for which could doubtless be added to drools as a semantic module). I did find a helpful pointer to Ronald G. Ross’ “Principles of the Business Rule Approach”:http://www.amazon.com/exec/obidos/tg/detail/-/0201788934/002-9283932-1911238?v=glance which has gone on my wish list.
* I discovered “Nagios”:http://www.nagios.org/, which appears a lot of what “Big Brother”:http://www.bb4.com/ does, only for free. Too bad in my new job its unlikely I’ll be doing any system admin stuff like I am now.
* Keith Donald has “checked in”:http://jroller.com/page/kdonald/20040308 the latest version of his and Seth Ladd’s validation framework into the Spring CVS sandbox. I’m in the process of integrating this with my command-framework.
* Daido Metal has announced a “toy car”:http://www.engadget.com/entry/1882334012266534/ that uses a water-powered fuel cell to generate hydrogen. I really need to read up on this kind of stuff…
* David Miller’s “Zebra Tables”:http://www.alistapart.com/articles/zebratables/ for “A List Apart”:http://www.alistapart.com/ shows you how to style your tables nicely using some CSS and Javascript.
* I became even more of an IoC Zealot, and as such started “defending the constructor(Daniel Bonniot’s Weblog – Are constructors useless?)”:http://www.jroller.com/page/dbr/20040309#are_constructors_useless.
* I read a book about “loosing a penguin(Penguin Lost )”:http://www.amazon.co.uk/exec/obidos/ASIN/1843430959/ref=sr_aps_books_1_1/026-5985556-2226861 and a “bigger book(Paul Auster – collected prose)”:http://www.amazon.co.uk/exec/obidos/ASIN/0571218474/qid=1078933755/sr=2-3/ref=sr_2_3_3/026-5985556-2226861 arrived.
* I also realised my books to read stack was growing rather than shrinking, and that I had less money than I thought. I think these two facts may be related.
* I discovered a lovely little shop on the “Portobello Road”:http://www.portobelloroad.co.uk/ that sells very nice cupcakes.

My posting has been somewhat infrequent of late, primarily due to time being spent job hunting. It actually went rather smoothly, however both of the jobs I was looking into had some rather rigorous application and interview procedures. Having successfully navigated both rather tortuous processes, I’ve made my choice and will be starting my new job by the end of March (don’t ask who – I ain’t going to tell). Hopefully between now and then I can knock some items off my todo list, such as:

* Site redesign (probably going to be less radical than I originally thought)
* Upgrade MT version and various plugins (Textile, MT-Blacklist)
* Research for future articles (one at the use of CSS+JSP, NanoContainer, perhaps IoC life-cycle)
* Finish my Fowler->Rest Of The World pattern dictionary (where our hero attempts to work out the mapping between Martin Fowler’s pattern names, and the names everyone else actually knows)
* Steam clean my carpets…

Well, you get the idea.

This is rapidly becoming a log of my stupid mistakes, but I thought I’d post another beauty from the Extremely Tired And Lacking In Coffee school of programming. A stored procedure was returning some very strange results – namely it was returning the same record no matter what was passed in. My procedure looked like this:


CREATE OR REPLACE FUNCTION get_some_info(customerId NUMBER)
	RETURN mercury.GenericCursor AS
res mercury.GenericCursor;
BEGIN
OPEN res FOR
	SELECT someinfo
	FROM customer
	WHERE
	customerid = customerId and
             ...;
RETURN res;
END;

Anyway, no matter the customerId passed in, back came the same record. Eventually my more SQL-minded colleague pointed out that Oracle is case insensitive at matching the parameter/column name and returned me the first record. A quick rename of the parameter to customer_id and all was well. It would of been nice if Oracle had thrown an error or at least a warning when I gave it the procedure – even so, not one of my finer moments.

Since I first heard about the notion of tablet based PC’s, I actually first thought about those little screens used in Star Trek TNG – little, A5 devices that fit in your hand. The reality was big, heavy laptops. Now thanks to the “Transmeta Crusoe”:http://www.transmeta.com/crusoe/index.html chip, the “oqo”:http://www.oqo.com/hardware/ looks like it might make the tablet PC a reality. Its about the size of a video tape, complete with a 1 Ghz processor, touch screen and keyboard. Oh, and its wireless. With bluetooth. And a 20GB hard drive.

No information on prices as yet, but according to “the inquirer(Transmeta’s goldfish conquer fear of Windows )”:http://www.theinquirer.net/?article=13578 it should be available in a few months, although the oqo website states that fall 2004 as being the expected arrival time.

I’ve just installed Oscar Hills’ very fine “EZ Subscribe To Comments(www.ofhills.com: November 18, 2003 Archives)”:http://www.ofhills.com/archives/2003_11_18.php plugin. It should allow people to subscribe to my various entries and track any comments made. It also provides a web-based interface for management of the subscriptions, so you can easily alter your subscription options. I have to give kudos to Oscar for this – the plugin installed very easily (a single file, no hacking of MT required) and worked first time. My comment forms now look a little ugly with the extra subscription options, but I’ll look to tidy this up in the next few days.
I have managed to overwrite the comment listing though, which will take me a bit of time to sort out. Anyway, feel free to post some test comments on this post and try the subscription options!

[Update: 09/01/2004, 10am]: The comment listing is fixed, and eveything seems ok now.

[Update: 09/01/2004, 11am]: Cleaned the comment form up a bit (its still pig ugly) and made sure the subscription options appear on all comment forms. I also found a bug whereby the blockquotes java script wasn’t being applied on some pages – this is also resolved.

Well, I’m back. I only have one new years resolution, but I’m not telling anyone what it is – at least not via this blog. I had a good Christmas and New Years, and have already started getting depressed at the thought of going back to work. Such is life. Presents included Bill Bryson’s “Dictionary of Troublesome Words(Amazon.co.uk – Dictionary of troublesome words by Bill Bryson)”:http://www.amazon.co.uk/exec/obidos/ASIN/0767910427/qid=1073234850/sr=2-1/ref=sr_2_3_1/026-0302931-1126870, Ryan Adams Album “Rock N Roll(Amazon.co.uk – Rock N Roll by Ryan Adams)”:http://www.amazon.co.uk/exec/obidos/ASIN/B0000PCUHQ/ref=sr_aps_music_1_1/026-0302931-1126870 (seeing him again in a couple of months), and some nice crockery for eating my takeaways off. I also decided to buy an iBook, then looked at my bank balance, and realised that I’d be better off buying an etch-a-sketch. On a Java-related note, my article on IoC, Spring and PicoContainer is going well – the prose is finished, it only remains to write the actual code. Expect more on this soon.

Ex RedHat CEO Bob Young gave an “interview(Lulu : Marketplace for a World of Digital Content)”:http://www.infoworld.com/article/03/12/11/HNredhatfounder_1.html to Robert McMillan this week as a followup to “his response”:http://www.lulu.com/journal/scoletter?fTheme=community to “Darl McBrides”:http://www.sco.com/copyright/ earlier open letter. Of particular interest to me is his detailing of damage mitigation, which he explains far better than I can:

…the way copyright law works is you have to prove damages. And there’s another concept in American law, which says you’re required to mitigate your damages. In other words, just because you know someone did something bad to you, you can’t maximize the impact of that bad thing and then claim a much bigger penalty against the person who did the bad thing to you because you maximized the harm.

Let’s take an example. If someone hits your car, your car is now damaged. But in order to maximize the penalty, you know your car is going to break down if you drive it to New York, but you drive it to New York anyway, because you know you can sue the guy who hit you for wrecking your car on the way to New York. Well a judge would say, ‘No, he should have fixed your car. He hit your car, but the fact that you further damaged your car by driving it to New York is your problem, not his.’ ” That’s the concept of mitigating damages.

But SCO is going out of their way to avoid the mitigation of damages. If SCO actually has a reasonable claim to owning the way that Linux swaps data in and out of data or the way that Linux talks to the video devices, we can fix that. But SCO will not tell us what they are claiming, so we can’t fix it.

So, even if SCO are successful in arguing that SCO-owned code was folded into Linux, and the resulting operating system then caused damage to SCO’s business, they still have to overcome the fact that in the eyes of US law they have done little to mitigate the damage done by Linux. To be honest I’d be amazed if SCO’s FUD campaign gets as far for this to be a major issue (I’ll be mildly suprised if it even gets to court), but you never can tell…

It is with a growing sense of dread and depression that I read the “news(news.com – Judge orders SCO to show Linux infringement)”:http://news.com.com/2100-7344_3-5114689.html that SCO finally delivered the UNIX source code that it claims IBM has infringed the copyright of. Surely this should be a cause for celebration? Finally we will see exactly what SCO has been talking about – an army of Linux coders waits in the wings to analyse the code and help rebuke SCO’s claims. The problem? Well SCO has decided to deliver said source code to IBM on 1 million pieces of paper. This reminds me of a bet I won with a welsh friend of mine concerning the England v Wales 5 nations (as was) rugby match a few years back – he took great delight in delivering the £5 in pennies, wet ones at that. I suppose its naivety on my part, but I had hopped that this whole debacle wouldn’t descend into playground tactics.