3 ms·
> Programming languages aren't slower or faster. The implementations of them are. People only say this if they haven't implemented a language. Look at somethi
by overgard 11y ago
> Programming languages aren't slower or faster. The implementations of them are.
People only say this if they haven't implemented a language.
Look at something like PyPy. The work is absolutely brilliant, written by insanely smart people... and it's still vastly slower than C for reasons that are implicit in the language. There are just aspects of the language that are hard to deal with (a lot of hidden allocations on the heap, etc.)
Here's a good talk on the subject: https://speakerdeck.com/alex/why-python-ruby-and-javascript-are-slow https://speakerdeck.com/alex/why-python-ruby-and-javascript-...
- spoiler 11y agoPyPy is still just a Python VM--it's not compiled, like C is. You could write a Python compiler, but it would be difficult, and you'd need to sacrifice certain parts of the language (and/or extend it, even). Take a look at Crystal[1]. Most Ruby code will compile without modification. Sure, some cases where type deduction is not possible (like `[]`), and certain cases of meta programming (like dynamic class creation at run-time), or accidentally calling a method on Nil (which is actually a feature to prevent runtime NPE[2]). [1]: http://crystal-lang.org/ http://crystal-lang.org/ [2]: Null Pointer Exception, in case the acronym was ambiguous.
- overgard 11y agoWell, there is a python compiler. And the compiled code is fast (although, the compile times are absurdly long). Specifically, RPython is a compiled language, and PyPy is written in RPython. So yeah, it's possible, and it has been done, but on the other hand... RPython is only superficially like Python, the semantics are vastly different. It's technically a subset, but the way you approach writing it is way different. It tends to feel like C with some syntactic sugar. So I don't think that invalidates what I'm saying, I think it actually demonstrates it: if you want efficient code the language needs to make efficiency a priority.
- spoiler 11y agoI agree, although I wouldn't say efficiency needs to be a priority. The language should simply be aware of the machine model instead of abstract those. It should know there's a processor, and that there's memory. Crystal does a pretty good job at being efficient without sacrificing much!
- ericfrederich 11y agoLook at implementing the Python language, couldn't you say that Python is faster than C if PyPy is faster than CPython ;-)