CoffeeScript is a language with a very clean Ruby-like syntax that transcompiles to JavaScript. Does the same thing exists with C? Then writing more readable and as fast as original C programs would be possible. If it doesn't exist, do you think that it would be a good idea?
|
closed as not constructive by gnat, Glenn Nelson, Martijn Pieters, MichaelT, Dynamic Mar 17 at 22:04
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.
|
CoffeeScript compiles to JavaScript for a very simple reason, JavaScript is the de facto client side language and it would be unreasonable to expect browser vendors to natively support CoffeeScript, when all it offers is an alternative syntax. In a very similar manner, the main point of high level language to C translators is immediate portability, as there's a C compiler for almost every platform and an abundance of C libraries. Vala, for example, was designed to:
GNOME is a traditionally C oriented project and GObject specifically is written in C, Vala wouldn't probably find much love amongst GNOME developers if it compiled to machine code, regardless of it's friendlier nature (and syntax). Not everyone seemed to like the syntax, to the point that another language, Genie, was build to improve upon it. For a C++ example, Facebook developed HipHop, a PHP to C++ translator. They were trying to solve a very specific issue, CPU usage, without having to replace all their PHP code and re-train their engineers (or worst, replace them). This is a far more specific example, as Facebook scalability issues are, well, unique, and again having access to the intermediate C++ code can be useful, as PHP extensions are written in C and C++. So a translator from a high level language to another is a good idea mostly when you access to the intermediate code is required. For CoffeeScript, the JavaScript code is necessary because of its wide browser adoption, and for Vala, Genie and HipHop because of the existing codebase. Obviously having access to the intermediate code means that you can further optimize it if need be. But generally speaking, it wouldn't be such a good idea to build a language that translates to C, or any other language, if you didn't have any use of the resulting code. There are so many languages out there, if you can't cope with C, just pick an other. Coincidentally the first C++ compiler written by Bjarne Stroustrup, CFront, was a C with Classes to C translator, but that was mainly because as a new language, it was impossible to bootstrap C with Classes. |
||||
|
|
|
I'm going to cover a few points Yannis Rizos didn't in his otherwise great answer. Yes, many languages exist. C is a common target for compiler back-ends as it's incredibly portable and heavily optimized, although with LLVM there's not much point to it. A few implementations I know that do this are:
No, just because it uses C as an intermediate language doesn't mean you will reach its speed. The reason C is fast is because of the method of writing the code which is obviously different for other languages. It's just a portable assembly, nothing special. |
|||
|
|
|
Vala and Genie are both languages that compile into C. haxe compiles into C++, but I'm not sure that's what you want. |
|||
|
|
|
Rock is an ooc compiler that generates C99 source. The ooc-lang is a programming language with objects, first-class functions, and pink unicorns. The ooc is a dynamic-language and walks so far away. It generates fatter and slower c codes. u need modified more to suite your requirement. But it is a good start point. |
|||
|
|
|
|||
|
|
|
OCaml can compile to bytecode, to native code, can be interpreted directly, or can compile to C. |
|||
|
|
