Re:Write Python inline in your Rust code
by airstrike on Tuesday April 23, 2019 @11:19AM
(#19729473)
Cool, but can anyone explain to me why I'd want this?
[ Parent
| on HN ]
Re:Write Python inline in your Rust code
by andolanra on Tuesday April 23, 2019 @12:59PM
(#19730509)
The author mentioned on Twitter that it was useful for quickly plotting data in Rust, with this example:
fn main() {
let data = vec![(4, 3), (2, 8), (3, 1), (4, 0)];
python! {
import matplotlib.pyplot as plt
plt.plot('data)
plt.show()
}
}
Source: https://twitter.com/m_ou_se/status/1118255841961025539This snippet right here might actually convince me to learn Rust. I work in C++ a lot, and deal with problems where visualization would be useful if it were easy. But because nothing in C++ is ever easy, I end up not doing it in a lot of cases, sometimes to my own detriment.
To gain access to thousands of Python modules would be my guess. A billion years ago, I wrote PyInline do that you could easily write C code in your Python program. I was stunned at how many people actually used it for real projects.
Sometime, it's just easier to get something working in Python. Plug it into your rust project, see how this holds, and if you are satisfy, convert to rust (or not, maybe it's enough).
I don't know if it's possible, but the first thing that comes to mind would be testing a Python extension written in Rust without having to leave the Rust testing ecosystem.
Because you want to program in Rust but have a specific need no Rust library full fills but Python libraries do. Suppose you need to convert between Gregorian, Julian, Islamic, Hebrew, and Armenian calendar dates. No such library exist for Rust but they do for Python. So you either spend (waste) time writing one for Rust or you use this Python binding.
Re:Write Python inline in your Rust code
by nicoburns on Tuesday April 23, 2019 @11:26AM
(#19729536)
I guess it could be pretty cool to make use of a python library from a Rust project.
Re:Write Python inline in your Rust code
by colonelpopcorn on Tuesday April 23, 2019 @12:02PM
(#19729881)
You're sacrificing the speed and low level nature of Rust though. If performance is not critical why would one choose Rust in the first place? It's neat, but I don't see any need or use case for this.
At work, we make high performant drone control systems in Rust. But for testing and debugging, we simply use Matplotlib (a Python library) to make plots of simulations, etc. So we prefer Rust for the control systems themselves for the speed and reliability, but for plotting results of simulations, we don't care much about performance and rather just use something with all the features we need.
Re:Write Python inline in your Rust code
by tingletech on Tuesday April 23, 2019 @12:23PM
(#19730099)
My grandpa used to make drone control systems with operation amplifiers (in the 1980s). I have a picture of him with a big plotter on a stand in a field flying a drone.
May I ask where you work?
Re:Write Python inline in your Rust code
by krat0sprakhar on Tuesday April 23, 2019 @05:28PM
(#19733078)
Seems like: https://github.com/dronesforwork
90% of time is spent in 10% of code(for some value of 90/10). As a concept, this will give you freedom to use extensive Python ecosystem, flexibility to write glue code etc. in a more 'accessible' language.
Re:Write Python inline in your Rust code
by laughingman2 on Tuesday April 23, 2019 @01:15PM
(#19730702)
Then I guess you're not looking hard enough. Recently swift integration with tensorflow also introduced easy way to import python. There into swift.
Data science engineers need performant language to do lot of stuff, and rust fits the ball. But it's hard to abandon python ecosystem.
I and others hate the pattern in python to write anything performant in C, Cython or some other language and write bindings for python. The python as binding language paradigmn doesn't work when all the stuff you want don't exist in performant languages.
TLDR; this fits the perfect use case for machine learning/data science, to use python only when necessary and hopefully migrate projects (parts of them atleast) to rust.