Saturday, April 26, 2008

The Best UI is No UI

The other day I watched someone unlock their car with a remote key. No big deal, a common occurrence. But for some reason I noticed it and thought that's cool. Maybe because I never had a remote key. I went from a regular, mechanical, non-electronic key, to a Prius with a "Smartkey" system.

With the Prius, I don't need to touch the key. I walk up to the locked car and open the door. As long as I have my key in my pocket or backpack it's all automatic. In other words, no user interface. (I'm now spoiled - I resent having to pull my office key-card out of my pocket, and even worse to have to use a mechanical key on my house.)

Too often in software (and other areas) we think the ultimate "solution" to a problem is some clever UI, like a remote key. But people don't want a clever UI, they want to get some job done, and often the less UI the better - none if possible.

Similarly, the best solution for errors is to prevent them in the first place. (again, no UI) You can't lock your key in the Prius because it won't let you lock the car if the key is inside.

Thursday, April 24, 2008

Multi-Threading Suneido - Thread Specific Storage

Back to work on multi-threading Suneido. After frittering away my last session, I figured I'd "park downhill" and decided at the end of that session that the next thing I'd work on was replacing my home brew thread specific storage with ACE_TSS. With a clear task I wasted less time.

ACE_TSS is a template class used like: ACE_TSS<mystruct> mytss;

which is then accessed like: mytss->member

It overloads operator-> to do its stuff.

In order to keep ACE specific code as limited as possible I defined functions to access my thread specific storage. For example:

Proc*& tss_proc() { return tss->proc; }

The '&' is needed so the functions can be used as lvalues like:

tss_proc() = newvalue;

Unfortunately, this meant replacing all the instances of proc with tss_proc() but I could use the compiler to do the heavy lifting by removing proc and seeing where I got compile errors.

I could have kept the name as proc, but changing it made the transition clearer, and it doesn't hurt to make it clear in the code that it is thread-specific.

For my current, non-ACE version of Suneido I simply defined the functions to access my home brew thread specific storage.

In the process I discovered that part of the old thread specific storage code was broken. It hadn't caused problems because it was code to clear unused memory during garbage collection, so it just meant the garbage collection was a little less efficient. I fixed it for the current version, but I don't know how to implement it for real threads so it's a good thing it's not critical!

The only real problem I ran into was that the Boehm garbage collector does not appear to "see" the ACE thread specific storage. That's probably fixable but it would require digging into how ACE_TSS is implemented. And that would be platform specific. Yuck. Instead I was able to make the thread specific storage simply point to data that would be seen by the garbage collector. I'll just have to be careful I don't forget about this issue in the future.

As far as I can tell, it's all working, both the current version and the ACE version. Next I have to start tackling the crux of the problem - locking global data structures. I think I'll start with the symbol table and the global values table. These are fairly loosely coupled and shouldn't be too hard to handle. That should give me a little experience to help tackle the hard parts like the database.

PS. I started this session using NetBeans but I gave up part way through and went back to using Scite. This was partly because I haven't got NetBeans set up to build, which meant I had to compile in a separate command line window, which meant there was no easy way to click on the errors and go to that part of the source. (which I can do in Scite, although it's mostly a straight editor). I could have messed around with getting the build environment set up, but then I would have ended up like last time, with no real work accomplished.

Another thing I found disappointing in NetBeans is that it didn't seem to have the kind of powerful tools that I want/expect from an IDE. For instance, there didn't seem to be any way to find all the uses of a function or variable. Maybe I just missed it. But I wouldn't be surprised if it wasn't there, C++ tends to get second-class support in primarily Java IDE's. The Eclipse CDT used to be fairly minimal too, but I think they're supposed to have made significant improvements in the latest version. I'll have to go back and take another stab at trying to use it.

A final annoyance in NetBeans was that it didn't treat underscores as word characters. e.g. if you choose "Whole Words" and search for "proc" you find "tss_proc". I looked through the configuration options but couldn't find anywhere to change this. It seems odd because that's not C++ specific. If anyone knows how to "fix" this, let me know.

Firefox 3 Beta

I've been holding off on trying the Firefox 3 beta. I used to be an earlier adopter but now that so much of my computing life goes through my Firefox browser I'm a little more reluctant to live on the bleeding edge.

But beta 5 is supposed to be the final beta before the release candidate so I thought I'd give it a try - as long as I could install it alongside my current Firefox. On Windows I used Portable Firefox but I couldn't find anything similar for the Mac. Instead I created a second profile and have Firefox prompt for the profile when it starts up. This works but is a bit of a hassle and I'm afraid I'll choose the wrong profile at some point.

A pleasant surprise on the Mac is that it finally has a more Mac-like theme. e.g. buttons on web pages are rounded instead of ugly rectangles.

Unfortunately, it still doesn't show the favicons on the bookmark bar. I guess this is to be compatible with Safari, but that seems pretty silly to me. But I found the Mac bookmark toolbar favicons style for Stylish which solved this issue.

If you asked me if I needed a customizable browser my first response would be "no". But when I go back to a "bare" browser I realize how much I depend on the add-ons I use. Of course, not all the add-ons have Firefox 3 versions yet. dragdropupload (which I use all the time for email attachments) was available.

But the Google Firefox Browser Sync isn't, which was a real hassle because it meant I didn't have any of my bookmarks or passwords. I don't have many bookmarks since I keep the bulk of them on so it was easy to export from Firefox 2 and import into Firefox 3 (once on Windows and once on Mac). I haven't found a way to export and import my passwords.

Passwords was another pleasant change in Firefox 3. I have a hard time remembering all my passwords for all the web sites I use, especially since I try not to use the same password for all of them. On Firefox 2 after you enter a password a dialog pops up asking if you want to remember it. But at this point you don't know if it's right or not. Either you say "remember" and then if it's wrong end up storing a bad password. Or you say "don't remember", in which case, if it works, if you want to remember it, you have to log out and log back in. Either way it's not ideal. But in Firefox 3, the "remember" prompt is inserted in a bar at the top of the screen mode-lessly - meaning you can wait to see if the password is accepted before choosing to remember it or not. Great improvement.

The Delicious Bookmarks add-on for Firefox 3 is a beta version that requires you to join the Yahoo group before you can download it. No big deal, but more hassle than necessary.

Firefox 3 is supposed to be a lot faster than Firefox 2. I can't say I've really noticed a big difference, but I haven't timed anything.

I haven't had any real problems with the beta so far. I crashed once in a couple of days, which isn't any worse than Firefox 2. I'll continue testing for a bit longer, but it seems good enough to switch over.

Tuesday, April 22, 2008

Wireless Security

Sometimes it seems like I go out of my way to make things hard for myself!

I got home from work to find a note from Shelley that her laptop wireless wasn't working. Oh yeah, I hadn't got it working with the new Time Capsule.

I run the Airport Utility, change the Wireless Security to WEP, and try to set the password to what I was using previously (so I didn't have to mess with the laptops or other devices).

Nope, it will only take an exactly 13 character password. Okay, I make up a new password and go to connect Shelley's Windows laptop. But it won't work. I mess around with the settings, stupidly failing to record the original settings. No luck.

I search on the internet. Some people say that on Windows you have to use the hex version of the password (you get that from the AirPort Utility from Equivalent Network Password on the Base Station menu). I type in a 26 character hex password multiple times. No luck.

More digging reveals that this is 128 bit WEP. (More or less. It's also Transitional Network Security that is also WPA compatible. Whatever that means.) The older 40 bit WEP that I was using previously is actually available - you just have to turn off the new 802.11n :-( and then hold down the option key while you pull down the Radio Mode list. (how could I have missed that!)

Now I can enter the old 10 digit hex password (with a dollar sign). And now the Windows laptop connects.

I pull out the Chumby to make sure it can still connect. It can, but in the process I find that it does handle WPA! So I don't need to use WEP after all. Argh! (It must have been my old Squeezebox audio player that was WEP only, but I'm not using it any more - too much hassle to run its proprietary server.)

Back to the Airport Utility, re-enable 802.11n, set it back to the default WPA. Back to the Windows laptop, enter the new password, it connects fine. Back to the Chumby, enter the new password, it works fine. Same with my MacBook.

So I think I'm all good. I'm glad my Mac mini is hard wired to the Time Capsule. Trying to configure wireless through a wireless connection would have added even more fun to the process!

Monday, April 21, 2008

New Time Capsule

I just replaced my Linksys wireless router and Lacie network drive with a 1 tb Apple Time Capsule. My reasons for the change included:

- The Linksys router periodically "dies". Even my wife knows to unplug it, wait a few seconds, and plug it back in, but it's still a hassle. Since this fixes the problem I'm assuming it's the router, but I suppose it's possible it's something like the ISP DHCP. I'm crossing my fingers that a new router will fix the problem.

- The Lacie network drive was getting full.

- I was using a second Firewire Lacie drive for my Time Machine backups from my Mac mini. This drive was also running out of space.

- I wanted to make Time Machine backups of my MacBook, and the only way to do that without plugging in an external drive is with Time Capsule. (Time Machine won't work to a regular network drive. I'm not sure if that's just a marketing decision or whether there is some technical reason as well.)

- I could replace two boxes (router & network drive) with one - the less cables the better, if you ask me.

- I occasionally had range problems with wireless. I'm hoping the new router will help.

As usual, the packaging was slick and the hardware is attractive. I plugged it in, installed the software, and it worked.

At first I couldn't see the drive from the Windows machine but after I set the right workgroup it appeared.

The setup wizard only allowed WPA wireless security. I was still using WEP since I have some wireless devices that don't support WPA (like my Chumby). I realize WEP is minimal security but it's enough to stop my neighbors from accidentally using my network. I have used MAC address filtering in addition but it's a hassle when you add new devices and I always seem to end up turning it off. I see the regular configuration allows WEP but I haven't got around to changing it yet.

To keep things simple (at least I assume that's the reason), OS X only seems to offer a single "key" entry field. I'm never quite sure if this is hex or text or what. If you were Apple/Mac only it wouldn't matter - it just works. But when you're connecting to other things it can be confusing. I've seen references to using a dollar sign or 0x prefix to enter hex keys but it doesn't seem to be clearly documented (that I've seen).

Once I had it set up I switched my Mac mini Time Machine to go to the Time Capsule. Of course, the first initial backup is huge and takes a long time. And there's no way to move your existing Time Machine backups to the new drive.

I probably should have know better, but while that was chugging away I turned on Time Machine on my MacBook and pointed it at the Time Capsule. Of course, it also was a huge initial backup.

At the same time (I know, asking for trouble!) I was playing with the Time Machine options to exclude certain files and directories. Then I realized every time I changed the settings the initial backup started all over again!

Just to stress it a little more, I started copying the other files (pictures and music) from the old network drive to the new one. It took me a few minutes to get the network drive working again - it wouldn't show up until I re-ran the configuration utility. This copy ran for quite a while (an hour maybe?) and then aborted with an Error 50. I suspect my impromptu stress test uncovered some bug in the Time Capsule software.

When I went to bed the two Time Machine backups were still running. When I got up, the MacBook had finished. Unfortunately, I'd forgotten I had the Mac mini set to power off at night. When I started it up, it had to restart the backup from the very beginning! I realize this is just the initial backup, but given how long it takes, you'd think they would have made the software handle resuming a backup. This time, without all the other concurrent activity, the backup went smoothly and finished.

Or maybe I should say, more or less finished. For several more hours it popped up windows about backup up large quantities of files. I'm not sure what this was - I hadn't modified or added any significant amount of files. Why didn't it get this stuff on the initial backup? But eventually it seemed to settle down. The problem with this kind of system that just invisibly does stuff in the background is that you're never quite sure if it's working properly (at least if you're a cynical techie).

Once the backups were done I went back and copied the other data from the old network drive. Again, now that I wasn't trying to do too many things at once, it went smoothly. (Theoretically, if the software is "correct" it shouldn't matter how much stuff you do at once. But no software is "correct". As the saying goes, in theory, practice should be the same as theory, but in practice, it's not.)

So far so good. My only (minor) complaint is that, judging by the temperature of the case, the Time Capsule doesn't seem to go to "sleep" - even overnight, with no computers active (or even turned on). There's probably continuous activity on the internet side, but if nothing is awake on the LAN side, I would think it could still be smart enough to go to sleep.

One nice side benefit is that the Time Capsule hard drive is a lot quieter than the Lacie.

I know it's showing my age but I can't help continuing to be a little mind boggled by gigabytes of memory and terabytes of hard drive space. (I just listened to a podcast that said that in many cases algorithms had progress more than hardware and in these cases you'd be better off with a modern algorithm on old hardware than old algorithms on modern hardware. In theory that might be true in some cases, but modern software is never going to fit on old hardware. I can't even fit a single digital picture on a floppy disk, let alone something like Open Office.)

My next plan is to replace my Mac mini with a 24" iMac. I considered a quad core Mac Pro for not a lot more money, but I decided I'd prefer the reduced "clutter" of the iMac. And if I wanted an Apple monitor, then the Pro would end up quite a bit more expensive. When I bought the mini it was more in the nature of an experiment so I bought the cheapest Mac I could. Now that I've pretty much converted to Mac I want something a little "bigger" i.e. 4 gb ram, 1 tb disk. Nothing like RAW photos and virtual machine images to eat up disk space!

Tools, NetBeans, and Eclipse

I've been pushing my Ruby on Rails programmer to use some kind of IDE instead of just an editor. I suggested NetBeans since I'd read some good things about it. He installed it, but so far I haven't convinced him to switch. I can sympathize, when you've got a comfortable routine it's a hassle to change. And productivity tends to take a dip at first while you're learning new tools. But in the end, better tools can make a big difference. Many of the new tools we've added to Suneido have become so useful that I'd be really annoyed to lose them. (Even though we went years without them, and without knowing what we were missing.)

Soon after, I found myself working on the Suneido C++ source code with ... just an editor. Hmmm. I decided maybe I should give NetBeans a try myself. I also figured I should see what progress there had been on the C++ tools (CDT) in Eclipse. Both NetBeans and Eclipse have had many improvements. I downloaded, installed, and tried both. My conclusions were similar to Eclipse 3.3 or NetBeans 6.0.

As much as I like the concepts of Eclipse, it's got some awkward aspects (like "workspaces"). With NetBeans I was able to get the Suneido code loaded with little trouble. I ended up giving up on Eclipse. I'm sure I could have figured it out in the end (I have in the past) but I wasn't in the mood to spend the time.

It's interesting that both these IDE's are written in Java and run on Windows, Linux, and Mac.

Of course, in the end, I used up the time I had messing with IDE's and didn't make much progress on my code. Was this an excuse to goof off or was it an investment in better tools? Depends whether it pays off in the future I guess.

Tuesday, April 08, 2008

Too many heap sections

Recently, a couple of our clients with big databases (for us that's over 4 gb) have been unable to repair their database after crashing. (Why they crashed in the first place is another question - there may be hardware problems.) The repair aborts with "Too many heap sections". Luckily Thankfully, the software does automatic backups twice a day and the customer didn't lose much data. But the repair is still preferable as it generally only loses incomplete transactions that were in progress at the time of the crash.

This error comes from the Boehm memory manager/garbage collector we use. The repair process does keep a lot of information in memory and the amount of information is relative to the size of the database. The question was how to fix it? Did I need to rewrite the repair process to keep less information in memory, maybe use a temporary file? (Although that would make it slower.) Or was there something that could be adjusted in the Boehm code? There's also a newer version of the Boehm code - we're on 6.5 and the latest is 7.0

I searched on the web but didn't find any useful information about this error. Most mentions of it were pretty old. (I did find a reference to the Boehm code with the Mac OS X code - I wonder what part of OS X uses it?)

I searched the Boehm code for the error message and found it in several places (not very DRY). The error is caused when MAX_HEAP_SECTS is exceeded. I searched for where that is defined and the value seemed to depend on whether SMALL_CONFIG or LARGE_CONFIG (or neither) was defined. I wasn't specifically defining either, presumably leading to a medium setting.

I figured it was worth a try re-compiling with LARGE_CONFIG. I modified the makefile and re-built. Then I read a magazine while I tried running the repair process. (It takes a while to process a 4 gb database, even with a fast computer with lots of memory.) It reminded me of the "old" days when I'd have time to catch up on my reading while I compiled what today would be regarded as tiny C programs.

Damn, it still crashed with the same error. Oh well, should have known it wouldn't be that easy.

I went back to remove the setting from the makefile and glanced at the file name. Hey! I was editing the makefile for the MinGW version, but I'd been testing the VC7 version. Doh!

Try again, this time build the right version & test the version I build.

Eureka! It completed successfully.

Now we'll just have to test this version enough to be relatively sure that the change doesn't have any unwanted side effects. Maybe it will be that easy after all!

Sidenote: Considering the number of people and projects using the Boehm code (e.g. Mono) it seems odd that there isn't more documentation. I can understand Boehm not writing it, I'd rather he spent his time on the code. But you'd think someone along the way would have written some. Maybe no one else understands it well enough. Despite having written my own, I know I don't - I just treat it as a black box.

More Software Frustrations

Here's a few software things that have bugged me lately:

I'm currently reading Why Software Sucks by David Platt. He praises how Google senses the country you are connecting from and uses the language of that country e.g. Spanish in Mexico. The problem is, it does this even if I am logged in to my account. Just because I am in another country doesn't mean I've changed my language. It's possible to get back to English but it's annoying nonetheless.

Next, I'm on my bank web site paying some bills (a feature I do appreciate). A message shows up telling me I can now receive one of my bills electronically, rather than having it mailed to me. Great! I click on the link and get presented with a blank form, without the name of the company filled in, forcing me to pick it from a huge list. (Most of the list is not applicable, e.g. for other provinces.) Next there is a "Name" field - who's name? mine? but surely it knows my name? or the company name? but I just picked it from a list? I leave it blank and continue - it doesn't complain so I'm still not sure what it wanted. Next it tells me I have to sign up for an ePost account. It's free, but it's annoying to have to sign up for yet another on-line account and come up with yet another password. Can't the company send bills to my bank without every account holder having to sign up for ePost?

But the best is yet to come. I get through the ePost signup, only to be told that I have to contact the company personally, by phone, before I can complete the process. Yeah, right. I pay bills on the evenings and weekends, so I have to wait till business hours to phone. Then I can look forward to the "pleasure" of an automated phone system and being on hold forever. Then I'll likely talk to some poor customer service person who has never heard of sending bills electronically. No thanks. And they wonder why so many on line transactions are abandoned part way through.

The next incident was minor, but it's a good example of a GUI blooper. I was ordering books through Lulu (copies of Getting Real for my programmers). I'm entering my address and I get to the field for "State/Province". Except there are no provinces. That wouldn't surprise me except that for the prompt. I skip it and move to the next field, "Country", and enter Canada. The screen jumps around a little bit. Hmmm... sure enough, State/Province now lists provinces. This is a good trick, some programmer obviously applied some Javascript. But they didn't consider that people generally enter fields in order, pretty much guaranteeing that Canadian customers will be frustrated. And most people wouldn't notice the slight screen jump and figure out that they could go back to a previous field and it would now magically let them do what it wouldn't just a minute ago.

We run into this issue in our own software. The rule of thumb is that if a field "depends" on another field it should be "after" it in the normal entry order. Usually this can be handled simply by changing the order of the fields. But in this case, it seems "wrong" to put Country before State/Province. My suggestion would be to remove the fancy Javascript - just have a combined list. The programmer can apply their Javascript by filling in the country based on the State/Province choice.

We use Snagit for our screenshots. It's a good program. But it has one really annoying "feature". Quite frequently, when I start it up, it pops up a dialog saying "You have the most recent version of Snagit". I always have to read this a couple of times because the normal expectation is that it would pop up to tell you there's a newer version.

I haven't quite figured out the logic behind this one. Why do I need to be told I have the latest version? I don't think it comes up every time, so maybe it only comes up after it does a periodic check for a new version. (Of course, I only use it periodically, so it happens more often than not.) It may just be that the programmer thought that since they'd gone to all the work of checking for a new version there should be some recognition of this. Programmers are often strangely reluctant to just have the program quietly do it's stuff. Maybe we need pop up blockers for more than just our web browsers.

There is a link on the dialog to the release notes. So perhaps the purpose of the pop up is to give you a chance to read the release notes. But surely if that was the purpose it would only pop up once after installing a new version. How many times (if any) do I want to read the release notes?

Enough being critical, I'd better go and try to do better myself. It's always easier to criticize. (Why Software Sucks does actually suggest solutions or at least, better alternatives, to most of the things it complains about.)

Monday, April 07, 2008

MindMeister Online Mind Mapping

I came across MindMeister from a list of web applications that use Google Gears to run off-line. Check out the demo screencast for a quick overview. It's free for a basic account.

From a quick look MindMeister looks like a good example of a Web 2.0 application.

I haven't got into using mind mapping but some people swear by it.