Speak and Shout

Tuesday, October 30, 2007

doctest with Python

At home I'm translating some C++ code to Python for doing 3-D math with vectors and matrices. (Yes, I know about NumPy -- I have my reasons.) Matrix math requires care to get all the indices right, and it's a good application for writing tests to make sure I've done things correctly.

About the same time as I started this project, I saw the following response from Fredrik Lundh (effbot) to a comment on Reddit:

>what was I thinking using self.assertEqual() in Python?!
Yeah, what were you thinking? Here's how it's spelled in Python, when using the One True Testing Tool (wink):
>>> foo.bar
3
(where all you actually typed was foo.bar; the rest is just good old cut and paste).

Of course, Fredrik here is referring to the doctest module. I'd seen Peter Norvig use it before in some of his Python code, and I should've paid attention then. Fredrik's comment gave me the push to finally try it. I found that it fits my style of Python coding very naturally, since I typically shake down my code at the REPL as I go. I cut and paste my interactions at the prompt into my class, and I've got some tests up and running quickly. The nice thing is that I'm helping to document my code (inline) as I go, which is a second advantage of doctest. I've never been that enamored with writing a separate test class like I've tried with the unittest library, for instance.

Good stuff. Thanks, Fredrik.

Thursday, October 18, 2007

Linux Mint Cassandra

I bought a new 160GB hard drive from Wal-Mart with a gift card I received for my birthday (Thanks, Dad!), and I decided to install Mint on it. For those that may not have heard of this particular Linux distribution, it is built on top of Ubuntu. The benefit is that it also includes all of the codecs that you would need to hunt for around the web to get your audio/video/movies to play correctly.

I was expecting to have to do some weird tricks with my hardware setup since I still wanted to be able to boot into Windows. I have two 80 GB Serial ATA hard drives that are hooked into a Adaptec RAID card in a mirrored configuration. I wanted to keep this setup, and this necessitated a separated HD for Linux -- I didn't want to do partitioning, and I've had bad luck with separate partitions getting corrupted anyway.

Since the Windows hard drives boot off the Serial ATA card and my new Linux HD was a standard EIDE, I was happy to find that the Mint boot loader actually figured out my weird setup. The loader simply intercepts the boot process and offers me a menu on which operating system to choose when I start up. I was a little wary of picking the Windows option the first time, but it worked just fine.

Mint itself is terrific. The only hitch I had was that my Sound Blaster Audigy wouldn't work without disabling the onboard audio in the BIOS. No loss since I never use the onboard audio anyway. Last night I was coding in Python with PIDA, listening to my music with Amarok, and watching Rear Window (and Grace Kelly!) on DVD with Totem Movie Player.

Everything works together smoothly. I'm impressed.

Labels: , ,

Skeptical Christian

I've been meaning to post for a while about Kyle Deming's Skeptical Christian website. He's done current book reviews on Richard Dawkins' The God Delusion and Daniel Dennett's Breaking the Spell: Religion as a Natural Phenomenon. He also tackles philosophical viewpoints such as the Cosmological Argument. Also, one of the best things about his site too is his (somewhat irregular) podcast in which he responds to questions posed by his blog readers. Highly recommended.

Labels: , , ,