5 ms·
Tell HN: The dragon compiler book (2nd edition) is a great book
Hello,
I have seen a lot of people on the internet say that the dragon book is horrible book to learn compilers from.
well, I have read some of the second edition of the dragon book and I think it is a great book. The main criticism is that its too focused on parsing. Thats just like 5 chapters. I skipped these and went straight into the intermediate language, code generation, and optimizing chapters.
These chapters give a detailed account of things such as register allocation, instruction selection, and instruction scheduling. The optimizing chapters are also good.
im not claiming im an expert compiler person. I am not but compilers is something i want to learn and so i gave the dragon book a try and i really liked it.
more importantly the dragon book made me realize that compilers are mathematical systems in a way. the ast is tree and trees have mathematical properties but graphs are needed for register allocation, dataflow analysis for optimization. optimization is math problem.
So i think this book gave me a better understanding of the field and it made appreciate compilers.
i'd say if youre interested in compilers you can start with "essence of compilation" by dr. siek and get some experience writing compilers and then read the dragon book.
i just wanted to share my experience. i think the dragon book is a great book.
- fargle 3y agoseconded. so a lot of people say a lot of things. i like chapters 1-5 just as much as the rest, btw. it's objectively a great book, written by objectively great developers and computer scientists. is it the best to learn from today? who can say. you might also say we should not start the education for structural engineering by studying the Brooklyn bridge either. but, so here we are.
- kaba0 3y agoBut as mentioned, not even the rest of the book is relevant for compilers without SSA, so I don’t think your bridge example is relevant.
- jobhdez 3y agoThe book introduces three address code which is similar to ssa
- jobhdez 3y agoYea the authors of the book won a Turing award a few years ago.
- ndesaulniers 3y agoI think the third edition of Engineering a Compiler was recently published (paperback only, WTH). I found that to be a better read IMO.
- jobhdez 3y agoI have heard good things about this book.
- eska 3y agoFrom the parsers I see in the wild (not strictly speaking about compilers here), I think most programmers should definitely spend some time studying the basics of them. It’s incredible to me how people mess up parsing even the simplest of file formats or make it super complicated.
- wwweston 3y agoHi, my name is Weston, and I'm bad at parsing (and it hurts the whole time I do it because I'm just barely clever enough to do it badly/dangerously). What else should I study besides the first 5 chapters of the 2nd edition of the dragon book?
- turndown 3y agoAn easy to reach for activity that usually involves parsing is stuff like Advent of Code, where there is almost always a parsing step.
- eska 3y agoSorry if I misinterpreted your comment, but the last sentence reads like a snark. Why did you have to go from “the basics” to “read half a compiler book”? Most developers don’t even seem to read a single Wikipedia article on it.
- kaba0 3y agoWell - do you want to be good at parsing/has any need for it? Even if you write your own programming language you are much better off using something like ANTLR to generate your grammar — the advantage is a well-specified standard description of your own grammar and no parser bugs. Though mind you, not everyone shares my sentiment here, last time I wrote that people were adamant about hand-written parsers.
- Buttons840 3y agoI'm having flashbacks to a well funded startup I used to work at. People seemed to think that to how to handle having commas in data while still being able to use CSV files was an area of active research. At, like, a dozen different layers in the application we would strip commas from any and all strings, but they would still frequently slip through and screw up the entire pipeline. The complaints I made about this quickly used up what little political capital I had. The joys of `str.split ','` based CSV "parsing".
- eimrine 3y agoI have the first edition but do not have an intention to create compilers yet, and the book is the hardest book I have for recreational reading. I can not just open it in the middle and find anything understandable.
- jobhdez 3y agoIt’s really rewarding though when you write a compiler. I recommend the experience. But if you think about compilers are so fundamental for the whole software infrastructure. So I think compilers is worth knowing. You will understand languages better; for example you will understand how statically and dynamic languages work because you will Implement a type checker, you will understand lexical scoping better because you will compile this to assembly; and overall you will have a better idea of how your high level code looks like in assembly which could help you write efficient code.you will also get to understand how memory is laid out which will help you appreciate NGINX.so by learning compilers I think you will be appreciate more web development. Those are my thoughts anyways. I’m not saying I’m correct but that’s what I’ve noticed in my journey
- Arelius 3y agoFor those that find it a bit light, I enjoyed Advanced Compiler Design and Implementation by Steven S. Muchnick. Which covers topics that I found much trickier.
- flashgordon 3y agoAmen. This is will have a permanent place in my bookshelf. I actually found that implementing some of the papers was very valuable (and joyful). Not only that this stuff points you to a lot more research generated after the book. Even better is that each paper you implement imo was very self contained on its own so you can build and use as you go.
- laichzeit0 3y agoI remember picking this book up at the university library in my second year because I had seen it in the movie “Hackers” and the cover looked really cool. I distinctly remember the parsing chapters especially recursive descent parsing. It was one of those light bulb “oh, this is how you do it” moments. Well worth spending a few weekends playing with that book, even if it’s somewhat dated, its like SICP in a sense more of a “mind expansion” device than anything else.
- Solvency 3y agoI know nothing about compiler design or compiler parsing. How broadly applicable are the chapters on parsing? Will it make the average programmer instantly more equipped to, say, write a robust JSON parser?
- sanxiyn 3y agoYes.
- kaba0 3y agoI’m not convinced that it would actually be particularly good as a parsing book either. But the average programmer should just use a CSV parser lib, why reinvent the wheel? For custom tasks learning about ANTLR is much more productive (a good parser generator)
- jobhdez 3y agoI think you would have the knowledge to build a parser generator that then you can use to write a parser for json. But you can also also just learn how to use a parser generator. You’ll have to know a little bit about regular expressions for this
- jobhdez 3y agoSICP was a great book too. It taught me to program, and bent my mind. I just marveled at the Beauty of it a few times.
- sanxiyn 3y agoBesides devoting too many pages to parsing, I think compiler practitioners have low opinion of the book because it isn't useful for them. For example, the second edition claims to be updated to modern optimization techniques, and in a sense that's true, but it is useless because the book isn't using SSA. For practitioners, SSA is not optional these days, and everything about optimization in the book needs to be updated to SSA to be useful. But you are probably not a compiler practitioner. Then I agree it is a good book to learn about compilers.
- incompleteCode 3y agoDo you recommend a book that’s more up-to-date?
- jobhdez 3y agoYou can try this book if you want something that came out this year https://github.com/IUCompilerCourse/Essentials-of-Compilation https://github.com/IUCompilerCourse/Essentials-of-Compilatio.... Go to the releases to either get the racket version or python version. But I mean cmu uses the dragon book second edition for a graduate level compiler optimization class.
- pjmlp 3y agoTiger books include SSA, GC (tracing and RC), OOP, FP,.... https://www.cs.princeton.edu/~appel/modern/ https://www.cs.princeton.edu/~appel/modern/
- jobhdez 3y agoBut the dragon book introduces three address code. SSA is a variant of three address code. Take a look here http://www.cs.columbia.edu/~aho/cs4115/Lectures/15-03-25.html#:~:text=Static%20single%2Dassignment%20(SSA),two%20different%20control%2Dflow%20paths http://www.cs.columbia.edu/~aho/cs4115/Lectures/15-03-25.htm....
- sanxiyn 3y agoWell yes, but you can't use the algorithm in the dragon book to generate three address code to generate SSA, because SSA has additional constraints. The dragon book really dropped the ball here, there is no excuse why it doesn't include any algorithm for SSA construction.
- kaba0 3y agoI had greater experience with Cooper and Torczon’s Engineering a Compiler book, I can only recommend it.
- Yizahi 3y agoReminds me of this thread :) https://news.ycombinator.com/item?id=3754545 https://news.ycombinator.com/item?id=3754545 Since it's so old that blog post is dead now, here is an archive copy: https://web.archive.org/web/20180929002914/http://www.billthelizard.com/2008/12/books-programmers-dont-really-read.html https://web.archive.org/web/20180929002914/http://www.billth...
- markus_zhang 3y agoWhat is a good book just for recursive descend parsing? I dabbed into some compiler books but found BNF difficult. Just some clarification, it is not difficult to understand but difficult to build from scratch. I'm thinking maybe a book that asks me to build up BNF expressions for a series of grammars of gradually increasing complexity would be nice.
- auxym 3y agoCrafting Interpreters was fun to read and easy to follow, even as someone with a mechanical engineering degree :)
- rramadass 3y agoYou might want to checkout Parsing Techniques: A Practical Guide by Dick Grune et.al. Came across it on HN but I have not read it though.
- atomicnature 3y agoNot a book, but a nice way to start with the task is to build up a simple JSON parser using recursive descent; This [1] is a great tutorial to start with. Personally, I followed up with a standards compliant JSON parser of my own, in Python [2], and later ported it into a larger golang codebase. Practically building up multiple JSON parsers taught me to build my own DSL, using recursive descent parsing. My path admittedly is quite non-standard and idiosyncratic, but was way more fun than going through a textbook :) [1]: https://www.booleanworld.com/building-recursive-descent-parsers-definitive-guide/ https://www.booleanworld.com/building-recursive-descent-pars... [2]: https://github.com/HexmosTech/json-rd https://github.com/HexmosTech/json-rd
- ryanmercer 3y ago"green book International Unix Environments. orange book Computer security criteria, DOD standards. book with man wearing pink shirt The Pink Shirt Book, Guide to IBM PCs. So called due to the nasty pink shirt the guy wears on the cover another book Devil book. The Unix Bible. another book Dragon book. Compiler design. large red book The Red Book. NSA Trusted Networks. Otherwise known as the Ugly Red Book that won't fit on a shelf." Sorry, title took me down a nostalgic trip.
- deterministic 3y agoI make a living as a high-performance JIT compiler writer, and the dragon book is a waste of time in my opinion. There are much better books out there. If you are a beginner, start by learning Recursive Descend parsing. And then learn LLVM.
- rramadass 3y ago> There are much better books out there. List please?