3 ms·
Haskell used to have a C back-end. That philosophy could in principle be extended to anything.
by loup-vaillant 10y ago
Haskell used to have a C back-end. That philosophy could in principle be extended to anything.
- tluyben2 10y agoThe problem is that usually not very human readable C comes out of it; to use something instead of your company's language of choice, unless you are the CTO or something else high up the ladder, would need to compile to the company's language and do it in a human readable way. Some Javascript 'transpilers' do that (I think Coffeescript?) but usually it really acts as a compiler and the idea is that no-one should need to read / use the source code that is emitted besides for running it.
- jjnoakes 10y agoThis is exactly it. This is why I think rust is a winner. I bet most rust code could be compiled to c++ very cleanly. You get rust's compiler with all of the safety checks, and you get the platform support of C++. It would be a dream.
- loup-vaillant 10y ago> The problem is that usually not very human readable C comes out of it The x86 assembly or LLVM intermediate representation that comes out of most compiler is not very human readable, but I don't see anyone having any problem with it whatsoever. Readability of generated code was never the point of C using C as a back-end. The point is portability and tooling. By the way /u/jjnoakes can suggest fancy languages and compilers, if only they can generate native code on obscure platforms (I guess, something other than x86 and ARM). Generating C code (even utterly unreadable C code) would solve his problem.
- jjnoakes 10y agoRemember, it isn't only the architecture. It is also the calling conventions and object/shared library/executable file format. All things that require work if I cross compile, but all things I get for free if I generate C or C++. I would prefer readable C or C++ as much as possible because it gives me debugability if the code generator goes wrong and it gives me an out if I want to move away from the language some day.
- loup-vaillant 10y agoWell, there aren't many solution out of this hole. If you need another language, you might have to write (and control) the compiler yourself. As in, if the code generator (or anything else) goes wrong, you can correct it. <sarcasm> Now this might require a little bit more work. </sarcasm>
- jjnoakes 10y agoThe solution I mentioned in my original post gets me out if this issue, as does the one in the article that this hn post is all about.