rc3.org

Strong opinions, weakly held

Month: May 2008 (page 2 of 3)

A blog for Tivo users

TV producer Chuck Lorre uses the two second “vanity cards” displayed at the end of shows he produces to publish short essays on whatever he feels like. You can only read the essays if you pause the shows on your DVR. One recent card discussed the then upcoming WSJ article about Lorre’s essay. If that doesn’t make his essays a blog in an unusual format, what would?

Institutions that are actually hedge funds

The American Scene has a provocative article that argues that Harvard University is actually a hedge fund, one that happens not to be subject to taxation. Porsche (the luxury car company) also makes most of its money by way of derivatives, as opposed to building and selling cars.

What users do

As you know, I frequently mine the long term road test blog at Edmunds Inside Line for interesting tidbits that relate to design and user experience. Today I ran into a problem at work where people could no longer log into FogBugz because the computer running Windows XP on which it runs had decided that too many people were connected and I was violating the arbitrary rules Microsoft imposes to force you to purchase Windows Server 2003. Here’s the thing — nobody was actually using FogBugz at the time and the problem went away when I rebooted the server.

Then today I read about a complaint that the Edmunds staff have with Subaru’s navigation systems. Subaru disables the controls for navigation systems when the car is moving:

I find it extremely frustrating that some navigation systems, like the one found in our Subaru, will lock out 90% of the menu functions once the vehicle is in motion. Want to program in a new destination? Pull over and stop. Want to change the route from “quickest” to something more scenic? Pull over and stop. What if you’re mired in traffic, late, on a highway with no shoulder, or simply want to keep going? Tough.

And this remains the case whether you have a perfectly capable passenger riding shotgun next to you to press the buttons or not. A passenger can read regular maps while underway, and AAA gives them away to members for free. Tell me why I should pay one or two grand for one of these, again?

So what do users do when confronted with these arbitrary, user-hostile restrictions? They hack around them:

But our 2008 Subaru WRX STI has a hand-operated parking brake handle, a type that is much easier to control. While doing a hand-brake turn while horsing-around on the safe confines of a dry lake, I inadvertently found that pulling up on it doesn’t simply illuminate the brake lamp. Doing so also energizes all of the navigation system menus.

In the end, he winds up jamming his iPod under the parking brake handle so that he can use the navigation system whenever he likes. In the case of our FogBugz server, I’m going to uninstall Windows XP and replace it with some Linux variant as soon as I get a chance.

Skipping the error handling?

The Relevance blog has an excellent post on simplifying code called Refactoring from Ceremony to Essence. In part it explains why people find Ruby on Rails to be a compelling alternative to J2EE, but it also illustrates a number of techniques applied by Ruby on Rails that could just as easily be used regardless of which language you’re using to develop your applications.

One point in their post directly addresses the “use less indentation” rule I posted about on Sunday. I spoke in favor of doing all of the basic sanity checks up front in a method and avoiding nesting, this post recommends leaving them out entirely:

Conditionals make code expensive to test; so ceremonial conditionals are a particular nuisance. Let framework error handling deal with missing data on the form.

I need to give that one a little more thought.

Priming the pump

Talking Points Memo’s David Kurtz wonders if there’s something a little wrong with becoming President, using the fame attendant with having been President to build a massive fortune, and then spending that fortune to attempt to get your wife elected President.

He also brings up the point that accepting fees for speaking and then loaning that money to a political campaign seems to exploit the campaign finance laws in a pretty obvious way. If I’m a billionaire, I can donate a maximum of $2,300 to Hillary Clinton’s campaign, or I can hire her husband to speak at a corporate meeting for as much as I like, and he can then loan that money to her campaign with no expectation of repayment. That doesn’t sound right to me.

Why people oppose peak oil on philosophical grounds

Andrew Leonard posts an explanation of why many conservatives hate the the concept of peak oil (and the idea that human activity is causing climate change):

Partisan conservatives pooh-pooh peak oil (and human-caused climate change) because they think that to concede that these challenges are real and must be confronted is to acknowledge that greed is not always good, and that free market capitalism must be restrained, or at least tinkered with substantially. Peak oil and climate change are fronts in the culture wars, and to some conservatives, watching the price of oil rise as the Arctic ice melts, it might feel like being in Germany at the close of World War II, with the Russians advancing on one front while U.S.-led forces come from the other. The propositions that cheap oil is running out and the world is getting hotter — as a result of our own activities — threaten a whole way of life. The very idea that dirty Gaia-worshipping hippies might be right is absolute anathema.

Given that many on the left also see peak oil and climate change as cultural battlefields, as weapons with which to assault enemies whose values they politically and aesthetically oppose (see James Kunstler), it’s no wonder that some conservatives are fighting back like caged rats, or that they want to blame speculators for oil prices, or biased scientists for climate change.

It really is a shame that these issues are subject to such strong partisanship. They’re problems that are going to require cooperation to address.

My rules of thumb for developers: use less indentation

Over a month later, post number two in my “rules of thumb” for developers series. The first post was on writing less code, period. This one is on using less indentation.

What I really mean by this is that I’m strongly not in favor of complex nested code structures. I find them to be difficult to follow when reading code, and to be good places for little logic bugs to hide. How often have you seen code that looks like this?

if (something > 10) {
    if (something < 100) {
        // Do something
    }
    else if (something > 150) {
        // Do something else
    else {
        return false;
    }
}
else {
    while (something < 10) {
        // Do some other stuff
    }
}

I often see conditional structures three or four levels deep, comprising case statements, if statements, and loops of various kinds, and in those cases, it can be very difficult to figure out exactly which conditions have to be in place for a given line of code to be executed.

Let’s look at a really common sort of coding problem:

private boolean doSomeStuff(String str) {
    if (str.equals("something")) {
        // Perform some tasks.
        if (str.length() == 10) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }
}

I would always write that method like this:

private boolean doSomeStuff(String str) {
    if (!str.equals("something)) {
        return false;
    }

    // Perform some tasks.

    return str.length();
}

Any time there’s a condition that causes code to be skipped, I like to put the return statement above the code that could be skipped. It enables me to avoid a level of indentation and, I think, makes the code more readable. This approach goes hand in hand with the practice I’m going to discuss next, which is to write more methods. I think it’s always better to be able to quickly figure out which code you can ignore when you’re reading through code and trying to figure out why something is happening. In the second version of the method above, it’s easy to see the conditions under which you can ignore most of the code in the method.

It’s particularly important to avoid excess nesting when you’re talking about mixing markup with code, in PHP files, JSPs, ERB templates, or whatever. Excessive nesting can render the source nearly unreadable. It’s almost always better to use includes or other approaches to make it easy to distinguish between the control structures in the page and the markup used to render the page.

This practice may seem pretty obvious, but I don’t think I’ve ever seen it explicitly describe before, and I read a lot of code that includes lots of deeply nested structures. I’d love to hear in comments whether people see any downsides to this approach, because I’m methodist when it comes to writing code this way.

Our drug war feeds Mexico’s civil war

For the past six months or so, I’ve noticed a smattering stories that paint a very grim picture of goings on in Mexico. This morning’s news is that Mexico’s national police chief was assassinated in his home yesterday.

Last year the Washington Post reported on murders of Mexican musicians by drug cartels.

For more background, read about Los Zetas, a group of former special forces soldiers who hired themselves out to a Mexican drug cartel.

These ultraviolent drug cartels are all competing for shares of the US drug market. As violent as America’s drug trade is, it doesn’t hold a candle to places like Mexico and Colombia.

There are programmers …

… and then there are programmers. jQuery creator John Resig has ported the Processing visualization language to JavaScript. Not only is this an incredibly cool hack, but it also makes Processing a heck of a lot more useful in a practical sense. I wonder if this will become the new best approach for presenting graphs and other data visualizations within Web pages?

OpenOffice for the Mac

Good news: there’s now a native version of OpenOffice for OS X. Bad news: it’s really slow and buggy.

Older posts Newer posts

© 2024 rc3.org

Theme by Anders NorenUp ↑