5 ms·
Besides being a fun side project and having a chance to play with lexical parsing - does this have any point? Converting programming languages really doesn't s
by elliottcarlson 16y ago
Besides being a fun side project and having a chance to play with lexical parsing - does this have any point?
Converting programming languages really doesn't serve any purpose whatsoever - this can't be used as a learning tool (a rubyist wanting to learn php) nor should this output ever be trusted in a production environment as you are going to count on the converted code being as efficient as your original code.
If you want to code in PHP, use PHP - if you want to code in Ruby, use Ruby - this just seems silly.
- jrockway 16y agoConverting programming languages really doesn't serve any purpose whatsoever - this can't be used as a learning tool (a rubyist wanting to learn php) nor should this output ever be trusted in a production environment as you are going to count on the converted code being as efficient as your original code. I'm guessing you don't use a lot of programs written in C?
- tlrobinson 16y agoThere are plenty of reasons to use source-to-source compilers (which is what I assume you meant by "converting programming languages") * Running multiple languages (each with it's own strengths) on platforms that natively support only a few languages. e.x. GWT, CoffeeScript. * Enhancing an existing language. e.x. Objective-J, Stratified JavaScript. * Performance. e.x. HipHop for PHP. * Quickly building new languages. Objective-C (and I think C++?) was originally just a preprocessor for C. That said, I personally don't find a Ruby-to-PHP compiler particularly useful. Maybe it could be useful for running Ruby on the ubiquitous and cheap Apache/PHP shared hosts, but I suspect the overhead of loading a large amount of code (even just Ruby's standard library, let alone Rails) on each request will make that infeasible.
- elliottcarlson 16y agoRunning multiple languages (each with it's own strengths) on platforms that natively support only a few languages. e.x. GWT, CoffeeScript. While this may be a valid arguement for some - I just can't accept it - if you are targeting a specific platform you really should (completely imho) use the tools meant for it. Anything else will easily lead to issues that may not be debug-able if you aren't already familiar with your target. Enhancing an existing language. e.x. Objective-J, Stratified JavaScript. Both of these enhance an existing language by creating a interpreted scripting language that gets compiled down by the original language. I wouldn't classify these as a source-to-source compiler imho. Performance. e.x. HipHop for PHP. HipHop is indeed a good example and I stand corrected there. The slight difference is that this is specifically targetted at creating highly optimized C++ to be compiled for quicker execution. In a Ruby-to-PHP example it's certainly not going to add performance gain and is a silly idea - but as I said, I didn't think about a valid execution like HipHop in my initial blanket statement. Quickly building new languages. Objective-C (and I think C++?) was originally just a preprocessor for C. I didn't even think about preprocessors and they are indeed another valid implementation for source-to-source compilation. My original statement was a bit too quickly posted - thanks for the correction!
- chc 16y agoThat's about as sensible as saying that languages that compile to machine code are impractical because you can't read machine code on all the platforms where you're going to deploy. Which is every language, ultimately. And you're also discounting the possibility that somebody might know multiple languages well enough to support the generated code (as is usually the case for CoffeeScripters) but are more productive one language for certain tasks.
- billybob 16y ago"if you are targeting a specific platform you really should (completely imho) use the tools meant for it. Anything else will easily lead to issues that may not be debug-able if you aren't already familiar with your target." By that logic, since my processor doesn't natively run Ruby, I should be coding in machine language. I can't speak for CoffeeScript yet, but the front-end developer who sits near me is using SCSS to generate CSS for our web pages, and he is able to do things that wouldn't be practical with plain CSS. For example, change a base color variable from blue to green, and have all the other colors on the page adjust to use complementary colors. If you trust Ruby to produce reliable C code and C to produce reliable assembly code, etc, isn't it possible that Coffeescript could produce reliable Javascript? Mightn't it give you advantages like Ruby gives you over plain C? I think this is less a matter of "compiling X to Y is good/bad" than "do I trust this particular conversion to be done correctly?" As far as compiling Ruby to PHP - well, I can't see any use for that at the moment, but I'm sure someone will come up with one. :)
- pkulak 16y agoC++ started out as a precompiled language, and I love CoffeeScript, which compiles to JavaScript. Java and C# don't compile all the way down to assembly either. There are plenty of reasons to compile one language to another.
- rtaycher 16y agoJava/C# are different in that they compile to a bytecode which is like vm assembly its also not meant as a high level programming language(note that this isn't always compiled to assembly at the end as it can be interpreted, standard java for instance does both jit and interprets for best results).
- viraptor 16y agoBoth Java and C# can be compiled to native binaries - there's nothing stopping that. The standard runtimes for them just don't do that. Java can be compiled via gcj ("It [GCJ] can compile Java source code to Java bytecode (class files) or directly to native machine code, and Java bytecode to native machine code." - http://gcc.gnu.org/java/ http://gcc.gnu.org/java/). C# can be compiled down to native code using various tools. MonoTouch uses that to run C# on iPhones for example.
- rtaycher 16y ago"Converting programming languages really doesn't serve any purpose whatsoever" Compilers are useful. This probably won't reach production quality but that doesn't mean it couldn't with the right effort, see hip-hop or one of those x-> javascript compilers.