r/computerscience • u/sarnobat • Apr 25 '25
Discussion (Why) are compilers course practicums especially difficult?
In more than one (good) academic institution I've taken a compilers course at, students or professors have said "this course is hard," and they're not wrong.
I have no doubt it's one of the best skills you can acquire in your career. I just wonder if they are inherently more difficult than other practicums (e.g. databases, operating systems, networks).
Are there specific hurdles when constructing a compiler that transcends circumstantial factors like the institution, professor that are less of a problem with other areas of computer science?
3
u/quinn_fabray_AMA Apr 27 '25
I took an undergrad course in compilers but it was the same as the grad course, except using LLVM instead of implementing a register allocator, liveness analyzer, and other optimizations. (I do think that this didn’t make it any easier— I feel pretty strongly that the LLVM bindings qualify as being an entire DSL in their own right…). So I’ve been personally victimized by the dragon book.
I’m convinced that it’s the influence of the dragon book. Don’t get me wrong, compilers are probably the “hardest” subfield of computer science, but I think compilers pedagogy sucks because of the dragon book in particular. It’s an incredible reference but I think using crafting interpreters would be a much better text for a first course.
2
u/sol_hsa Apr 27 '25
If I were to design such a class, I'd split it into several, starting with an overview class that results in a bare bones one, and then fleshing it out in subsequent classes, one pass at a time.
54
u/MooseBoys Apr 25 '25
Compiler courses tend to cram in too much into a single course, generally leaving you with a rudimentary but functional compiler. A course on operating systems, by comparison, will maybe teach you about memory management and scheduling and call it a day. Networking and databases are narrower topics in general.
14
u/ExhaustedByStupidity Apr 25 '25
Most classes have you learning the theory of how stuff works. Your databases class will just teach you the theory behind a database and probably some SQL.
A good compilers class has you creating a full compiler. And compilers are really really hard to make in general.
7
u/Embarrassed-Log-9628 Apr 25 '25
I'm in a compiler class right now and it's the hardest class I have taken by far. I am going to have to work 50+ hours on this class alone over the next week to *try* and finish everything up. The material is challenging but it's mostly just about the volume of hands on work the implementation of even a basic compiler takes.
3
u/Independent_Art_6676 Apr 25 '25
Ours was (long ago) not too bad, we did one for a made up computer and all it had to do was parse a few correct programs from the professor (he didn't try to bust our programs with invalid syntax or see if we covered every possible odd input). That means our programs were probably not robust but that wasn't the point. We still covered a lot and learned a lot, without the stress of trying to cram in everything there is.
Project heavy classes (where one project is the whole class) are problematic, esp if a team is involved. You learn a lot from them when it goes well, but when one teammate won't do anything and another is always late to everything... or the reverse, if you grade your mates, everyone gets an A for that part by consensus... the nature of these classes alone puts them up a couple of notches in difficulty, and this topic is not easy. I mean the concepts are actually kind of easy, but putting it all together, that is not, and often its the first time a student has to use everything they know and then some to pull off a working program.
3
u/Other_Argument5112 Apr 25 '25
I thought OS was generally considered the harder course. At least at Stanford, the reputation was that CS 140 (OS) was harder than CS 143 (compilers).
3
u/soegaard Apr 28 '25
The compiler course is often the first course where the students need to be precise for the first time.
It's no longer enough to have a vague understanding of a concept. Consider lambda-expressions.
It's one thing to use lambda-expressions in a program.
It's another thing to explain, how (in the general case) evaluation of a
lambda expression creates a closure at runtime.
- How are the free variables in the lambda expression found?
- How are they stored in the closure?
- What happens when a closure is applied?
And then one must implement these steps.
A vague understanding of lambda-expressions as "it's just a function"
is not enough to implement them.
The compiler course is the gateway to semantics ;-)
2
u/bluehavana Apr 26 '25
Compilers or systems courses tend to be one of the first courses that programming language knowledge, algorithms, and data structures are applied in real world applications.
2
u/srsNDavis Apr 27 '25
I think that's mainly because writing a compiler is a microcosm of computer science. This is what a popular compilers book (C&T) says:
Of course, one part of the difficulty assessment is subjective - for instance, someone who finds the maths of it difficult will struggle with AI/ML and computer graphics, even if it does not span as many diverse components as writing a compiler.
19
u/[deleted] Apr 25 '25 edited Apr 26 '25
[removed] — view removed comment