I {heart} PHP

Reasons why I love PHP:

  • It’s quick.
  • You can build your own framework. (Or use someone elses.)
  • The whole PHP distribution can be compiled into one single, distributable binary.
  • It’s got a rather sweet mix of raw power, raw utilities, caches, add-ons, and dangerous things you can do with it. If you know what you’re doing. Kind of like C, but without the hassle.
  • If you’re careful enough, you can actually develop new features directly in the production system.
  • A nice mix of classes, reflection, and syntactic sugar.
  • The same source files can be deployed anywhere – Windows, Linux, Web hotel A, Web hotel B, localhost… no additional configuration necessary. Painless distribution through xcopy.
  • Small footprint.
  • No System.Web.Utilities.Page.PageHelper.Random.Help.ImLost.RandomAccessAttribute.VeryImportantSetting.
  • It doesn’t use Xml and helper classes to configure a website. Just make an include file. Or use parse_ini_file.
  • …and you can edit the darn thing in notepad. (No big Visual Studio to install. No dependencies. No dlls. Nuff said.)

Sure, there’s no strict typechecking, it’s not binary, and you need one or two tricks to make it really fast. But the easiness with which you set projects up, the power behind it, and the fact that you can pretty much beat it into doing anything you want – while at the same time being able to distribute it anywhere and it just works right out of the box… Yep, PHP won my heart.

Waking Up the Caveman

It’s sometimes been said, by many people, that turning the computer off at night and starting it up again is bad, because it puts an undue wear on the processor and components inside when you switch on or off the electric current.

This is almost entirely, completely false.

However, I think, some day, it should be measured the cost of turning Microsoft Outlook on or off. Whenever I come back to work, turn on the computer again, and start Outlook, I just let it sit there for a few minutes until Outlook has stabilized itself. It sort of steps out of the cave like a burly caveman who haven’t had his coffee yet, and who realizes that there’s been a time gap since he last was lucid, panics for a brief moment, and then proceeds to spend the next few minutes rummaging about in a frenzy and doing everything at once, until he finally comes to his senses again and idles back.

It’s pretty much come to the point where I usually start by opening Mozilla Thunderbird instead, go through the mail briefly, and then press the little Outlook button to wake up the caveman. In the meantime, I can go get coffee, say hello to my colleagues, chat a little, and when I come back, the caveman has just about come to his senses again, and I can continue working.

I wish I knew why.

Threading is Bad

Threading, as a software method, is bad.

The idea is good in itself: Make the program execution split up in several threads, which all run independently; creating an illusion that the program is doing several things simultaneously – and, if you have multiple cores, processors or hyperthreading, the program actually does several things at once.

It is a wonderful way to scale – letting ten users work with the same program, or hundred users, is all a matter of how many threads you create.

But from experience, we’ve realized that threading is very hard to pull off without glitches. Why?

  • It has proven very difficult to isolate threads from each other: They all access the same data, so you need data isolation through locks. But sometimes it’s hard to predict – especially in a GUI environment – which data that require locks or not. We’ve discovered instances where deeply embedded components were not “thread-safe” but actually used the same data source.
  • When threads collide, they do so unpredictably, and can be a nightmare to find. A program can run 10.000 queries without problem, and query 10.001 will crash the whole program.
  • It is very difficult to debug, and exponentially more so to observe thread collisions in a debugger.
  • Threading problems are more likely to occur in production systems that development systems.

.NET and Java do mitigate these problems somewhat, but still doesn’t solve the fundamental problem – that threaded programming is hard, error-prone, and can lead to very serious failure in production environments.

Erlang, the language developed by Ericsson, solves this in a wonderfully simplistic way. The main difference between a process and a thread in a conventional system is that threads share global data between them, whereas processes all reside in different address spaces and thus share no global data. Erlang doesn’t have any global data, and thus, the distinction disappears. As they say,

“If you think Java is stable, Erlang is rock steady.”

So, is there a way to mitigate this situation? There just might be.

What if there was a way to split the process into separate “services” that share no data between them? What if it was possible to create a message-based system of requests and responses, where the system itself would be able to create services as needed? And if the only way to communicate between these services would be through some kind of message system which is guaranteed to be stable? (WM_COPYDATA comes to mind.)

One might argue that copying data back and forth in the system is slower, more memory-consuming, and less efficient. But if we are indeed approaching a paradigm shift in programming, where the limits of a single CPU has been reached, it only makes sense to adopt a different methodology to work in a multi-CPU environment. More threads, more concurrency, more CPU’s running more threads simultaneously – then the problem of increasing speed can simply be dealt with by, basically, adding more CPU’s. Instead of tuning each thread at the expense of computational stability, you tune the available services and the overall flow of the system, which is one of the cornerstones in highly parallel environments. (Think of a brain.)

Of course it would pay off to fine-tune individual components/threads/services as well; the advantage of the service-based setup is that it would be remarkably easy to extract one service and test it, simulating a virtual testing environment around it.

Such a system might very well be implemented in Delphi, in a similar way as Erlang, by building services that run as threads and operate on Windows message queues. And since, ideally, no data would be shared between them, it would make no difference whether the individual components were in-process or out-of-process. Building on the Serialization module I built earlier, this might be quite easy to accomplish.

Likely candidates would be, for instance, our internal web server than I’ve never been able to make as stable as I want it.

Small Is Beautiful

A colleague sent me an attachment today, a MindManager map file. MindManager is a tool that has become popular recently; it’s a program that allows you to build mindmaps. A lot of people here like it. I’m not intending to plug the program here, I use Notepad to make my mindmaps and it works well for me.

Of course, to view the actual MindManager map files, you need a viewer. So I went to their site and downloaded the free viewer, which turned out to be a whopping 76 megabytes of download. It included a full professional installation, that reverted back to a free viewer when the trial period expired. Good marketing, supposedly, but that was not what I was looking for.

And it integrates with the entire Office suite, install dictionaries and so on; unless you manually deactivate all those features – although I was unable to deactivate the installation of the German spell check library for some reason.

This is, I’m noticing, a trend.

  • The latest Office suite, 2007, is beautiful, but appallingly heavy. Outlook is a nightmare in the load that it puts on the computer.
  • Adobe Acrobat, Windows Media Player, RealAudio… all these applications almost take over the computer when they’re installed. They’re heavy, they install themselves everywhere, and they only bog down the computer for little gain. Even WinAmp belongs in this category now.
  • The worst is when you click on the wrong icon and accidentally start BDS2006 or Adobe Photoshop. Go get some coffee while the program starts, then come back and close it.

More and more, I’m leaning towards Portable Applications. Portable applications are programs you can install onto a USB stick, that require no further installation or setup in terms of registry settings, COM registration or anything. It’s just a simple, portable program: Plug it into a computer, start it, and you’re on.

My favorite application in this category is Miranda IM. A complete Instant Messaging client that supports ICQ, MSN, IRC, Jabber, and several other protocols. No advertising, no graphics-heavy application that takes over your system. Just a clean, small program that does what it’s supposed to do.

Truly, small is beautiful.

Using Junctions to Host IIS Ftp Home Folders

So, the problem I faced was that I was trying to set up the IIS ftp service to handle multiple users. However, in its User Isolation mode and with using Local users, the IIS expects the folders to be named “LocalUser\username” within the ftp-root. It’s not difficult to set that up, if you have a clean installation.

The problem was that we had an existing infrastructure in place, where the folders were named c:\inetpub\user01, c:\inetpub\user02…, etc. So it was impossible to add a directory structure that the IIS would recognize as the users’ home folders.

We tried accomplishing that using Virtual Directories, but for some reason, IIS failed to recognize them when we tried to add two virtual folders in succession (one LocalUser virtual folder, and then “user01″, “user02″ virtual folders beneath that).

Ultimately, the solution we found was to use NTFS junctions, using the SysInternals junction utility.

By creating a folder “LocalUser” within the ftproot directory, and adding junction points under that, we were able to create a directory structure that accommodated our setup. It looks like this:

c:\\InetPub
   + ftproot
      + LocalUser
         - user01 -> ..\\..\\user01
         - user02 -> ..\\..\\user02
   - user01
   - user02

This means that users can be added to or deleted from the ftp service simply by using junctions. Moreover, it means that we don’t have to use the IIS administrator utility to do that, but can script it using conventional bat files (and without using the iisftp tool either).

Provided that using junctions doesn’t open the system up to any security vulnerabilities (which I haven’t found so far), this is (I think) a very neat setup.

A Brief History of Cacls

In the beginning was cacls.exe. This little command-line utility could edit access control lists in the NT filesystem. It was deemed by some to be inefficient and underpowered.

So when Windows Server 2003 came along (and Vista, mind you), Microsoft shipped an updated version called icacls.exe which was more competent in some areas, and less competent in some areas.

Looking at the situation, Microsoft realized that icacls was insufficient, and wrote another tool called xcacls.exe. This was more competent, but also underpowered.

So they wrote another version, called xcacls.vbs, which finally – after four iterations – offers users the capability to remove inheritance on folders from the command prompt. The functionality has always been there in the GUI, though.

It makes me wonder if anyone – anyone – writes scripts for Windows. On the other hand, given the crappy cmd.exe, maybe it’s no surprise no-one does.

On Tickle Tests

Tickle is a pretty fun website with tons of tests. If, for some unexplainable reason (yeah right) you have nothing to do on a Saturday night, it’s a fun way to goof off.

I took a “work quiz” and came upon this question.

At first, I didn’t understand the question. And then I had to laugh out loud.

I have never, ever, during my entire time (6+ years) at Vision, been without a huge backlog of projects in the pipeline.

Is that normal?

CSS And Tables

I found chart the other day, obviously humorously intended, depicting the average amount of time spent on different activities during web design.

It’s more accurate than you think. I’ve done a lot of time trying to build css-only sites, only to give up and fall back to good ol’ tables. Tables have a way of working that’s fundamentally accepted by every browser. And once to do some magic tricks with tables, such as using a little positioning adjustment, things just work.

CSS is nice, sweet, and powerful. But it’s just too much trouble.