5 ms·
Fascinating, while I was reading that, it got 5 upvotes! Mindblowing. This is a really awesome description too. The only thing I know about compilers is that I
by Swizec 14y ago
Fascinating, while I was reading that, it got 5 upvotes! Mindblowing.
This is a really awesome description too. The only thing I know about compilers is that I implemented one for class (without fancy optimisations) and I am surprised any software works, ever. Compiler are just ... mindbogglingly complex things. Almost as much voodoo dark magic as engineering.
- perlgeek 14y agoOne of the reason software still works is that compilers are (mostly ()) very easy to test. Just just need an input source code, and expected outcome (either compiler error, or the result when running the code). No intermediate state to consider, no concurrency, no test database to set up etc. Oh, and many serious compilers can compile themselves, so bootstrapping is a pretty good test too. Another reason is that compilers simply must* work for software development to continue, so people have spend the necessary amount of energy to get implementation and tests "right". (*) There are always exceptions, like when a compiler auto-parallelizes code and introduces a race condition that is rarely triggered. But those cases are blessedly rare.
- Swizec 14y agoTesting was the hardest thing I came across. You have on your hands a compiler that you can no longer think of a program for, that would produce an incorrect result. You're happy. Then your friend comes along and the first thing they try behaves incorrectly. The problem isn't even that the compiler would crash and burn, it lovingly compiles the input program into something that does the wrong thing!
- michaelt 14y agoThere are tools available that can generate random (valid) C programs, comparing the results generated by code from different compilers [1]. CSmith say bugs have been found in every tool tested [2] - from GCC to costly commercial compilers. [1] http://gcc.gnu.org/wiki/summit2010?action=AttachFile&do=get&target=regehr_gcc_summit_2010.pdf http://gcc.gnu.org/wiki/summit2010?action=AttachFile&do=... [2] http://embed.cs.utah.edu/csmith/ http://embed.cs.utah.edu/csmith/
- eru 14y agoWhat did you write your compiler in? Writing compilers in, say, raw C is indeed a complex endeavour. But using, say, OCaml or Haskell (which is secretly a DSL for compiler writing) should make it much easier to not fail silently.