Speak and Shout

Tuesday, March 29, 2005

Andale Mono

Bill de hOra has posted a list of notes on how he sets up his development machine. The most interesting thing I saw was this comment:
Install the Andale Mono typeface. Don Box claims Lucida Console starts to work for code onscreen at >14pt and is good for presentations. At under 14pt (which is all programming) andale mono is the most beautiful typeface. It's the only programing typeface I've used for years ...

I did some searching on Google Groups and found that this font doesn't come preinstalled with Windows 2000/XP. It took a little effort, but I did find Andale Mono on the Core Fonts project on SourceForge.

I didn't like it immediately, but it's really starting to grow on me. It's now my default font at home and work.

Maximum code, minimum space

While solving the 3n+1 problem on the ACM-ICPC problem set archive, I used this piece of C-style boilerplate code every programmer will recognize.

long max_value = 0;
long val = 0;
for (long i=1, i < 1000000; i++)
{
    val = some_func(i);
    if (val > max_value)
        max_value = val;
}
return max_value;

Here, some_func is a function that returns a single value which I'm trying to optimize. For each value returned from the function, I'm comparing it with the maximum value I've seen so far and keeping the higher of the two.

This boilerplate code -- while simple to write and understand -- bugs me. For one thing, the only thing I'm interested in is the maximum value, but I have to assign the return value of the function to a temporary variable too. Then, there's the fact that there's three lines of code in the loop to express the concept "give me the maximum value from all the iterations of this function".

Actually, thinking through that last statement gave me an idea. How about instead:

long max_value = 0;
for (int i=1; i < 1000000; i++)
    max_value = max(some_func(i), max_value);

return max_value;

Much better. The extra variable is gone, and the body of the loop is reduced to a single line. It seems this is about as good as you can do with C/C++. I paid a little for this brevity ... over the million iterations, I lost about 100 ms with the one-line max function. That's in the noise for typical applications.

My favorite language, Python, is known for brevity. I wondered if I could do better than the C version.

My first attempt draws on one of my favorite language features, the list comprehension.
return max([some_func(x) for x in range(1, 1000000)])

This manages to combine the return statement, the loop, the function call, and the maximization logic into one line! Its only disadvantage is that two large lists are being generated -- one is by the range statement and the other is by the list comprehension.

Enter Python 2.4's generator expressions. The syntax is a little different than the list comprehension, but the idea is exactly the same. However, a generator expression builds only one list instead of two and wastes less memory.
return max(some_func(x) for x in range(1, 1000000))

Actually, it looks cleaner than the list comprehension anyway. Go, Python!

Monday, March 28, 2005

Bookmarks for 3/28/05

Smack the pingu - stupid but fun (requires Flash)
Mplayer being shut down for patent infringement -- possible dark days ahead for open source
StumbleUpon - a Firefox extension that suggests new websites based on your interests
ChristianTuner - live Christian radio and TV stations, programs, on demand, and mp3 links
My Last Visit with Terri Schiavo

IronPython and language success

Via Steven, I saw IronPython 0.7 was out. Apparently, Edd Dumbill doesn't think much of it, and he suggests that SmallScript or Boo may be more mature alternatives.

I guess Edd misses the point. A new programming language will really prompt people like me to switch if it has 1) comfortable (probably C-style) syntax, 2) extensive library support (including GUI libraries -- preferably with native GUI support), and 3) a good IDE (including a GUI builder and code completion).

I'm even getting disgusted with Python at this point because while it has #1, #2 and #3 are lacking. CPython has Tkinter as its built-in library, and it's just bad (except for its canvas functions). While wxPython and Qt are decent alternatives, there's no good IDE support for them. (Sorry, Boa Constructor doesn't cut it.) Komodo 3.1 Professional only supports Tkinter and its tiny set of widgets. BlackAdder's QT Designer (along with the entire IDE) is buggy and hasn't been updated for a couple years.

While I'm not a fan of the C# language because of its dumbed-down syntax, it's easy to see why it's become so popular. It has all the prerequisites for success I've mentioned -- in spades.

I've played with Java and Jython a bit, but the GUI libraries and associated IDE support don't compare with C#. There are some SWT GUI builders I've downloaded for Eclipse, but they're all bad/clumsy in my opinion.

Considering that all major OSes are now based on a Windows environment, shouldn't your favorite programming language/tools make it really, really easy to make a GUI? I mean ... to borrow from Douglas Adams here ... absolutely, mind-boggingly simple? Why don't all the language makers get this? Microsoft sure does.

[Sidebar: And you know, CPython is so close to all three criteria for success. If Komodo would just support wxPython in their GUI designer, we'd be all set. Argh.]

Thursday, March 24, 2005

Back from Orlando

Doris and I were down in Frostproof, FL to visit my 93-year-old grandmother, Dee, this past week. We also took time to visit Orlando and take in some sights.

I bought a new toy while we were down there -- a Kodak digital camera. I've posted some of the photos we took of Epcot Center here. I also finished up a roll of film on my old 35-mm camera -- I'll try to scan those as soon as the photos are developed. (Those are the ones that actually have my grandmother in them.)

But for now, enjoy these pics.

Wednesday, March 02, 2005

Cool screen saver

Here. I think these are all copied from similar X-Windows screensavers written by Jamie Zawinsky and friends.

Flu

Doris and I both have the flu. Fortunately, it's a mild case ... only the headache, joint aches and fever.

It was really only a matter of time. Almost every family we know has had someone get sick over the past few weeks.

Time to head back to bed! :)

BlogBridge

My new RSS reader is BlogBridge.

BlogBridge suggests new feeds to you based on 1) user-defined keywords and "star" ratings, 2) links from the subscriptions you already have in the reader, and 3) Technorati feedback. This is a little different than my idea of a feed-discovering Firefox extension, but I think the end result is the same. I have been very impressed so far with its discoveries.

[For those of you who don't know what RSS is, it's a way of subscribing to web pages so that you can be notified when a web site is updated. It's the solution to endless checking to see if anything has been updated. Pito Salas has created a screencast of BlogBridge in action, so you can find out about RSS feeds and BlogBridge at the same time.]

Update: I found that BlogBridge doesn't put an icon in the Start Menu for some reason. I had to create a shortcut on the Desktop by going to Control Panel: Java: Temporary Internet Files: Settings: View Applications, then right-click on BlogBridge and select Install Shortcut. Whew!

Tuesday, March 01, 2005

Screencasts

Jon Udell has blogged recently about screencasting. The term describes movies of software ... "screen video, along with voiceover, [that] can produce compelling software demonstrations".

Some useful bookmarks on the subject:
Jon's explanation of the term.
How to make screencasts yourself [Windows Media, QuickTime, Flash]
A Walking Tour of Keene, NH -- Jon's compelling demo of screencasting using Google Maps
Download Windows Media Encoder, a free screencast tool from Microsoft.
Why Can't Visual Studio Do This? ... a screencast displaying Eclipse's superior features for Java development.

I have an extra headset at work ... I think I'm going to bring it home and give Windows Media Encoder a try.