"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Tuesday, June 06, 2006


Tim Bray wonders about Java and binary search...

If we can’t get binary search right, what chance do we have with real software?
Psst... look at the code. You *did* get binary search right.

The problem is you got integers wrong.

Real programmers use the *complete* numeric tower.

Update: Troy makes a point in the comments that there are many basic algorithms that are easy to get wrong when the foundation is weak.

Without having to think about integer overlow you are free to think more mathematically and less mechanically. Here is an unusual (to most) definition of factorial. This is iterative using the "let-loop" syntax which can be added trivially to Scheme since it has lambda and tail recursion. OK -- C# and Java have a new iteration syntax the compiler writers added for you. Can you iterate on multiple parameters? Can you invoke the next iteration even in a non-tail-recursive position?

Ha! We *still* win! But you still have more programmers.

But we still have the complete numerical tower!!! Yea!

> (define (fact n)
    (if (< n 0) (error "fact n, n >= 0")
        (if (< n 2)
            (let loop ((result n) (n (- n 1)))
               (if (< n 2)
                   (loop (* result n) (- n 1)))))))
> (fact -1)
*** ERROR IN (console)@52.1 -- fact n, n >= 0
1> ,t
> (fact 0)
> (fact 2)
> (fact 6)
> (fact 100)
> (time (fact 1000))
(time (fact 1000))
    25 ms real time
    30 ms cpu time (30 user, 0 system)
    8 collections accounting for 3 ms real time (0 user, 0 system)
    1230816 bytes allocated
    no minor faults
    no major faults
(goes on for several more lines)

Orchestration Patterns

Dragos and Boris have a new draft of their Orchestration Patterns book. There is a discussion list as well. One thing I am on the lookout for was mentioned in an ealier post today... Ralph Johnson's point about structure *and* process. Beyond the question of what is an "orchestration" vs. some other kind of programming... what is the process for adopting one when it is called for.

One thing I like about orchestration tools is support for increasingly transparent reliability across long-running, asynchronous operations. I don't see how this would ever become completely transparent, but on the one hand most programming languages offer nothing by default, while orchestration tools try to offer something by default.

Other than that the current tools I am familiar with leave much to be desired in terms of programmer comfort... at least this programmer is not fond of "programming via property boxes". Perhaps we need something like Rails, but rather more for long-running, asynchronous process steps.

Atom Over XMPP

Peter Saint-Andre has a new draft in the works for Atom Over XMPP. The previous draft is still available.

This memo describes a method for notifying interested parties about changes in syndicated information encapsulated in the Atom feed format, where such notifications are delivered via an extension to the Extensible Messaging and Presence Protocol (XMPP) for publish-subscribe functionality.

Structure and Process in Patterns

Ralph Johnson delivers more goods...

A lot of people seem to follow the errors of Design Patterns and focus on structure to the exclusion of process. A pattern description should tell the reader how to create the pattern in a system where it doesn't exist, and many pattern descriptions do not.

One of the things that helps me think about process is to imagine a system without the pattern. What would I do to use the pattern in the system? What alternatives are there to the pattern?

Sunday, June 04, 2006


Stefan Tilkov exposes yet another useless analogy in the land of WS-SUV's.

Maybe some people also choose which cigarette to smoke based on the cowboy who promotes it.

Influence: The Psychology of Persuasion

Tim Bray has an item on the anniversary of the Tiananmen Square massacre.

The book Influence: The Psychology of Persuasion explains how the Chinese government used subtle and simple techniques to help the population conform following the massacre. Those same techniques, according to the book, were used by the Chinese on prisoners of war during the Korean War.

The book is a really good one. When I mentioned some aspects that lend themselves to agile development, someone on the XP mailing list responded the book is his favorite from the last ten years. High praise, but I can see why.

The information is of practical use every day in this market-driven and political society. With many less dramatic, but more commonplace, stories I can't imagine most people not recognizing situations from their own lives.

I think the book should be required reading for high school students. May as well go into life somewhat prepared for the onslaught.

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.