This blog has moved. Please update your bookmarks.

Because of the way things are going, I've decided I might as well get a domain of my own.

So through foresight and fortitude, I have now registered the domain; and I am now moving my blog to this location. This means that anyone who reads this site, will have to move over to the new one.

Since it's ultra-brand-new, it may still take some 24 hours before the DNS servers throughout the world learn about the address, but it should work OK by now I think.

Thoughts About Threading

Threading, as I've mentioned before, is hard. Especially in non-managed languages, such as Delphi for Win32.

Various people, including Allen Bauer, is thinking about how languages can be adapted to support thread-based development easier:
"This increases the need for the average developer to be become more adept at writing multi-threaded applications. What if the compiler and the libraries made this easier and more accessible? It is these kinds of questions we ask ourselves everyday..."

One way of doing it, I'm thinking, is to have the compiler automatically generate warnings or errors in certain cases. We've patched the ZeosLib library so different threads cannot access ZConnection objects created in other threads; the ZConnection objects keep track of thread ownership and refuse to work for other threads (unless manually overriden). This behavior causes exceptions to be thrown in this case, which is far more desirable than having access violations deep inside one's code.

Just tossing ideas around, why not have certain attributes (I'm inspired by C#) that specify thread access? Like, for instance,
procedure TForm1.Log(const Text: string); mainthread;
... main-thread code here ...

Certain attributes might specify whether, like in this case, a method may only be accessed from a main thread; or with another attribute "threaded", special vigilance may be required and certain patterns may be enforced by the compiler. A function marked as "thread-unsafe" may not be called from a "threaded" method without certain encapsulation or something.

I think there are lots of things that can be done. Delphi/Win32 right now is at the same level that C++ were with strings (back when C++ was actually used by people). It can be done, but it's all manual, hard labor. Even few changes can yield significant returns.

Green Tea Sucks

Yep. Can't stand it.

Nightmares on Serialization Street

Serialization is the process of taking an object, and streaming the contents of that object into a file, or communications channel, or any other form of media; and then rebuilding that object on the other side, so that it takes up the exact same representation as it did on the sender side. Think of it as a Star Trek teleportation device, but for data objects - the data objects being represenations of invoices, computer commands, telephone extensions or more complex forms of data.

Delphi has this for TComponent objects, but not for anything else. So I've had to build a complete serialization layer, using such fancy classes and interfaces such as ISerializable, TSerializeBuffer, TSerializeObjectHelperRTTI, TSerializeObjectHelperNoElements, TXmlInterfaceSerializer (which isn't complete), all available through functions like SerializeObject, UnserializeObject and PeekSerializedClassName, through heavy use of variants and run-time type information.

To further agonize over this, this is but one part of the problem. We're building server flashes into our system, meaning that a specific information-gathering part of our programs can run in three different ways: 1) through normal execution, 2) threaded execution to provide application responsiveness even though a task is executing, and 3) a server-based remote object call, placing the heavy burden on the server instead of the client.

I don't know how this happened, but somehow, I find myself building a complete client/server-based remoting layer into a language that doesn't have it; and interfacing that remoting layer with dynamic fail-over to local methods in case the link goes down.

Isn't this what the wizards at Sun or Microsoft are supposed to be doing?

The Smell of Victory

As I mentioned briefly in a previous post, I have a new job. Technically I'm not working there yet; I'll be starting the 19th of June running full focus on development in C++ and C#, which will be a difference for me personally, having worked with Delphi the past five years. We'll see how it turns out... I'm pretty confident I'll get up to speed quickly. I have a policy of usually not mentioning the company I work for, although it slips out from time to time - the main reason for that is that I don't want to associate that company with my blog. This is me, Mats, writing on my own.

Leaving my old job isn't easy. I'll be leaving a bunch of terrific guys and girls that I've worked with for years now.

In one sense, I feel like I've been in the army. I look back on this successful campaign and I realize that we've worked miracles. So much of effort, enthusiasm, hard labor and engineering went into our products. Not all code is as good as I wish it was, and looking back I see how we could have made things differently (like, more objects); but we made it work.

A few things stand out: That early morning in January 2002, when we came back from the holidays and thinking it'll be an easy start, and the first thing I see in the mail is that my boss has sold a new system (not existing yet) to this large hospital in Sweden. Gulp. So much for slow starts. The next months were frantic.

The first installation, 30th of May 2002, nearly five months later. Monday morning after installation weekend, thirty-something operators come in and put the system to maximum use. If it hadn't worked, it would have severely affected about ten thousand employees in this hospital. But it worked. We ran into a problem with MySQL connections, which forced us to take down the system briefly at about 0815 hours: Five minutes downtime, all clients discovered the server was down and idled until a reconnect could be made. Not one program needed to be restarted. The line held, the battle was fought and we came out victorious.

After that, it was one battle after another. Fierce competition, tough market, even lawsuits... New versions came out: 1.3, 1.4, 1.4.1... It was a continual struggle to stay ahead, keeping our heads above the water as we built and built and built. We produced software like maniacs, and somewhere in the midst of it all we managed to find time to look over and update our software processes too. The company grew, new organizations, tears, sweat and blood... But the line held. And we reaped victory after victory.

The software worked, too. Sure, there were bugs, there were complications. But somehow we hit it just right; we built a reputation for ourselves, which our partners and customers noticed too. The darn things worked! If they didn't, we went back, fixed them, and then they worked! And on top of it all it looked good - much better than anyone elses; the user interface was clean, efficient, easy to use and shined in front of our competition. For that I give all credit to my boss and our graphics designer.

And prestige customers started to drop in. We even snatched some from our competitors; big corporations which you would instantly recognize if I printed their names - which I won't. Today, I don't know how many people get in touch with our systems, but depending on how you count, it might affect over one hundred thousand people here in Sweden.

Along the way, I fell in love with Borland Delphi. I've been a Borland fan since the eighties, but Delphi has been my tool of choice for quite a few years now. I notice with a smirk how others talk about these great features of .NET, and I think to myself that we've been doing some of those a long time in Delphi now. And that's on Win32, with zero libraries deployed.

Our company is big now. One of the big guys in this niche of our market, though we're only about twenty guys, and four developers.

So, I feel like we've been through North Africa, Sicily, Italy, England, Normandy and France, Holland and Belgium, and now we're standing in the heap and rubble of defeated Germany. We did it. We won. And now the time has come to leave my squad and be reassigned to new theaters of war.

I never got paid as much as I'd hoped for (my friends will be the first to tell you that), but it doesn't bother me much; because I'm thinking, maybe I took something with me that was worth more. My favorite quote from Apocalypse Now tells it right: "I love the smell of napalm in the morning... Smells like - victory."


Blog contents copyright © 2005 Mats Gefvert. All rights reserved.