Wednesday, November 17, 2004

Redaction and Reaction

First, let me beg forgiveness for the original single-list posting. I let a search-and-replace get out of control, and all of the ":=" operators in the Formula Language portions were replaced with ":[space]=". (I needed to allow line breaks in list concatenations in order to make the web page flow and failed to use the "Selected Text" range option, in case you were wondering.) If anyone was doing a copy 'n' paste, you were likely scolded severely by Designer when you tried to save the code. That'll teach you to use code you just find laying around on the web, eh? The links were also all broken because they started with "http[space]:[space]//".

Second, I want to ask you to follow the link to Damien's site and read what he has to say about Formula Language's list handling, particularly in R5. He's in a unique position to know; he's the guy who rewrote the Formula Language engine for Notes and Domino 6. If you like things like @For, @While, @Transform and @Sort, he's the guy to thank. Send him money. While you're at it, find the name of the guy (or gal) who invented the window-screen-on-a-stick thing that keeps stuff in the frying pan from spooging up the kitchen, and send him (or her) money too.

You can make the dialog snappier by exploding a string of numbers rather than coding a list directly. I was not aware that, in the example I posted, 98 separate arrays were being created and 97 destroyed in memory. I had assumed that the initial declaration of a literal array/list would be dimensioned all at once, and that only additional items would take the equivalent of a Redim Preserve (or string mutation, for those who are familiar with how strings really work) hit. I like learning stuff like that; it makes me better at what I do, and what I do is often stuff that can be horribly expensive if I don't pay attention to details like that. Interesting, though, that the segment of the posting that caused my blog to break was the same piece that will improve my code from here on out. The OpenNTF R5 version will incorporate the improvement; the Notes 6 version will be using @Transform for numbering.

About being expensive — it's not that I go out of my way to write stuff that takes a lot of resources. I just hate to hear things like, "Notes can't do that." Notes usually can, and if it can't, then Domino on the web can. I'm not talking about writing highly transactional systems for international money transfers or anything like that. It's almost always about taking the things that Notes has proven itself to be good at, is already being used for, and moving some aspect of that to the next level. I don't have the skills (or, frankly, the ambition to gain the skills) to write low-level tools, so I'm stuck with Formulas, LotusScript, DHTML and my embarrassingly sparse Java. Often the initial implementation, while functional, is far from the best way of going about doing what I've done, but I'll release it anyway because it fulfills a business need. Just as often, I'm in uncharted waters, so I can't just ask how others have done it before. I can usually find a much better-cheaper-faster way for version 1.1, but I can also make sure that version 1.0 is as good as it can be given that it may be a fundamentally flawed approach. Paying attention to people like Damien (and others who know what they're talking about, like Ben and Rocky) helps make my bad code limp along at least a reasonable trot, and makes sure that my good code flies.

2 comments:

Damien said...

I agree with you 100% Stan, SEND ME MONEY!

Just kidding, but I have to say I think you are too hard on yourself. There was nothing wrong with any of the code you posted, I think its pretty rad. And anyway a single uncached DBLookup can cause WAY more performance problems than that.

Also, premature optimization is the root of all evil. Ok, it's not really, but it does tend to cause buggy, unmaintainable code, reduces time spent on more important things (like usability) and supports state sponsored terrorism. You don't want to help the terrorists, do you?

Stan Rogers said...

Of course I'm hard on myself -- it's all part of the morose-Anglo-in-Montreal persona I'm trying out. Thanks for the compliment -- I do try to do what I can. (And, for that matter, what I can't. I won't be posting many of those examples.)

There's premature optimization, and then there's ignorance in action. This was a case of the latter. There are, amazingly enough, things I don't know, and list construction under the covers was one of them. Even at the sketch level, I wouldn't use Redim Preserve in every pass through a loop, and this appears to be essentially the same thing. I thought -- hoped, actually -- that this issue would be of interest to others.