Archive for the ‘Technology’ Category

Using an ostrsteam correctly

Thursday, November 20th, 2008

At work, I recently ran across a bug in some legacy code using ostrstream. As it turns out ostrsteam is extremely bug prone. In fact, ostrsteam has actually been deprecated in favor of stringstream. If you’re writing new code, do yourself a favor, stop now, and go use stringstream.

If you can’t - say you’re maintaining legacy code - I strongly advise checking to ensure that your code follows the pattern below. If you’re not - and you’re using dynamic buffering (the default) - you probably have at least one bug and one memory leak in your code.


/* By default the constructor allocates a 512 byte block of memory which is managed by the object itself. */
ostrstream stream;

stream << /* some data */;

/* This is the first bug fix. An ostrstream is a BINARY stream. It is not NULL terminated by default, even when calling str(). Since an allocator is not guaranteed to give you a zeroed block of memory, your string may be much longer then you expect. This could cause memory corruption, data corruption, or stack dumps. (Mine was the first two and was a royal pain in the ass to track down.) */
stream << std::ends;

/* Not absolutely required, but the second parameter is an example of paranoid programming. Just in case someone comments out the line above, you'll still be safe from memory corruption. Note: Depending on you're implementation of string, you might get a string with two null characters at the end. This shouldn't cause any problems, but is worth mentioning for clarity sake. */
std::string str( stream.str(), stream.pcount() );

/* This is the fix for the memory leak. The str() call above gave the caller (you) responsibility for deleting the dynamically created buffer. Rather than worry about how that buffer was allocated (new[] versus malloc), you can just tell ostrstream that you don't have a reference to its internal buffer and it will take ownership of the buffer again. Thus the dynamic buffer gets deleted when stream goes out of scope. */
str.freeze(false);

Now if only more UI designers would read this

Tuesday, November 18th, 2008

I have occasionally been tempted to write a post/rant about about interface design. Instead, I’ll just refer you to a couple of useful resources, and say “what they said!”

What reading Tufte won’t teach you: Interface design guidelines - Simply stated rules for designing UIs.

User Interface Design for Programmers by Joel - If you haven’t read this, and you claim to be a UI programmer, who the heck are you kidding?

more to come.. Suggestions welcome.

Never fight your way through a phone menu again

Friday, August 15th, 2008

I’m sure most of you hate phone menus as much as I do. Hell, I recently moved my brokerage account away from E*Trade primarily because their phone system (and thus customer service) was an absolute disaster. Well, I just ran across a product which could change all that. *

Fonolo essentially allows you to call a company and skip the whole damn phone tree to get right to the person you want. Honestly, if it weren’t for the privacy concerns, I’d be jumping up and down and begging to sign up for the beta. This sounds like it could save hours of frustration.

Unfortunately, there is one big catch for me: all of your calls are routed through Fonolo’s servers and recorded. Do I really want them recording my call to my credit card issuer? Or bank? The ramifications of them having that data is beyond scary. I don’t know what there privacy policy is, but honestly it doesn’t really matter. How long until they get bought out? What happens to all that - potentially very personal - information then?

* I first saw mention of Fonolo in Seth Godin’s blog.

Goverment enforcement of copyright

Thursday, July 31st, 2008

One of the strengths/weakness (depending on whom you ask) of copyright law has long been that the government had no real roll in enforcing it. If someone was misusing your copyright, it’s your job to find them, sue them, and prove your case. The only real help the government provides is the court room.

However, this may soon change. There is a bill being introduced in the Senate that would grant the US Attorney General the ability to file civil law suits and the responsibility to enforce copyright. While there are some pluses to the bill (mostly to copyright holders like music labels and movie studios) the consequences of the bill are quite scary.

First, the government has significantly more resources than even the richest company. And since the government is not out to make a profit, there’s no “it’s not worth it financially” incentive to restrict suits. As a result, were likely to find the number of enforcement suits going way up. Personally, I don’t like that idea much at all.

More importantly though, this is breaking into some significant new legal ground. Traditionally, the government has been (in theory at least) a neutral party in the battle* between consumer rights and corporate profits. This bill would bring the government down strongly on the “wrong” side of that battle. It sets the government up as the enforcer of corporate policy and profits. Equally importantly, the government has traditionally had no roll in the enforcement of civil law. This bill will be opening a while new legal arena in terms of government involvement and possible prosecution. Do you really want the government suing you for libel? (Say of George W Bush or Hillary Clinton?) We’re heading in that direction folks.

* Yes “battle” is a slightly inflammatory term, but can you truthfully tell me its become anything less?

Further Reading:

Senators Announce New Intellectual Property Enforcement Bill
Posted by Richard Esguerra of the Electronic Frontier Foundation

Some of the articles best quotes are:

The real “problem” may be that some so-called “offenses” can’t be proven beyond a reasonable doubt, the standard for any crime. This new provision would allow the AG to sidestep that high burden of proof — a burden that gives the average citizen an important measure of protection from the overwhelming power of the government.

If the bill is passed, something as simple as taking your iPod to Mexico could be considered an infringement of the copyright owners’ distribution right.

Civil law (legal system)
From Wikipedia

Lawsuit
From Wikipedia

Marketing quotes from Seth Godin

Thursday, July 24th, 2008

Never heard of Seth Godin? Neither had I until a few days ago. Now, I’m getting seriously addicted to his blog. The man can write. Every one of his posts make an interesting succinct point and does it in an enjoyable read. Here are some of my favorite quites so far. You’ll probably be seeing more in later posts.

Updated (7-27-08): Added extra quote and corrected grammar in post title

Most people, most of the time, steadfastly refuse to pay attention.

The tragic mistake of demographics and media planning is that they overlook the single most important issue: is the person you’re talking to ready to listen?

– From “Are they ready to listen?”

If you want to enrage customers, just sit idle while they rage against a broken system at your organization.

– From “What do you do when your systems break?”

The world needs fixed-price web podiatrists.

Podiatrists, not doctors.

Doctors do surgery and prescribe expensive drugs and stuff. Podiatrists can just make it easier to get around.

– From “Two simple web businesses”

Here’s my number one fiduciary rule for big brand marketers: The executives involved in approving a sports or entertainment promotion should not be permitted to attend the event.

– From “Promoting the promotion”

Cognative Bias: Jumping to Conclusions

Sunday, July 20th, 2008

A few days ago, the folks over at the Business of Software blog posted an article on how the human minds tends to jump to conclusions. For me, this turned out to be a fairly timely article that I kept coming back to over the last couple of days.

This artificial experiment is an interesting illustration of a couple of human tendencies. First of all, we jump to conclusions. Secondly - more important, but also far more subtle - we tend to seek out evidence that confirms our hasty conclusions, rather than evidence that might contradict them.

At work, I often find myself trying to make educated guesses from very little information while trying to debug issues found in either QA or released code. One of the things I’ve gotten burnt by several times now is exactly the type of failure to test my initial conclusions that this article describes. I’ll be fairly convinced of my initial conclusion, mention it to someone else, and have them shoot (what were in retrospect) very obvious holes in my theory. As a result, I’ve been trying to apply a much more systemic approach to confirming my initial theories before taking them to anyone else. It’s been helping so far; at least when I remember it that is! Overall, I highly recommend this one for anyone who has to solve problems with insufficient information.

As for the Business of Software conference itself, man do I wish I could afford to attend. Sounds like it’ll be a blast, but at “only” $1495, that’s not going to happen anytime soon.

Elegant technology makes things simple

Monday, June 23rd, 2008

A great example is the Capital Words project. Every wonder what our politicians are actually talking about in Washington but don’t have the time to read the full transcript? This site will tell you in a single word. I really like how they’ve used technology to simply something really complex (congressional transcripts) down to something really simple (a single word.) The result is easily understood by anyone and gives a good insight into the current hot topics on capital hill. Now if only the had source linking…

I encountered this site through the blog of the Open House Project. As I’ve said before, I enjoy reading their articles for the occasional gems scattered throughout. Most of their posts aren’t that useful, but some really make you stop and think.

Best spam of the day

Wednesday, June 11th, 2008

It’s not often I get spam that makes me laugh out loud. This one did.

From: Friends at Match (.com)
Subject: What does your hand say about you?
Body: Your answer to this question reveals something about your love life. (snip)

*shakes head* Did they really send that out?

How to undo “rm -rf /”

Thursday, April 24th, 2008

One of the worst things you can do by accident on a Unix/Linux box is run the command above. (DON’T! Or I will not be responsible for the consequences.) If you are running as root - you’re not are you? - this command would delete your entire file system. That is, every file you’ve ever created would be gone.

Suffice to say, this is often considered a “Bad Thing”.

I ran across this interesting account of how to undo some of the damage described above. Note: This is really only for *serious* Linux geeks. Frankly, some of what they describe I didn’t know was possible. Then again, I’m barely a Linux user much less an admin.

As a challenge, can anyone tell me why on some Linux distributions the above command will fail part way through? No, its not a safety measure. I’ll give you a clue, where does the “rm” binary live?

Two wonderful new Thunderbird extensions

Saturday, March 8th, 2008

In the last 24 hours or so, I’ve discovered two new Thunderbird extensions that I absolutely love. The first is the new Release Candidate for Lightning 0.8 (the calendar extension). (Warning: This is NOT a final release. I would not recommend using it with real data yet.) For years, I’ve been using Sunbird - the standalone calendar from Mozilla. (Lighting & Calendar are developed in parallel by the same team.) However, the integration features this time around might just be enough to get me to switch over. The task integration was a particular improvement over previous versions.

The other extension is Seek. It adds faceted search to Thunderbird. I can’t tell you how many times I’ve thought about how nice it would be to have something like this. (I actually had an extension I’d started myself to do this, but never got very far.) This will completely change how I sort, save, and search my archived mail. Beautiful. (This one is a full release, but is more features are forthcoming.)

Lightning 0.8 RC1: ftp://releases.mozilla.org/pub/mozilla.org/calendar/lightning/releases/0.8rc1/

Seek: http://simile.mit.edu/seek/