3 ms·
There is much much more to programming languages than syntax. If syntax was the main difference between programming languages it would be very easy to write tr
by haberman 15y ago
There is much much more to programming languages than syntax. If syntax was the main difference between programming languages it would be very easy to write translators from one language to another. Lots of people like their pet language more than JavaScript, so why don't we see tons of compilers like Python->JavaScript, Lua->JavaScript, Ruby->JavaScript etc?
The answer is that syntax is just the tip of the iceberg. Even ignoring major language differences (garbage collection, static vs. dynamic typing, lexical vs dynamic scoping, eager vs. lazy, threads vs. coroutines) there is an incredibly long list of very detailed semantics that you probably don't even realize you're dealing with when you move from one language to another. For example:
- in a complex inheritance hierarchy, which method is selected for a.b?
- how much precision do numeric types have?
- what happens when numeric types overflow?
- what order are arguments evaluated in?
- what happens if fewer arguments are passed than were declared?
- are keyword arguments supported?
- are default arguments supported?
- when are default arguments evaluated?
- are simple types like integer and string classes?
- can they be subclassed?
- can they be monkey-patched?
- will types be implicitly converted? (ie 1 + "2")?
- does 0 evaluate to true or false? what about "0"?
- are function arguments passed by value or by reference?
- are values hashed by their identity or by their logical value?
- what hooks can you define to customize the behavior of your object?
Nothing in this list is about syntax. Syntax is just the tip of the iceberg when it comes to what makes languages different.
- deleted 15y ago[deleted]
- cousin_it 15y ago> Lots of people like their pet language more than JavaScript, so why don't we see tons of compilers like Python->JavaScript, Lua->JavaScript, Ruby->JavaScript etc? Uuuuhhh, I'm really embarrassed to ask, but did you check with Google before posting that? "Tons of compilers" is exactly what we have now: https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS https://github.com/jashkenas/coffee-script/wiki/List-of-lang... . In fact my own job involves writing Java code that ends up being compiled to JS. I'd be overjoyed if such things were not necessary. I would even be okay with never using things like 1 + "2" or monkeypatching in 50% of my code if that made that 50% conform to some widely adopted cross-language standard. That would mean 50% less effort spent on any future rewrite. 50% less risk from using the new and shiny platform that came out yesterday. 50% lower rate of platform-induced bitrot for the project as a whole. C'mon, who wouldn't want the world to work like that?