4 ms·
Cython[1] is the closest I'm aware of to optional type annotation for Python. It works quite well, although requires a separate compilation step and the source
by michaelmior 13y ago
Cython[1] is the closest I'm aware of to optional type annotation for Python. It works quite well, although requires a separate compilation step and the source code is no longer Python.
I assume by "new PHP implementation", you're referring to Hack[2] which is a different language, although heavily based on PHP. (I believe Hack is a superset?)
[1] http://cython.org/ http://cython.org/
[2] http://hacklang.org/ http://hacklang.org/
- nly 13y agoCython actually shows the cost of interpretation quite well. Even without added type declarations it speeds up a quicksort of a list of integers by anywhere from 40-50%. https://github.com/psoberoi/stepanov-conversations-course/tree/master/languages/python https://github.com/psoberoi/stepanov-conversations-course/tr... I certainly don't see Cython as anything but a quick way to get efficient C code in to Python module though... you typically get the worst of both worlds with compilation + dynamic typing.
- pekk 13y agoWhy are you not using existing, efficient sort implementations?
- nly 13y agoThe github repo is from Alex Stepanovs course at A9, which is largely focused on data structures and algorithms. The point of the benchmarks is to compare 'FORTRAN like' code in many languages and to demonstrate that languages don't really matter if you pick the right DS&As. That quicksort algorithm is about as efficient as it gets btw.
- maxerickson 13y agoThere is support in Cython for doing the compilation transparently: http://docs.cython.org/src/tutorial/cython_tutorial.html#pyximport-cython-compilation-the-easy-way http://docs.cython.org/src/tutorial/cython_tutorial.html#pyx...
- girvo 13y agoWell yes, Hack is a "new language" in a similar way TypeScript is, but Hack is built to interoperate with regular PHP code. It's a superset, similar to how Objective-C was/is with C, only even more integrated with it's subset language :) Regardless, it's damned nice (especially with TypeScript on the front end: static optional typing everywhere!)