When I was in my very first undergraduate programming class, they hammered into me on very important truth:

The compiler is never wrong

The compiler has no bugs in it, the libraries have no bugs. If you’re not getting the output you expect, then the bug is in your code. Nearly every week, someone would be there furiously muttering to the tutor that he just needs to LOOK at this example because the code is so OBVIOUSLY correct that it MUST be a compiler error of some kind. And every time it happened, the tutors would simply smile complacently back and remind the student that “The compiler is never wrong”. Eventually, with enough repetition, we understood this fact down deep into our bones and I think it’s made us better programmers as a result of it.

On the face of it, this is absurd. Compilers are programs just like anything else and they contain bugs like every other program. If we were talking about established, battle scarred compilers like gcc, you might be able to make a credible argument but we were working with the Glasgow Haskell Compiler which most certainly did have bugs in it.

The statement “The compiler is never wrong” has such power because it’s so patently easy to prove false. And as I grow older and think I understand more and more about the world, some of the most powerful beliefs that you can hold are the obviously wrong truths. You can never tell an obviously wrong truth to someone who is not ready to hear it because it’s so obviously wrong. You need to take a leap of faith and accept that something can be obviously wrong and still true for such things to make sense.

If this sounds supiciously like what you’ve heard religious people say, it’s because maybe this is what religion is…

  • Pingback: Anything you think is either unoriginal, wrong or both « Bumblebee Labs Blog

  • http://t-a-w.blogspot.com/ Tomasz Wegrzanowski

    Check kernel mailing list every now and then – gcc has plenty of bugs. I was bitten by one ages ago too, something related to signedness and long longs, I don't remember the specifics any more.

    Many of gcc bugs are things that are underspecified in C standard, but just because C standard allows you to make a compliant compiler that makes every single real world program incorrect doesn't make it not-a-bug.

    Standard libraries for C and Java tend to have few bugs because they're so tiny. Standard and semi-standard libraries for Ruby, Python, or Perl tend to be filled with bugs because they do so much.

    At some point you need to give up this belief.