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?
5
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:
- Programming Pearls (Jon Bentley)
- Code Complete (Steve McConnell)
- Accelerated C++ (Andrew Koenig and Barbara Moo)
- Effective C++ (Scott Meyers)
- Design Patterns (Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides)
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).
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.
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):
wwww.github.com
www.codeplex.com
code.google.com
Also you should read: The C++ Programming Language by Bjarne Stroustrup
3
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.