Log in

No account? Create an account
If you don't know how compilers work, then you don't truly know how computers work. - Adventures in Engineering — LiveJournal
The wanderings of a modern ronin.

Ben Cantrick
  Date: 2007-06-23 16:04
  Subject:   If you don't know how compilers work, then you don't truly know how computers work.
  Mood:der uber-nerd
  Tags:  digg

If you don't know how compilers work, then you don't truly know how computers work. If you're not 100% sure whether you know how compilers work, then you don't know how they work.

In fact, Compiler Construction is, in my own humble and probably embarrassingly wrong opinion, the second most important CS class you can take in an undergraduate computer science program.

The first reason Compiler Construction is such an important CS course is that it brings together, in a very concrete way, almost everything you learned before you took the course.

You can't fully understand how compilers work without knowing machine architecture, because compilers emit machine code. It's more than just instructions; compilers need to understand how the underlying machine actually operates in order to translate your source code efficiently.

Incidentally, "machines" are just about anything that can do computations. Perl is a machine. Your OS is a machine. Emacs is a machine. If you could prove your washing machine is Turing complete, then you could write a compiler that executes C code on it.

But you knew that already.

You can't understand how modern compilers work without knowing how Operating Systems work, because no self-respecting machine these days runs without an operating system. The OS interface forms part of the target machine. Sure, you can find people working on five- to ten-year mainframe projects that ultimately run no faster than a PC from Costco, and they may dispense with the operating system due to time constraints, plus the fact that they have a worldwide market of one customer. But for most of us, the OS is part of the machine.

You won't understand how compilers work unless you've taken a theory of computation course. The theory of computation reads like part one of chapter 1 of a compilers book. You need all of it.


This is a long rant, but I enjoyed it. Compiler construction was the one CS class that I never got to take in college, and to this day I'm still annoyed about that. I've tried to teach myself to an equivalent level. I bought the Dragon book, I know what a BNF grammar and LALR parser are, I learned lex and yacc, even wrote my own small Forth interpreter with them. And I'm still not sure if I'm smart enough to create my own languages and compilers.

Incidentally - Do not use the Dragon book as your first book on compiler construction! Hardcore C programmers with a lot of spare time to write code will be much better served by Ronald Mak's "Writing Compilers and Interpreters". Everyone else who just wants a good introductory text... well I'm still looking. Torben Mogensen's "Basics Of Compiler Design" is worth a shot.
Post A Comment | 3 Comments | | Link

  User: j_b
  Date: 2007-06-24 01:45 (UTC)
  Subject:   (no subject)
abelits I think just took this one ...
Reply | Thread | Link

  User: nickhalfasleep
  Date: 2007-06-24 02:48 (UTC)
  Subject:   (no subject)
Why does anybody need to know how compilers work? Unless you're writing in C / Assembly / Embedded processors, the need to optimize at a design level is an invitation to trouble. Actually, I'd say it's worse because if you sit there and fret about compiler level optimization while designing and writing, you'll make your code a horrible, unmaintainable mess.

I think it's better to design around good algorithmic methods and use good MP libraries to spread the work around.
Reply | Thread | Link

Ben Cantrick
  User: mackys
  Date: 2007-06-24 08:48 (UTC)
  Subject:   (no subject)
For all the same reasons it's a good idea to know how a gasoline engine works even if you're never going to be a car mechanic.
Reply | Parent | Thread | Link

May 2015