5 ms·
This seems like the sort of a comment that can only be written by completely refusing to understand why compiler writers take advantage of UB. Compiler writers
by tyg13 3y ago
This seems like the sort of a comment that can only be written by completely refusing to understand why compiler writers take advantage of UB. Compiler writers are not engaging in "adversarial" behavior with their users -- they are their own users!
The simple truth is a lot of UB exists to allow for optimizations that programmers entirely take for granted. In order to optimize something, you have to make assumptions, particularly when dealing with languages as permissive as C and C++. By programming to an abstract machine and explicitly specifying which behavior is defined and which is not, we allow a compiler to make these assumptions. Despite what you may wish, a compiler is not able to read your mind to know when a given piece of UB is actually code that you intended to execute with particular semantics, or whether it's the result of some other optimizations on a code path that will never execute.
- eru 3y ago> Compiler writers are not engaging in "adversarial" behavior with their users -- they are their own users! Only if your language is self-hosting, isn't it?
- arcticbull 3y agoThat's usually a major checkpoint for a programming language maturing no? Go became self-hosting in 2015 (1.5) [1] Rust was originally written in OCaml and became self-hosted in 2011 - excluding LLVM of course, but I guess, that's kind of up to you where you draw that specific line. [1] https://go.dev/blog/go1.5 https://go.dev/blog/go1.5
- tialaramex 3y agoIt might make sense for a General Purpose language, but really only if the language's goals make it suitable. For example suppose you decided goal #1 is ease of use for beginners so you consciously choose verbose syntax. It's unlikely that your compiler is written by beginners and they may get sick of needing all this verbosity. For Special Purpose languages it only makes sense if their purpose is centrally writing compilers. It doesn't make sense to write your Verilog "compiler" in Verilog.
- eru 3y ago> That's usually a major checkpoint for a programming language maturing no? It depends on the goals of the language. Of course, compiler writers tend to be (relative) fans of their language, so they might want to use it more than might be wise. But eg I wouldn't want to write _any_ compiler in C or Fortran or Cobol. That includes not wanting to write C, Fortran or Cobol compilers in these languages. (But I think any language that you might want to write a compiler in should have algebraic data types and pattern matching at the very least, especially these days.) Somewhat ironically, writing a Python compiler in Python would be an ok idea, but writing a Python interpreter in Python is probably not a good one.