I'm a junior in college majoring in Computer Science. Apart from writing lots of code, I want to start reading source code written by others to improve my coding skills and learn better/different ways of doing stuff. I was thinking I should start reading some of the key parts of the code in C++ compilers. I think this would help me do two things:

  • Learn elegant coding practices because compilers are hard and the code represents solutions to this hard problem.
  • This would also help me learn about how my most used language is compiled, the details, how each error is generated, how code is parsed, and become really good with the specifications of the language.

Do you think this is a good idea?

  • 2
    most C++ compilers are very complicated (because parsing C++ is very complicated) and don't have the best code quality, you are better off looking for other compiler/interpreter resources – ratchet freak May 28 '13 at 0:16
  • 3
    Why is this voted down? I think it's a good question. – Rocklan May 28 '13 at 0:49
  • 1
    @LachlanB the vote says it was off topic. I don't think it is. – Reactgular May 28 '13 at 2:30
  • 1
    Kudos for wanting to read code. Most programmers aren't interested. – tcrosley May 28 '13 at 2:58
  • 1
    I am truly amazed that all the answers say "no, don't do it". I couldn't disagree more with those answers. In addition to reading source code, you might enjoy and benefit from reading academic papers describing parsing algorithms and compiler architecture. +1 for a good question and good luck. – user39685 Jun 21 '13 at 13:21

Hard to say from your post how much you already know about C++, but I wouldn't start by reading a compiler's code. I would spend time with good books first. A very short list:

| improve this answer | |

Do you think this is a good idea?

The only reason it might be a good idea is so you can get the experience to know that most code, even frequently used, "good" code (especially frequently used, good code in fact) is thoroughly inelegant.

Oh, and it should prove a good learning experience about how code rarely looks like specifications and/or how little code actually follows specifications.

And perhaps so you can learn how much you have to learn.

But no, I don't think this is a good idea - even for the reasons you might gain from it (and definitely not for the reasons you think you might gain from it).

| improve this answer | |

No, it's not a good idea because you gain so little. It's better to take the compiler class and read the dragon book if you want to specialise in compiler. If you want to specialise in C++, buy and read the standard. Those will give you more engineering skills than reverse engineering a compiler.

For pure programming skill, I'd recommend "The Practice of Programming" by Pike and Kernighan.

| improve this answer | |

I would not start by reading compiler code because it's real complex. You should do a search for C++ projects on(to read the code, build the project, making changes):


Also you should read: The C++ Programming Language by Bjarne Stroustrup

| improve this answer | |
  • 1
    This is a bit risky... there's way more bad C++ out there than good. – Daniel Gratzer May 28 '13 at 1:29
  • @jozefg That's true for all languages – Harrison Brock May 28 '13 at 1:30
  • 1
    That doesn't really change the meaning of my remark, randomly searching open source code is not a good way to discover best practices. Well known projects though might be different. – Daniel Gratzer May 28 '13 at 1:35

Instead of reading source code, which will likely contain no comments. You should try reading some books on how to write good C++.

Give Scott Meyer's Books a try. I think you'll like his Effective C++ books.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.