(When) Should I learn compilers?

Viewed 13650

According to this http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html article, I defnitely should.

Quote Gentle, yet insistent executive summary: If you don't know how compilers work, then you don't know how computers work. If you're not 100% sure whether you know how compilers work, then you don't know how they work.

I thought that it was a very interesting article, and the field of application is very useful (do yourself a favour and read it) But then again, I have seen successful senior sw engineers that didn’t know compilers very well, or internal machine architecture for that matter, but did know a thing or two of each item in the following list :

  • A programming paradigm (OO, functional,…)
  • A programming language API (C#, Java..) and at least 2 very different some say! (Java / Haskell)
  • A programming framework (Java, .NET)
  • An IDE to make you more productive (Eclipse, VisualStudio, Emacs,….)
  • Programming best practices (see fxcop rules for example)
  • Programming Principles (DRY, High Cohesion, Low Coupling, ….)
  • Programming methodologies (TDD, MDE)
  • Design patterns (Structural, Behavioural,….)
  • Architectural Basics (Tiers, Layers, Process Models (Waterfall, Agile,…)
  • A Testing Tool (Unit Testing, Model Testing, …)
  • A GUI technique (WPF, Swing)
  • A documenting tool (Javadoc, Sandcastle..)
  • A modelling languague (and tool maybe) (UML, VisualParadigm, Rational)
  • (undoubtedly forgetting very important stuff here)

Not all of these tools are necessary to be a good programmer (like a GUI when you just don’t need it) but most of them are. Where do compilers come in, and are they really that important, since, as I mentioned, lots of programmers seems to be doing fine without knowing them and especially, becoming a good programmer is seen the multitude of knowledge domains almost a lifetime achievement :-) , so even if compilers are extremely important, isn't there always stuff still more important?

Or should i order 'The Unleashed Compilers Unlimited Bible (in 24H..))) today?

For those who have read the article, and want to start studying right away :

Learning Resources on Parsers, Interpreters, and Compilers

9 Answers

If you just want to be a run-of-the-mill coder, and write stuff... you don't need to take compilers.

If you want to learn computer science and appreciate and really become a computer scientist, you MUST take compilers.

Compilers is a microcosm of computer science! It contains every single problem, including (but not limited to) AI (greedy algorithms & heuristic search), algorithms, theory (formal languages, automata), systems, architecture, etc.

You get to see a lot of computer science come together in an amazing way. Not only will you understand more about why programming languages work the way that they do, but you will become a better coder for having that understanding. You will learn to understand the low level, which helps at the high level.

As programmers, we very often like to talk about things being a "black box"... but things are a lot smoother when you understand a little bit about what's in the box. Even if you don't build a whole compiler, you will surely learn a lot. You will get to see the formalisms behind parsing (and realize it's not just a bunch of special cases hacked together), and a bunch of NP complete problems. You will see why the theory of computer science is so important to understand for practical things. (After all, compilers are extremely practical... and we wouldn't have the compilers we have today without formalisms).

I really hope you consider learning about them... it will help you get to the next level as a computer scientist :-).

You should learn about compilers, for the simple reason that implementing a compiler makes you a better programmer. The compiler will surely suck, but you will have learned a lot during the way. It is a great way of improving (or practising) your programming skill.

You do not need to understand compilers to be a good programmer, but it can help. One of the things I realized when learning about them, is that compiling is simply a translation.

If you have ever translated from one language to another, you have just done compiling.


So when should you learn about compilers?

When you want to, or need it to solve a problem.

Compiler theory is useful, but not essential.

Although there are some techniques which come in handy, like lexical analysis and parsing.

Another one is error handling. Compilers need a lot of these. User input can contain anything, even the unexpected. And you need to deal with all of these.

If you're going to be working at a high-enough level where you're worrying over UML and self-describing code, you could easily go your entire career without wanting or needing intimate details of how the compiler works.

But, if you're an in-the-trenches coder and have no aspirations to manage your friends, it's likely that one day, you'll realize you're waging war with your compiler. It could be a random bug that comes along or a hallway conversation about while-verses-for loops. You'll realize the assembly (or IL, likely, in the coming years) is just a bit to the left of what you were needing and another universe will unfold.

So, I suppose my answer is, just be aware of the compiler for now, that it's doing quite a lot, but don't worry over it too much.

The compilers courses usually focus on how the high-level code is analyzed and translated into machine code. That's very interesting, but not crucial. It's more important to understand what is this machine code that is generated by the compiler so that you understand how a computer works and what is the cost of each language construct.

So I'd rather say that you should know an assembly language (I mean a limited subset of assembly language for one architecture) to understand how a computer works and the latter is definitely required for a competent programmer so that he understands what segmenation fault is, when to optimize and when not and other similar low-level things.

If you intend to write extremely time-critical real-time code, you will benefit from understanding how the compiler optimises your code. However, you will actually benefit more from understanding the underlying architecture of your hardware.

From my experience, if you understand how the hardware works, and how the compiler interprets your code, you will be able to write code that does exactly what you intend it to do. I have been caught on several occasions, writing code that got optimised away by the compiler and made the hardware do something that I did not intend.

All in all, understanding the entire software-hardware stack is not essential to write good algorithms and code, but it will most certainly help!

Related