News for hackers. Stuff that matters.
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by Demiurge on Sunday December 21, 2014 @07:33PM (#8781450)
As I'm sure everyone, I was wondering, why... If you follow through from the top to the blog, there is authors reasoning:

Introducing Rusthon

Rust is a systems programming language, and too low level for quick prototyping, or simple web backends. It is nice to have all of the low level control so you can fine tune performance later, but it should be optional. Rusthon is a high level Python-like language that compiles to Rust. Rusthon started as a fork of Gython, which is a fork of PythonJS.

The goal of Rusthon is simple and clean syntax inspired by Python. Rusthon will allow you to code at a higher level than normal Rust code, and interoperate well with hand written Rust and the Rust libraries. You can start off writting your application in Rusthon, and drop down to hand written Rust where you need more performance.

http://rusthon-lang.blogspot.com/

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by haberman on Sunday December 21, 2014 @07:13PM (#8781420)
Compiling to Rust is a really interesting proposition, because it means the resulting program has the same safe-without-gc properties as native Rust programs.
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by quotemstr on Sunday December 21, 2014 @07:50PM (#8781485)
Unless it transmutes pointers and uses unsafe blocks, of course. One of Rust's most important features is that you can do things like that. Hell, the stdlib even has longjmp.
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by alkonaut on Monday December 22, 2014 @03:31AM (#8782446)
Surely it just does that, otherwise it would be dropping all the cognitive overhead of lifetime management that we pay (happily) in Rust, without losing safety? If that was possible you'd think it was already in the Rust specs...
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by tomjakubowski on Sunday December 21, 2014 @07:58PM (#8781506)
Really? Where's the longjmp function?
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by quotemstr on Sunday December 21, 2014 @10:50PM (#8781895)
Err, I think I was mistaken.
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by Matthias247 on Monday December 22, 2014 @06:01AM (#8782675)
Does this care about memory at all? In the transpiled code I see structures getting allocated but never deallocated.

That will work for this trivial examples, but not for anything serious.

To properly translate Python to C++ you would have atleast produce a shared_ptr<T> from every T and even that doesn't work with cycles. Rust translation is even more complicated.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by agentultra on Monday December 22, 2014 @10:33AM (#8783410)
It also doesn't even appear to generator initializer lists for the constructor which could lead to some fun behaviors down the road...
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by sdfjkl on Sunday December 21, 2014 @06:34PM (#8781356)
Reminds me of Nim (formerly Nimrod): http://nim-lang.org/
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by def- on Sunday December 21, 2014 @07:46PM (#8781478)
Nim was also in the benchmark on the frontpage yesterday: https://news.ycombinator.com/item?id=8778041
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by duey on Sunday December 21, 2014 @07:23PM (#8781432)
Why would you use this over LLVM? e.g. pyston (LLVM Python) and then using llc -march=rustc/c/cpp/whatever to convert?
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by yazaddaruvala on Sunday December 21, 2014 @07:46PM (#8781481)
The biggest reason would be the "native" interoperability. No FFIs because while you could call it a language it's more accurately syntax sugar.

Another reason with Rust at least. Rusthon can make the same memory guarantees as Rust.

Personally I wish this was done with Ruby.. But then again I'm not writing it myself, so I can't really complain.

A random last thought, it would be really something if Rust could formally prove its memory safety and then push that whole system of lifetimes and borrow checks into LLVM or a similar abstraction on top of LLVM. Because Rust as a compiler target is very interesting but it wasn't really built for that.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by rattray on Sunday December 21, 2014 @07:45PM (#8781475)
Pyston is a very exciting project. The commit velocity on github seems quite high [0]. Here's the latest status update on their blog, for those interested: http://blog.pyston.org/2014/11/21/pyston-status-update/

[0] https://github.com/dropbox/pyston/graphs/commit-activity

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by techdragon on Sunday December 21, 2014 @09:23PM (#8781683)
Except it's not targeting Python 3

Pypy is pushing towards full 3.4 slowly, which is good because I want some of that Juicy STM support in my web apps.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by BuckRogers on Monday December 22, 2014 @11:48PM (#8786808)
You are one of few concerned with Python3 targets. Pyston, PyPy are all mostly Python(2) projects. PyPy3 does exist, but it's considered beta and not recommended for production use as PyPy is.

Python(2) code/libraries will mainly survive on PyPy/Pyston going forward. With stuff like Nim and Rusthon, I think something like those will carry the torch forward after Python(2), rather than Python3.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by amit_m on Sunday December 21, 2014 @07:21PM (#8781426)
Cython already compiles to C and is relatively mature.

In my opinion these hacks will always be specialty tools. What the world really needs is more languages that are both expressive and run pretty fast. e.g. Julia.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by shadowmint on Sunday December 21, 2014 @07:53PM (#8781492)
Cython isn't the answer.

It's a neat tool, for sure, but it's a very specific thing, and it has several down sides, mainly:

- Every module compiles to a shared library.

- Requires significant c infrastructure installed on the target machine to compile.

- Compiled code cannot be used without the python runtime.

This renders it almost useless for generating code for serious applications. It's an adhoc solution to ffi and slowness because those are things are major issues for python.

However, this (Rusthon) has some serious upsides:

The transpiled (if that's the word?) C++ / rust code is portable and fast.

It does not include the bloated standard python library.

It can be directly compiled using existing compiler tools for mobile devices (to be fair, as the kivy-ios project shows, this isn't impossible with cython, but it involves patching the python source to load modules differently).

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by andreasvc on Sunday December 21, 2014 @08:08PM (#8781527)
> - Every module compiles to a shared library.

How else would you import a module if it wasn't? If you want to reduce the number of shared libraries you could put all your code in a single module, of course.

> - Requires significant c infrastructure installed on the target machine to compile.

Anything which involves compilation to native code requires significant infrastructure.

> - Compiled code cannot be used without the python runtime.

And this is a downside why? Combining the best of both worlds--native code and Python--is the whole point. If you want to take out Python from the equation just use C/C++.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by shadowmint on Sunday December 21, 2014 @08:15PM (#8781541)
The issues I pointed out are related to building distributable targets.

Shared library per module and 'wrapped' compiler execution for example, is fundamentally hostile to distribution for mobile environments. Have a look at the hoops kivy-ios jumps though. It's absolutely ridiculous.

That's the thing python is the worst at; building a single stand alone application that does not require the user to install a copy of python and run pip to download a million dependencies before it will run.

This isn't in question. It's just life; that's not what python is good at.

Cython doesn't solve that problem. It solves a different set of problems; namely, ffi and speed.

My point is that by choosing an alternative approach (compile to portable C++ / rust) this project gives you the benefits of ffi and speed and distribution.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by andreasvc on Sunday December 21, 2014 @08:44PM (#8781608)
For Cython's intended audience, mostly scientific programming, distribution is just not a primary concern, but rather efficiency and productivity. I think the issues you cite are mostly the fault of the mobile targets themselves; e.g., their app stores put up artificial barriers of which languages may be used. On the server side or on a compute cluster having to pull in a bunch of dependencies is absolutely no problem, and is the very reason the ecosystem of Python provides productivity gains.
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by shadowmint on Sunday December 21, 2014 @09:31PM (#8781695)
It's a little bit convenient to blame the platforms when your things don't work on them.

The reality is that the tools (cython, python) were built without mobile platforms in mind, and they (currently) are ill suited to supporting them. That's not the platforms fault; it just an artifact of the development history of the projects.

Cython is not a general purpose compile to C solution. It solves a different problem to Rusthon.

/shrug

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by andreasvc on Sunday December 21, 2014 @09:49PM (#8781747)
I see your point, Cython is not the right tool for the job when that involves mobile platforms. I just thought that the claim in your original comment came off as sweeping--"Cython isn't the answer"; you didn't mention that you had a specific problem in mind.
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by BuckRogers on Monday December 22, 2014 @10:20PM (#8786630)
" It's a little bit convenient to blame the platforms when your things don't work on them."

Except, Python does work on them.. no one's blaming the platform. Everyone is at the same disadvantage on non-native platforms as everyone else. No ones blaming it. It's just that it's a hard think to retrofit -anything- to Apple or Google's platform that isn't ObjC/Java.

Python is further along here than most, which should be commended.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by BuckRogers on Monday December 22, 2014 @09:38PM (#8786548)
"That's the thing python is the worst at; building a single stand alone application that does not require the user to install a copy of python and run pip to download a million dependencies before it will run. This isn't in question. It's just life; that's not what python is good at."

It is in question. I hate people with these narrow-minded viewpoints as if there's not a ton of flexibility and creativity going on with programming. It's preposterous and you must have a grudge or ulterior motive.

Python is not a stationary target with a fixed set of pros/cons. It's changing all the time.

In fact, I do what you're suggesting it isn't good for, all the time. Distributing single-binary applications using PyInstaller and Nuitka.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by andreasvc on Sunday December 21, 2014 @07:54PM (#8781494)
The trade-offs between a single JITed language versus having a scripting and native language are interesting. I think there are a few advantages to the latter approach though. JIT is never going to beat carefully hand-optimized code, and the amount of code that needs such optimization is small. Furthermore the performance of JIT is not necessarily predictable, and comes with additional memory usage. Finally languages such as Python, R, or Matlab have a vast ecosystem of libraries; this gives a big incentive to keep on interoperating with them instead of switching to a new language.
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by BuckRogers on Monday December 22, 2014 @11:45PM (#8786798)
It is interesting and the combo of native compiled and interpreted is IMO preferable over single JIT.

The good news is that Python itself offers JIT though PyPy, and now Rusthon offers the former.

I prefer Rusthon (or the idea of Rusthon if it works out well) over all else for the future. But with standard Python (meaning 2.x) code carried forward primarily with PyPy at the same time.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by andywood on Monday December 22, 2014 @09:18AM (#8783094)
Some comments here suggest the possibility of making manual changes to the Rust code. After cross compiling, how does one make changes to the Rust code, then go back and make changes to the Python code, and cross compile again without losing the customized Rust code?
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by jumanji on Sunday December 21, 2014 @07:21PM (#8781425)
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by broodbucket on Sunday December 21, 2014 @11:59PM (#8782065)
https://github.com/rusthon/Rusthon/blob/master/pythonjs/pyth...

Doesn't look like there's C++ flag in python_to_pythonjs, so I'd guess not.

Re:Rusthon – A Pythonic language that compiles to Rust and C++ by chenzhekl on Sunday December 21, 2014 @11:50PM (#8782038)
It would be great if it can interoperate seamlessly with existed C++ library.
Re:Rusthon – A Pythonic language that compiles to Rust and C++ by lago on Sunday December 21, 2014 @10:02PM (#8781778)

  # naming fix :)
  mv Rusthon Pythrust