Live data from Hacker News

Why scientists are turning to Rust (2020)

nature.com

51–55 of 55 posts

Re: Why scientists are turning to Rust (2020)

#51

Earlier quoted context omitted.

I do not have any experience with C++ and thus none about its python interop, which makes it hard for me to compare it to nim's python interop which I do have some experience with. Given that, I'm curious what bits of C++/python interop are easier. I'm mostly asking because my experience of nim-python interop consisted of: Compile nim module with nimpy imported. Put compiled nim module somewhere where your python can…

Well, I certainly wouldn't call C++/Python interop easy . It is, IMO, verbose, arcane and complex. BUT, once it works, you have truly seamless integration of Python and C++ code. It feels as magical as, say, two languages interacting on JVM or .NET (not that I used either). Or different languages talking through a REST API. In C++, you'd write your C++ code as if you don't care about Python. Then, you add the "glue"…

Thanks for the Infos! For context: I used nimpy for a bit for a reimplementation on how Django hashes passwords, making use of one of python's std lib modules.

In terms of seamlessness, I can not confirm that it is exactly like having a python class, merely "fairly close". If you define a type, you can pass it to python, python can instantiate (with the typical way of Type() ) or even receive instances (if you define e.g. a constructor proc yourself). It can pass the instances back to nim to work with no problem (see e.g. quick example I whipped up: https://pastebin.com/v5wAqGxZ).

However, I have found that there are differences of a nim-type to a pythonclass:

1) In python you do not have direct access to the fields of an instance of a nim-type. You can access them via getters and setters, but you'll get runtime errors if you try to access them directly. To make that behave seamlessly you'd need to define a python wrapper class and hide stuff with @property decorators. Without such a wrapper class you could also not add a field to an instance of a nim-type like you could a normal python object.

2) An imported nim-type can not be inherited from in python (not sure if that works in C++, but at least it's a nim-python-interop limitation).

If you wanted to make a library in nim available in python that wasn't originally intended for the export, you'd likely also need to write a glue-layer in nim. The efffort there would consist mostly in copy pasting the proc signatures you want to make available and annotating them with the export-pragma, copy pasting the nim-type to make it inherit from the type needed for exporting and converting from the exported nim-type to the imported nim-type or vice-versa when jumping from python to nim or vice versa. Further, to hide the short-comings (that you can't inherit and that you don't have access to fields or can add fields) you'd need to wrap the nim-type in a python-class as described in 1).

My conclusion from what I heard from you so far and what I know of nimpy would be, that nimpy is 90% of the way there, workable but not as seamless, given that exported nim types and their instances aren't functioning exactly like python classes and their instances. Further the fact you'd need to wrap them in a Python class to hide that means, in comparison, extra work to C++ (though that may balance out with if the glue layer in C++ is more involved than the one in nim, I don't know).

Re: Why scientists are turning to Rust (2020)

#52
I know someone working on a materials science PhD. He might have to learn python. I could more easily recommend Rust if there were, say, different flavors of Rust, that allow learning the "hard stuff" in stages, but starting with one that uses garbage collection by default. Then, instead of learning python and maybe having to re-learn Rust later--I realize this is less likely, but still--to save time overall, he could learn the "intro level" of Rust now, and expand his Rust skills as need arises, without ever having to restart from scratch to learn a new language, new libraries, etc.

In other words, a step-by-step developer growth process from simple to hard, maybe 2-4 levels, governed by a Cargo.toml setting probably (comparable to a compiler switch), and you never have to throw away what you already learned. Like maybe "learn once, do anything".

(Yes, compatibility with peer group is probably a larger factor. But as an option for some where it fits.)

Re: Why scientists are turning to Rust (2020)

#53
post #52

I know someone working on a materials science PhD. He might have to learn python. I could more easily recommend Rust if there were, say, different flavors of Rust, that allow learning the "hard stuff" in stages, but starting with one that uses garbage collection by default. Then, instead of learning python and maybe having to re-learn Rust later--I realize this is less likely, but still--to save time overall, he coul…

Is the lack of GC that much of a showstopper for novice learners? If all they're writing is toy programs, they might as well use Rc and accept that cycles will leak.

Re: Why scientists are turning to Rust (2020)

#54
post #52

I know someone working on a materials science PhD. He might have to learn python. I could more easily recommend Rust if there were, say, different flavors of Rust, that allow learning the "hard stuff" in stages, but starting with one that uses garbage collection by default. Then, instead of learning python and maybe having to re-learn Rust later--I realize this is less likely, but still--to save time overall, he coul…

Is the lack of GC that much of a showstopper for novice learners? If all they're writing is toy programs, they might as well use Rc and accept that cycles will leak.

My general impression is that it is, for many. Rust definitely has a reputation for being harder to learn than Python, for example, which is what I'm suggesting be fixed for one "step" of Rust. The ownership, borrowing, and lifetimes are a hurdle for someone who is almost certainly not going to be a full-time programmer, but needs to program sometimes, and more than toy programs.

I think even Rc might be a barrier, because it looks like more complexity than Pythonistas expect.

Re: Why scientists are turning to Rust (2020)

#55

Yeah no, "scientists", this wonderful general category that means nothing and everything, in general, are not turning to Rust. Programming is a niche. Rust is a, albeit amazing and gaining traction at a fast pace, niche in this niche. 99% of mathematicians, physicists and biologists I have worked with have not even tried programming yet. And if they do, they will start with the stuff their friends are already using:…

Full agreement here. My past experience in the bioinformatics field taught me pretty much that "scientists" at large are just as afraid of the terminal as the average person. The science-folks more specialized on informatics typically are folks focusing on being able to use one language. Not use it well, mind you, just able to produce functional, untested code. Given that, I highly doubt any of them are even aware of…

Must be scientists out of school in the past 15 years with the remark about C and C++ being scary, since engineering and science curriculums in the 80s taught Fortran, C, and C++. 'Numerical Recipes: The Art of Scientific Programming', and books like it, were books I turned to do science or engineering. But, I guess you're right, since I learned to program in 1978 on a Commodore PET 2001, computer science and web development have made pushed friendlier languages like Python, Ruby, JavaScript, and so C, C++, and now Rust (I prefer SPARK2014 or Zig), are considered 'scary' for scientists. BLAS (Fortran) and CBLAS (C) are under the hood of all the dressed up Python code up front (Numpy -> CBLAS).

Real Scientists use assembler, C, and Frink! ;)

Sad to say the engineering firm I worked at for 6 years was filled with 20-something and 30-something engineers with only one of 15 of them able to code. Excel use, sure. Coding, no. It wasn't that way 25 years ago.

Post reply on HN