5 ms·
In academia many compilers are written in functional languages, particularly OCaml. Unfortunately, the programming community has come to this bone-headed idea t
by pharmakom 6y ago
In academia many compilers are written in functional languages, particularly OCaml. Unfortunately, the programming community has come to this bone-headed idea that to be a serious language, its compiler must be implemented in itself. As a result, compiler implementation languages follow popular language trends. I’m sure a much faster TypeScript compiler could be written in OCaml or Rust, for instance.
- MaxBarraclough 6y ago> Unfortunately, the programming community has come to this bone-headed idea that to be a serious language, its compiler must be implemented in itself. I wouldn't say so, I think 'serious' compiler developers seem to take a fairly level-headed view here. Python and JavaScript for example aren't likely to ever be self-hosting, as it wouldn't make much sense. There's PyPy of course, but people only pay attention to PyPy when it does impressive things with performance, it doesn't get all that much 'credit' for being written in RPython. If that were all it brought to the table it would be viewed as a mere curiosity. Java is moving to be more self-hosted (Graal), but this can bring real advantages (fewer undetected buffer overflows inside the JVM for instance), it's not being done just because it's cute. Compilers can of course be written in all manner of different languages, I don't think it's a mistake that DMD is written in D, or that GNAT (the Ada frontend for GCC) is written in Ada, or that GHC is written in Haskell. It could serve as a useful example of a complex program written in that language, and it only requires that contributors know the language they're compiling. > I’m sure a much faster TypeScript compiler could be written in OCaml or Rust, for instance. In that specific instance I suspect you might be right, but this is just guesswork.
- onei 6y agoI've never used it, but [1] claims to be a much faster js/typescript compiler than some of its competitors and written in Rust. 1. https://github.com/swc-project/swc https://github.com/swc-project/swc
- pharmakom 6y agoHmmm my conclusion was drawn from the following languages having their main compiler written in that language: Haskell, Java, Scala, OCaml, Kotlin, C++, C#, F#, Rust, Go, Nim, Zig... Not criticising any of these choices, but one has to wonder why. Most of these compilers were rewrites after a bootstrap implementation was created in an existing language.
- gpderetta 6y agoat least two reasons come to mind: simplified bootstrapping and being a testcase and a source for feature requests for the language itself (especially important early on when there are few large codebases in that language).
- pharmakom 6y agoIs it a good test case though? If the language is designed for writing compilers then sure, but I imagine most people using TypeScript (for example) just want to write full-stack web applications.
- MaxBarraclough 6y agoI agree that TypeScript isn't an obvious choice for writing a compiler, but self-hosting still has advantages. It tests out the language at scale, and there's the 'dogfooding' aspect that the compiler developers use the language they created (although as you say they're using it for an unusual purpose).
- pjmlp 6y agoDepends, https://www.infoworld.com/article/3436840/microsoft-proposes-static-typescript-for-embedded-systems.html https://www.infoworld.com/article/3436840/microsoft-proposes... https://www.microsoft.com/en-us/research/blog/rocket-fast-embedded-typescript-for-makecode-arcade/ https://www.microsoft.com/en-us/research/blog/rocket-fast-em...
- wrycoder 6y ago
- pjmlp 6y agoThere have been self hosted Java versions for quite some time now, with JikesRVM being the first one.