4 ms·
From Julia to Rust (2021)
- tiffanyh 2y agoMaybe the worst TLDR ever :) Interesting post, even though I don’t understand “Why Rust” because all the reasons cited are not an issue with Julia (eg memory safety). This seems to not be about Julia at all. It just a post of a person who only knew Julia, and is now wanting to learn another language (which happens to be Rust)
- samatman 2y agoThat stood out to me as well. The collection of reasons given to prefer Rust to C happens to be completely compatible with preferring Julia to C as well. There's a different collection of reasons which wouldn't have that property (smol binary, suitable for realtime and embedded, etc), but it isn't the ones the author picked.
- miguelraz 2y agoAuthor here! Precisely, the most natural symbiosis for a Julia + Rust combo seems to fill a hard-realtime, critical safety or embedded niche with offline simulation. The Py03 and maturin story is something that we haven't brought to Julia yet and I'd love to have some time to work on a tighter integration story there. For example, getting a hot-reload with Revise.jl and a bindings generator that watches file changes and recompiles and the fly so that a Julia REPL gets updated with the new definitions would be so enviable. I haven't spoken to Tim Holy to see how to string that together but many of the pieces are there.
- ssivark 2y agoI don’t think it’s a case for switching from one to the other. It seems like an intro to rust from someone whose first language was Julia (which is used as the perspective to contrast with).
- nurettin 2y agoWow I thought it was only me. "Why did you switch?" shouldn't be answered by "this talk, that person's opinion and that powerpoint presentation"
- affinepplan 2y agoI don't think this is an article about switching. The author still uses Julia --- he has just learned Rust as well! This is an article about the learning experience and some notable differences and takeaways from the adventure into Rust.
- miguelraz 2y agoRight, back then there weren't as many Rust-inclined people in the Julia community and I felt like writing a trip report for my Julia friends. Now I've done a "From Julia to Rust" workshop at the latest JuliaCon and an accompanying survival guide, so that still ongoing work.
- ayhanfuat 2y agoThis is not about switching. He mentions his first language was Julia and he became interested in learning Rust. He answers that question and there is nothing wrong with someone getting interested in something by watching talks and getting inspired by people's opinions.
- acomjean 2y agoThere is a good list of Rust learning resources though… I’ll agree that it’s mostly about its like using Rust compared to Julia. It’s not very dismissive of Julia. The first paragraph lets you know what your in for.
- SkiFire13 2y ago> are not an issue with Julia (eg memory safety) Note that Julia does allow memory unsafety, for example you can mark array accesses with `@inbounds` to remove bound checks, kinda like how you can use `unsafe` in Rust except it looks much less scary. It also doesn't help that the official example for how to use it safe was actually not safe [1]. Granted, this is just a single example and has been fixed since then, but it doesn't give a nice impression of their mindset when dealing with memory safety. More in general there doesn't seem to be a strong mindset for correctness either. See [2] for a collection of such issues. [1]: https://github.com/JuliaLang/julia/issues/39367 https://github.com/JuliaLang/julia/issues/39367 [2]: https://yuri.is/not-julia/ https://yuri.is/not-julia/
- dist1ll 2y ago> For loops are not idiomatic in Rust That's not really the case. For loops are certainly less common compared to C, but they are completely fine to use. Forcing every loop into an iterator-chain style can sometimes be more confusing. Not to mention doing for-iterations with early exits. Yes, you can use try_fold, but if I'm not writing generic iterator library code, I'd prefer explicit for in cases like this. > writing Fortran-ey code instead of iterators will lead to pain and slower loops. No it won't. At least not in the general case. Not to mention that iterators also have performance footguns that are pretty easy to trigger.
- John23832 2y ago>That's not really the case. For loops are certainly less common compared to C, but they are completely fine to use. Forcing every loop into an iterator-chain style can quickly become an unreadable mess. There are no C style "for" loops in Rust: https://doc.rust-lang.org/reference/expressions/loop-expr.html https://doc.rust-lang.org/reference/expressions/loop-expr.ht... There is the "for" expression, but that does not give you a C-style "for" loop. It gives you something akin to a "foreach" you might see in Java, C#, Go, etc.
- steveklabnik 2y agoFrom the link: > A for expression extracts values from an iterator, looping until the iterator is empty. They look like this: for i in 1..10 { println!("{i}"); } And they're totally fine to use in Rust, I agree that the article is not exactly accurate here. EDIT: Okay you edited your comment to say this doesn't count. Sure. This is what the author of the post was talking about, though.
- John23832 2y agoI guess the statement >>That's not really the case. For loops are certainly less common compared to C, but they are completely fine to use. Forcing every loop into an iterator-chain style can quickly become an unreadable mess. Implies a C-style for loop, some sort of counting accumulator, and an update expression. That doesn't exist in rust. That's all I was saying. I know who you are, so I know I'm preaching to the preacher.
- exo-cortex 2y agoJust one thing (maybe the author reads this): The nicest way to avoid the "oh a lot of boilerplate!"-problem with implementing "Add" for a custom type is by using the "derive-more"-crate. Then you simply put a "#[derive(Add)" above your struct. That was the initial reason I switched to Rust myself: because I was writing a dynamical systems solver in C++ and had to overload arithmetic operators for my state-struct. But doing this was so complicated and I never felt sure of it performance wise (what if one side is a reference? And so on). In rust I have a macro and don't have to ever worry about that again.
- miguelraz 2y agoAuthor here! Oh, that's a neat crate, I'll check it out. I'd be interested to see if you have benchmarks of your dynamical systems solver in Rust vs the ones implemented in Julia. They've done great work!
- miguelraz 2y agoAuthor here! I have no idea why this blog is making the rounds again and I've learned a lot of Rust since, see my (badly benchmarked!) presentation at this year's Scientific Computing in Rust 2024: https://www.youtube.com/watch?v=bdsBhqKOe7A https://www.youtube.com/watch?v=bdsBhqKOe7A and a PR I sent in for the Rust compiler to speed it up for some low hanging fruit: https://github.com/rust-lang/rust/pull/110477 https://github.com/rust-lang/rust/pull/110477 I'll have to revisit this blog at some point and see what I should update, as well as a "From Rust to Julia" post for those that want to venture into that world as well.
- solarengineer 2y agoYou could edit your blog post to say what you’ve just said
- doodpants 2y agoPeeve of mine: blog posts that lack a date stamp. The only date appearing anywhere in the article is at the bottom, where it says "Last modified: August 29, 2024." So for all I knew it was a brand new post, until this comment. How old is it actually?
- lawtonnichols 2y agoThe blog post itself [1] as well as its modification history [2] are available on GitHub. Looks like it's from mid-2021. [1]: https://github.com/miguelraz/miguelraz.github.io/blob/master/blog/juliatorust.md https://github.com/miguelraz/miguelraz.github.io/blob/master... [2]: https://github.com/miguelraz/miguelraz.github.io/commits/master/blog/juliatorust.md https://github.com/miguelraz/miguelraz.github.io/commits/mas...
- deleted 2y ago[deleted]
- Decabytes 2y agoI'm still not understanding the switch to Rust other than for education (which is fine). All of the things you get from Rust with memory safety you get in Julia with the Garbage Collector?
- miguelraz 2y agoI didn't switch! At least for some scientific computing codes, but I did learn a lot of Rust along the way and extended my knowledge into (some) embedded and systems programming. Learning has been fun and the Rust people have been very friendly.
- bobbylarrybobby 2y agoI think there is one thing Rust can help you with that Julia doesn't which is race conditions. In Rust they're compiler errors, in Julia they just... happen?
- nritchie 2y agoI'm a physicist whose written substantial projects in both Julia and Rust (and C/C++/Object Pascal/Java/Python/...). I'm also a person who refactors frequently. While my mind was initially blown away by all the cleverness in Julia, I eventually found that for non-trivial packages the "time-to-first-X" became painful - way more painful than compiling Rust code (mostly with debug occasionally with --release). Plus the amazing generality of Julia code was both a blessing and a curse. Julia really needs interfaces to ensure that a duck really is a duck. In the end, I find Rust (despite/maybe because of) the picky compiler to be overall much more productive. With Rust, I find I can make major refactors, when the code compiles and my test code runs, I'm good to go. With Julia, months after I've refactored, I'm still finding footguns. I still use both but it is Rust that has my heart these days. Other thoughts: Developing Rust on Windows is painful but on Linux a joy. both cargo and Julia package managers are wonderful compared to other language alternatives.
- miguelraz 2y agoI'll agree on several counts (as a physicist too!): * Rust's tooling lets you have a base-floor of what is acceptable code that is much more palatable than non-top tier Julia codes. There's a world of difference opening a random crate's code in Rust that has been linted/clippy'd/check'd by the compiler rather than a random Julia package that a coworker/colleague just fired up. This tooling is getting better and better in Julia and I'd be interested to hear which Julia projects you worked on were really hampered by TTFX and refactoring woes. Hard agree on the footguns - I want the VSCode plugin to be better at detecting dead code, it cost me weeks on a project lately. * I'm also excited for some notion of interfaces to come to Julia. Perhaps it will be a 2.0 thing, but there's still lots of design stuff to figure out. * We have different understandings of "productive" for different focii then - I still find it painful to do the equivalent of `rand(1:10, (20, 20))` in Rust and I can get STEM people to be productive with Julia before you can even finishing saying "borrowchecker".
- yrlin 2y ago> ... I eventually found that for non-trivial packages the "time-to-first-X" became painful ... Have you checked the TTFX in 1.9+? It is significantly reduced for various packages e.g. Plots.jl.
- a-dub 2y agointeresting question: does it still make sense to have different or specialized languages for scientific computing vs generalized software engineering?
- miguelraz 2y agoNo clue! We'll see how they play out in time I guess.
- djhn 2y agoIt makes a lot of sense in fields where there are benefits to using code (instead of GUIs) to generate statistics and figures, as long as learning the basic syntax of the language to write this code can be done in a week or two. Learning just enough R (or Julia or Python) for the purposes of making replicable, easily updated, easily styled, easily adjusted tables and figures for research is something that a freshman in social sciences and humanities can handle. And for many academics that level of knowledge is enough for grad school and eventually even tenure. That level of knowledge will not necessarily include even the most rudimentary software engineering skills: the code will (most likely) live in a single long file. That file will contain both working chunks of code, old/broken/redundant chunks of code as well as comments and notes both related and unrelated to the task at hand. It will never be executable in a linear fashion (only chunks at a time in a REPL). And some data importing or package/library management will still have to be done through a GUI.
- a-dub 2y agoyou make an important point -- there's the choice and mechanics of a computer language (which is where i was thinking), and then the overall hci of the data analysis activity. should it look like software development or use of an (incredibly powerful) interactive calculator with dsls that are carefully designed to match the lingua franca of the fields they serve. (or, assuming possible, should the lingua franca move to a dsl and hci paradigm that is easier for humans and machines to reason about with minimized ambiguity?)
- hi-v-rocknroll 2y agoIn the "and Rust can be used for X" department: Add new builtins to Bash using a shared library (or .bundle on macOS) written in Rust. Bash also allows running bash other commands from native code. (There's a rust crate for creating bash builtins, but it doesn't currently compile on mac due to some improper and some missing linker flags.)
- djhn 2y agoReally enjoyed this article, even though I’ve only ever explored the basics of Julia. I’m always on the lookout for articles and guides that would help people with basic R, Julia and Python REPL skills to learn software engineering patterns, computer science basics or, especially in the case of R, more general purpose languages.
- miguelraz 2y agoAuthor here, that's great to hear! Well, if you're looking for good REPL resources, I just happened to have done a 3 hour Julia REPL Mastery for a previous JuliaCon. https://www.youtube.com/watch?v=bHLXEUt5KLc https://www.youtube.com/watch?v=bHLXEUt5KLc I should shrink this a more bite-sized version at some point.