tags:

views:

593

answers:

12

In medical school they teach students:

"If you hear hooves, think horses not zebras".

In other words, look first at the simplest explanation for a problem.

What's a programming example of this?

+4  A: 

People blaming the CLR whenever their C# / VB.Net program behaves unexpectedly

It's far more likely that you have a bug in your program than there is a bug in the CLR that only your program exposes.

JaredPar
Except when it comes to VBA in Excel :P Or maybe I just don't like VBA and Excel.
Nick Bedford
+14  A: 

Any SO C++ question which contains the phrase "is this a bug in the compiler"

JaredPar
sometimes it really is a bug in the compiler... I hit one (often one I've seen before in new clothing) probably at least twice a month. It's MSVC6 though...
rmeador
@rmeador just because it's usually horses doesn't mean it can't be zebras, it's just less likely :)
JaredPar
I agree. In fifteen years I've seen one bug in a compiler. And even then I could only crash the compiler on some pretty ugly code when the optismisation flag was on.
dave
+2  A: 

"There must be a bug in the compiler! Oh no, wait a minute..."

Nick
+1  A: 

Not programming-specific, but Occam's Razor comes to mind:

"Entities should not be multiplied unnecessarily."

Or, in the original Latin:

"Entia non sunt multiplicanda praeter necessitatem."

James Thompson
Occam's Razor is a different name for the same principle. I was hoping more for programming applications of the principle.
Hugo
A: 
// My template vector
template<class T>
class vector { };

vs

std::vector<T> dont_fight_stl;

?

Nick Bedford
A: 

90% : Is the app configured correctly?
  9% : Does the code handle all possible errors reasonably?
  1% : Is the code wrong?

Loadmaster
+1  A: 

I think it was jwz who said:

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

Regular expressions are great, but don't fall into the trap of using them for everything.

dave
While this is true, I don't see what it has to do with the question.
Doug McClean
I think the question is about looking for the simplest solution to a problem. I've seen several occasions where regular expressions (zebras) were used, when a simpler solution (horses) presented itself.
dave
Some people, when confronted with a problem, think, "I know, I'll quote Jamie Zawinski." Now they have two problems. (I don't know who said that, but it's brilliant.)
Jörg W Mittag
Ouch :) I've been zinged on SO
dave
This does fit the problem. All too often people resort to regex when a simple string search will do. A recent example on SO was extracting something from a HTML document (say, the title). All you need to do is find the positions of `<title>` and `</title>` and take a substring.
DisgruntledGoat
+1  A: 

I often see people jumping to heap corruption when, in reality, they simply have some sort of multithreaded synchronization issue.

jeffamaphone
+7  A: 

I think some people may not understand the question. The question is about simplicity. It is a form of Occam's razor. The quote is trying to convey that zebras are exotic and it is far more likely that we'd be hearing horses (this would be an example given in the western world and not Africa btw).

I suppose for myself an answer would be (but certainly not the only one):

When the code doesn't compile think typo and not any number of more complex answers.

OR more recently:

When a method won't accept the standard documented input, think namespace conflict and not obscure bug effecting you that no one else on the planet has noticed. [Which is my own version of JaredPar's]

This. So many questions here are along the lines of "I'm learning X. How come X doesn't support <some feature X totally supports>?" Then after playing 20 questions, the asker posts code and, lo and behold, they declared an int as a string or something.
Chuck
I've done that several times in the last week.
thepocketwade
+4  A: 

Raymond Chen's blog has a entry today on this topic.

In his example, duplicate GUID's were encountered. This could be due to fundamental problems in the GUID algorithm, NIC's with identical MAC ID's, etc.

Or someone just copied the GUID.

Michael
A: 

A similar concept in software is often borrowed from the Pragmatic Programmer:

``select’’ Isn’t Broken It is rare to find a bug in the OS or the compiler, or even a third-party product or library. The bug is most likely in the application.

lomaxx
+2  A: 

I can't tell you how often people concoct these wild theories about why they are getting file 'bla' not found errors without even checking whether the damned file actually exists or not. And in 99% of the cases it turns out that when your computer tells you that it cannot find a file, it's not because the file finding algorithm has a weird heisenbug that only affects you, but rather because there is no such file!

Jörg W Mittag
+1 for "Heisenbug". :)
Matt Peterson