5 ms·
How Little Things Change: a Pascal-to-Javascript Converter
- 3pt14159 15y agoIt's cool, and I've seen this happen before with 30 year old banking code, but it is easier with the simpler languages. Write me a Ruby to JavaScript or a Common Lisp to VBA converter and I'll be much more impressed.
- azakai 15y agoIt sounds like this does a naive conversion of syntax to syntax. That will work for most code, but anything that relies on type specifics will fail. For example, Pascal integers are (I believe) 32-bit ints. But addition of such values in JavaScript can create a double value, instead of overflowing.
- derleth 15y ago> How Little Things Change ... in Algol-derived languages that don't have special features to take advantage of hardware-specific functionality, such as vector processing or pervasive multicore.
- sitkack 15y agoQuick, someone tell Donald Knuth!
- IvoDankolov 15y agoTo be fair, going from a less syntactically rich syntax to an almost complete superset of it isn't too hard. Yet, to draw from that the conclusion that javascript, or any other modern language of that family is pretty much the same seems like too much of a stretch to me. I just don't buy the argument that "oh, pretty much no one uses the new syntax" invalidates it. One usually doesn't go around designing features around what an idiot would use. And to ignore a feature on that exact point, I think, completely misses how much modern compilers can do for you. I'd very much like to see converting something that uses yield[0] to generate collections in C#, or handling variable capture and anonymous functions to, say, C, by just twiddling around with the syntax. [0] : I have working lazy evaluated collections in C++, complete with state machine generating code. It is not, by any stretch of the imagination, pretty to implement. However, being able to say - naturals()->Map([](int x) { return 2 * x; })->Take(N); - can be pretty satisfying.
- russell 15y agoThis is not rocket science.* I did a Pascal to C translator back in the 80s. It was something like a two week project back then, with another month or so when we decided to make it a commercial product. Most of the effort was not the translation but implementing a string package that duplicated the Pascal semantics without the brain-dead Pascal typing, where string[10] was a different and incompatible type from string[11]. (Actually, we got around that in the original code by writing a Pascal to Pascal interface written in C.) His conclusion that things stay the same is totally wrong. Pascal is a very primitive language, and it is usually straight forward to translate from a primitive language to a richer one. And C was richer. Programming in C was like breathing fresh air. My productivity doubled. There are more doublings with modern languages like Python and JavaScript. * I posted a comment yesterday mentioning some work I had done on Project Apollo. That WAS rocket science. ;-)
- abecedarius 15y agoI wonder if you could convert TeX. (Background: http://www.monperrus.net/martin/compiling+Knuths+tex+with+GNU+Pascal+-+gpc http://www.monperrus.net/martin/compiling+Knuths+tex+with+GN... )
- VMG 15y agoWhat is the state of general language-to-language converters? Are there any projects trying to do this?
- wlievens 15y agoAnd more importantly, is there any business in this? Converting code as a gadget in one thing, but is there actually someone looking for a practical use for this? It's easy to say "But there are thousands of companies who want to convert there legacy code", but is converted code actually good enough compared to a rewrite? Is it feasible?