Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

closed as not constructive by Glenn Nelson, Caleb, MichaelT, gnat, Eric King May 28 '13 at 4:21

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

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
Why is this voted down? I think it's a good question. – LachlanB May 28 '13 at 0:49
@LachlanB the vote says it was off topic. I don't think it is. – ThinkingMedia May 28 '13 at 2:30
Kudos for wanting to read code. Most programmers aren't interested. – tcrosley May 28 '13 at 2:58
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:

share|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).

share|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.

share|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

share|improve this answer
This is a bit risky... there's way more bad C++ out there than good. – jozefg May 28 '13 at 1:29
@jozefg That's true for all languages – hbrock May 28 '13 at 1:30
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. – jozefg 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.

share|improve this answer

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