News for hackers. Stuff that matters.
Re:Was Rust Worth It? by goku12 on Thursday October 26, 2023 @12:17AM (#38021544)
> but the ergonomic is really bad. Every time I write some rust I feel limited.

> But I do not think it is a good general purpose language.

Remember that this is not a sentiment that's shared by everyone. I use Rust for tasks that need anything more complicated than a shell script. Even my window manager is controlled from a Rust program. I say this as someone who has been programming in Python for nearly two decades now. At this point, I'm about as fast in Rust as I am in Python.

Re:Was Rust Worth It? by lumost on Thursday October 26, 2023 @01:01AM (#38021782)
I tried to get into rust for many years, I'm now in a C/CPP job (after Java/Python/Ruby and other gigs). What I've come to understand is that Rust's lifetime model is very difficult to work with whenever you have a cyclic reference. In C/CPP the same holds, but you deal with it through clever coding - or ignoring the problem and cleaning up memory later. Java, and other GC'd languages just work for these structures.

While the Rust devs believe such cyclic references are rare - I think this speaks mostly to the problem domain they are focused on. Relational models are everywhere in Apps, they are often common in complex systems software like databases, and they are fairly rare in firmware/drivers/system code code.

There are a few patterns for dealing with cyclic references, but they all end up requiring either unsafe or a main "owner" object which you clean up occassionally (effectively arena allocation). Having now worked in C/CPP - the idea of having unsafe blocks sprinkled around the code doesn't bother me, and many C/CPP components have some form of arena allocation built-in. I just wish Rust learning resources would be more upfront about this.

Re:Was Rust Worth It? by lifthrasiir on Thursday October 26, 2023 @01:36AM (#38022005)
> Relational models are everywhere in Apps, they are often common in complex systems software like databases, and they are fairly rare in firmware/drivers/system code code.

It's not like that you can't write relational models in the safe Rust. The only forbidden thing is a reference pointing arbitrary memory, which is typically worked around via indices and often more performant in that way. It is much rarer to find applications that need an absolutely random pointer that can't be hidden in abstractions in my opinion.

Re:Was Rust Worth It? by goku12 on Thursday October 26, 2023 @01:15AM (#38021859)
> I just wish Rust learning resources would be more upfront about this.

While beginner resources don't dwell too much upon cyclic references, they don't consider unsafe blocks as unusual. All the material I've seen say that there are certain domains where Rust's compile-time safety model simply won't work. What Rust allows you to do instead, is to limit the scope of unsafe blocks. However, the beginner material often won't give you too much details on how to analyze and decide on these compromises.

Anyway, compile-time safety checks (using borrow checker) and manual safety checks (using unsafe) aren't the only way to deal with safety. Cyclic references can be dealt with runtime safety checks too - like Rc and Weak.

Re:Was Rust Worth It? by mtsr on Thursday October 26, 2023 @02:50AM (#38022516)
> Cyclic references can be dealt with runtime safety checks too - like Rc and Weak.

Indeed. Starting out with code sprinkled with Rc, Weak, RefCell, etc is perfectly fine and performance will probably not be worse than in any other safe languages. And if you do this, Rust is pretty close to those languages in ease of use for what are otherwise complex topics in Rust.

A good reference for different approaches is Learn Rust With Entirely Too Many Linked Lists https://rust-unofficial.github.io/too-many-lists/

Re:Was Rust Worth It? by pncnmnp on Thursday October 26, 2023 @03:33AM (#38022803)
Also, take a look at GhostCell (https://plv.mpi-sws.org/rustbelt/ghostcell/ and https://www.youtube.com/watch?v=jIbubw86p0M). If anyone's used this in a project or production environment, I'd love to hear your firsthand experiences and insights.
Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @04:45AM (#38023248)
Except in those other languages the compiler types .clone() for me.
Re:Was Rust Worth It? by chalsprhebaodu on Thursday October 26, 2023 @07:14AM (#38024076)
Sometimes the compiler types clone for you even you don’t actually want it to.
Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @08:19AM (#38024549)
It is easier to tell it, "don't do it this time" than all the time.

It is no accident that while Val/Hylo, Chapel and Swift have taken inspiration from Rust, they have decided to not inflict the affine types directly into the language users, rather let the compiler do part of the work itself.

Re:Was Rust Worth It? by lumost on Friday October 27, 2023 @04:34PM (#38043549)
You still need a main owner in those patterns, that owner must be part of a DAG of owners - you cannot have cyclic ownership.
Re:Was Rust Worth It? by mjevans on Thursday October 26, 2023 @01:54AM (#38022119)
What's a frequently encountered case for such cyclic loops? Without details I'm drawn to trying to break the cycle, either by promoting the shared state to a container object for the set, or by breaking it out into it's own object that multiple things can point at.
Re:Was Rust Worth It? by rurban on Thursday October 26, 2023 @02:12AM (#38022267)
a parent field.

a doubly linked list

Re:Was Rust Worth It? by littlestymaar on Thursday October 26, 2023 @03:55AM (#38022945)
Doubly-linked list is something you have almost no reason to ever write.

Parent field is something where you have a clear hierarchy (it's not really “cyclic”, so it's the perfect use-case for weak references).

When coming from a managed-memory language, this obviously requires some conceptual effort to understand why this is a problem at all and how to deal with it, but when compared to C or C++, the situation is much better in Rust.

Re:Was Rust Worth It? by jacobgorm on Thursday October 26, 2023 @04:54AM (#38023302)
Also, a parent field is something you should be able to infer, e.g, keep a stack of parents as you traverse down a search tree following the child pointers, instead of storing parent pointers in the tree nodes.
Re:Was Rust Worth It? by akoboldfrying on Thursday October 26, 2023 @05:16AM (#38023428)
That's assuming you traverse the tree down from the root each time. Often you do, but there are cases where you don't -- e.g., if your goal is to determine the lowest common ancestor of two given nodes.
Re:Was Rust Worth It? by tialaramex on Thursday October 26, 2023 @04:46AM (#38023257)
Your parent said "frequently encountered" and while it's probably true that doubly linked lists may be "frequently encountered" in some people's code they're usually a bad idea and "don't use a list here" is often the right fix, not "conjure a way to make that safe in Rust".

It's very noticeable how often people who "need" a linked list actually only wanted a queue (thus Rust's VecDeque) or even a growable array (ie Vec).

Aria has a long list of excuses people offer for their linked lists, as well as her discussion of the time before Rust 1.0 when she sent lots of Rust's standard library collections to that farm up-state but wasn't able to send LinkedList.

https://rust-unofficial.github.io/too-many-lists/

Re:Was Rust Worth It? by solomonb on Thursday October 26, 2023 @02:06AM (#38022202)
ASTs
Re:Was Rust Worth It? by mjevans on Thursday October 26, 2023 @02:41AM (#38022459)
An Abstract Syntax Tree / or Double-Linked List both qualify, but they're also a lower level implementation detail than I'd expect to frequently interact with in a reference safety focused language.

I've still been meaning to write something in / learn Rust's ways of thinking; is there not an intended replacement for these data structures? Or do they expect it all to go under Unsafe?

Re:Was Rust Worth It? by littlestymaar on Thursday October 26, 2023 @04:05AM (#38022999)
> is there not an intended replacement for these data structures? Or do they expect it all to go under Unsafe?

For linked-lists, there's one in std and the majority of people should never have to write their own as it's error prone and requires unsafe.

For graph use-case then you can either use ECS, arena, ref counting or unsafe, but you're probably better off using/developing a dedicated crate that optimizes it and abstract it away behind an easy to use (and safe) interface.

Re:Was Rust Worth It? by lumost on Friday October 27, 2023 @04:45PM (#38043688)
The one in std uses unsafe. My main concern with learning rust is that you can spend ages trying to learn “the right way” of doing things in rust, when the right way really is to use unsafe.
Re:Was Rust Worth It? by littlestymaar on Saturday October 28, 2023 @02:45PM (#38052335)
No, the right way is to use unsafe primitives that have been tested, audited or even formally proven (like the ones in std).

Sometimes such a primitive doesn't exist and you should use unsafe yourself, but then you're the one supposed to make sure that your code is in fact sound. If you keep unsafe for small portions of the code you can reason about and extensively test so Miri gives you a good level of confidence, then it's fine to use unsafe. But it's the more expensive option, not the default.

Re:Was Rust Worth It? by lifthrasiir on Thursday October 26, 2023 @02:14AM (#38022275)
ASTs are one of "nicely behaving" data structures. It is like a archetype of abstract data types pervasive in functional programming languages.
Re:Was Rust Worth It? by SkiFire13 on Thursday October 26, 2023 @03:26AM (#38022747)
An abstract syntax tree can't have cycles by definition.
Re:Was Rust Worth It? by foldr on Thursday October 26, 2023 @03:52AM (#38022925)
Technically true, but sometimes you want parent pointers. You then have a more general graph in the underlying representation, but it still represents a tree structure.
Re:Was Rust Worth It? by lumost on Friday October 27, 2023 @04:43PM (#38043665)
Same shows up in Postgres Query* struct for SQL. Copying memory between parser, planner, execution would be too expensive in large queries - so instead you have an arena allocated representation.
Re:Was Rust Worth It? by mordae on Thursday October 26, 2023 @05:27AM (#38023488)
You usually solve this by using a traversal helper that keeps the stack and next/prev for you without storing them inside the AST explicitly.
Re:Was Rust Worth It? by oconnor663 on Thursday October 26, 2023 @09:48AM (#38025483)
I think a game is a good example, or anything that's kind of like a game in that it's modeling a world that's changing over time. Objects come and go, and they "target" each other or "require" each other or whatever sort of relationships the program wants to express. Those relationships end up forming a graph that might contain cycles.

I just put up a blog post about this actually :) https://jacko.io/object_soup.html

> promoting the shared state to a container object for the set

Yeah I think that's a good way to describe these "ECS-ish" patterns.

Re:Was Rust Worth It? by worik on Thursday October 26, 2023 @05:38AM (#38023555)
> While the Rust devs believe such cyclic references are rare -

They are.

I have not had to use cyclic references ever, except once doing experiments with fully connected graphs, that was very unusual

If you're doing a lot cyclic references Rust is not the right choice. Horses for courses

But are you sure you're using the best algorithm?

Re:Was Rust Worth It? by jcelerier on Thursday October 26, 2023 @08:35AM (#38024697)
Maybe for you it's unusual - in my previous work all the apps contained graphs, and I just joined a company where almost all the apps also contain graphs
Re:Was Rust Worth It? by underdeserver on Thursday October 26, 2023 @09:12AM (#38025058)
I don't write Rust, but I never understood why graphs meant you need circular references.

Doesn't it just come down to the question of who owns the node?

If it's a tree, and parents are never removed before children, just make the child owned by the parent and keep a weak reference to the parent.

If it's a general graph, and vertices can exist or not exist regardless of edges, keep a list of them independent of the edges, and keep weak references in the edges.

If it's a graph where a one or a few roots exist, and nodes exist as long as there's a path from a root node to them, that sounds like a classic use case for Rc<>.

Is there a common use case I'm missing?

Re:Was Rust Worth It? by lumost on Friday October 27, 2023 @04:38PM (#38043610)
Things get tricky when you have a valid triangular relationship amongst equal objects. This comes up far more often than you’d expect.
Re:Was Rust Worth It? by underdeserver on Sunday October 29, 2023 @12:33AM (#38055823)
Can you give an example?
Re:Was Rust Worth It? by zabzonk on Thursday October 26, 2023 @05:45AM (#38023581)
to be a bit pedantic, i assume the language you a referring to as CPP is actualy C++? cpp to me means the c (and c++) preprocessor.
Re:Was Rust Worth It? by oconnor663 on Thursday October 26, 2023 @09:23AM (#38025182)
Oh I just put up a blog post about this on Monday :)

https://jacko.io/object_soup.html

Agreed that I wish more beginner Rust books had a section about this. The pattern is quite simple, but it's hard for beginners who get stuck to realize that they need it.

Re:Was Rust Worth It? by strokirk on Saturday October 28, 2023 @07:38AM (#38049028)
I would have needed this when I started learning Rust! All my early programs were object soups.
Re:Was Rust Worth It? by hiAndrewQuinn on Thursday October 26, 2023 @02:31AM (#38022386)
I've finally set my mind to properly learning a new language after Python, Haskell, and typescript. I'm looking into Rust especially because of how I've heard it interoperates with Python (and also because it's maybe being used in the Linux kernel? Is that correct?).
Re:Was Rust Worth It? by PartiallyTyped on Thursday October 26, 2023 @02:33AM (#38022405)
Linux kernel has support for rust userland drivers, and rust interops with python with pyo3.
Re:Was Rust Worth It? by maccam94 on Thursday October 26, 2023 @03:25AM (#38022734)
Not sure what you mean by "userland" drivers here, but support for kernel modules written in rust is actively being developed. It's already being used for kernel drivers like the Asahi Linux GPU driver for M1 Macs.
Re:Was Rust Worth It? by PartiallyTyped on Thursday October 26, 2023 @03:34AM (#38022807)
I am referring to userspace / userland drivers.

https://www.kernel.org/doc/html/v4.18/driver-api/uio-howto.h...

Re:Was Rust Worth It? by tremon on Thursday October 26, 2023 @01:18PM (#38028709)
But you can write userspace drivers in any language, as long as that language has basic file I/O and mmap() support. There's nothing special about using Rust for userspace drivers.
Re:Was Rust Worth It? by TylerE on Thursday October 26, 2023 @10:50PM (#38034137)
Isn't this false? Don't certain languages basically need, say, a libc that isn't nessesarily available in kernel space?
Re:Was Rust Worth It? by tinco on Thursday October 26, 2023 @03:39AM (#38022847)
Rust is an excellent follow up to those languages. It's got many influences from Haskell, but is designed to solve for a very different task that's not yet in your repertoire so you'll learn a ton.

And yes the Python interop is excellent.

Re:Was Rust Worth It? by hiAndrewQuinn on Thursday October 26, 2023 @04:54AM (#38023299)
I'm sold, thank you. Yes, it felt like a great "missing quadrant" to my generalist skillset.
Re:Was Rust Worth It? by PartiallyTyped on Thursday October 26, 2023 @02:32AM (#38022397)
Surprisingly, I am faster in Rust than any other language. Something about my prior experiences just made it click just the right way. I don't want to program in anything else anymore. I don't want to deal with obscure C++ error messages, C footguns and lack of ergonomics, I don't want to deal with abstraction hell of Java, or the poor person's typing that python has.

I have been programming in Python for the past 6 years, I know all sorts of obscure details, and with rust, I just don't need to think about all of those issues.

Re:Was Rust Worth It? by goku12 on Thursday October 26, 2023 @04:15AM (#38023065)
> Surprisingly, I am faster in Rust than any other language.

Not really surprising, given that you have C and C++ background. That's what I was trying to highlight. Rust isn't a confusing or unproductive language as many project it to be - if you have the conceptual understanding of what happens on the hardware. Especially about stack frames and RAII. If you know those, the borrow checker complaints will immediately make sense and you will know how to resolve them.

Add rust-analyzer (Rust's language server) to it, you get real-time type annotations and a way to match types correctly in the first attempt. In my experience Rust also helps structure your program correctly and saves a ton of time in debugging. All in all, Rust is a fast way to write correct programs.

Re:Was Rust Worth It? by PartiallyTyped on Thursday October 26, 2023 @04:30AM (#38023157)
I'd add that if you have some understanding of how memory ownership should be such that you don't end up with memory leaks, you are fine. The borrow checker just verifies that your mental model is correct, and removes some of the cognitive load from you.
Re:Was Rust Worth It? by ayewo on Thursday October 26, 2023 @09:10AM (#38025031)
> if you have some understanding of how memory ownership

What reading materials will help me level up my understanding of this?

Re:Was Rust Worth It? by caskstrength on Thursday October 26, 2023 @06:30AM (#38023817)
> Rust isn't a confusing or unproductive language as many project it to be - if you have the conceptual understanding of what happens on the hardware. Especially about stack frames and RAII. If you know those, the borrow checker complaints will immediately make sense and you will know how to resolve them.

I have reasonable understanding of "what happens on the hardware" (been writing kernel code for years), know modern C++ (with RAII and stuff) and Rust is confusing and unproductive language for me.

Re:Was Rust Worth It? by mst on Thursday October 26, 2023 @10:02AM (#38025704)
I get the feeling that learning rust can be a "bang your head against it until you get an 'aha' moment" sort of affair, much like learning git.

Some people pick up rust quickly because it clicks into their brain early, some take longer or end up bouncing off.

Re:Was Rust Worth It? by goku12 on Thursday October 26, 2023 @11:00AM (#38026472)
I had university courses on computer architecture and assembly, even before I took up Python as a hobby. I did have a little C experience before that. My entire perspective on Rust type system from day 1 (back in 2013, before Rust 1.0) was based on the hardware (primarily stack frames) and problems I had with assembly and C. There was never a point where the borrow checker didn't make sense. This is why I insist that Rust isn't hard to understand if you learn the hardware on which it runs.

Back then, people were debating the design decisions that led to the borrow checker, in public for everyone to see (on Reddit and IRC). They were trying to avoid memory safety issues in Firefox and Servo. They were even a bit surprised to discover that the borrow checker solved many concurrency bugs as well.

Re:Was Rust Worth It? by PartiallyTyped on Thursday October 26, 2023 @11:34AM (#38026961)
I took a different route to Goku (other commenter), I used to write a lot of C and C++ in university, did everything there, up until 2018-ish, I got a bit into rust and things just clicked, my understanding of memory was just not that good enough, and then my C skills skyrocketed as a consequence of learning proper memory management.

Then I got into Haskell, and functional programming, that made thinking about traits, immutability, and all functional aspects a breeze.

Then finally, I got into rust again, use it at work and personal projects. Somehow I managed to rewrite a project that took me 4 months in Python in about 4 days. It was faster, more robust, cleaner, and I could sleep at night.

Re:Was Rust Worth It? by mcronce on Monday October 30, 2023 @09:47AM (#38069419)
My background is PHP, Python, and Go, and I have the same experience as GP
Re:Was Rust Worth It? by pizza234 on Thursday October 26, 2023 @04:52AM (#38023287)
> At this point, I'm about as fast in Rust as I am in Python.

This is factually impossible.

For anything larger than (very) small programs, Rust requires an upfront design stage, due to ownership, that it's not required when developing in GC'ed languages.

This is not even considering more local complexities, like data structures with cyclical references.

Re:Was Rust Worth It? by goku12 on Thursday October 26, 2023 @05:08AM (#38023388)
> This is factually impossible.

How do you outright deny something as subjective as my personal experience? Besides, I'm not the only one in this discussion that made the same opinion.

> For anything larger than (very) small programs, Rust requires an upfront design stage, due to ownership, that it's not required when developing in GC'ed languages.

While GC'ed languages allow you to skip a proper initial design stage, it's a stretch to claim that it's not required at all. In my experience using Python, while the initial stages are smooth, such design oversights come back and bite at a later stage - leading to a lot of debugging and refactoring. This is one aspect where Rust saves you time.

> This is not even considering more local complexities, like data structures with cyclical references.

I'm not going to dwell on cyclical references, since there's another thread that addresses it. They point out a way to make it as easy in Rust as it is in GC'ed languages.

Meanwhile, the upfront architecture and data structure design isn't as complicated as you project it. Rust is mostly transparent about those - even compared Python. How well do you understand how Python manages Lists, dictionaries or even objects in general? I often find myself thinking about it a lot when programming in Python. While you need to think upfront about these in Rust, there's actually less cognitive overhead as to what is happening behind the scenes.

Re:Was Rust Worth It? by Ylmaz on Thursday October 26, 2023 @08:52AM (#38024846)
This is possible if you are really slow in python
Re:Was Rust Worth It? by ParetoOptimal on Thursday October 26, 2023 @09:58PM (#38033831)
Or maybe they mean "fast to 1.0" rather than "fast to 0.1"?

They didn't specify.

Re:Was Rust Worth It? by steinuil on Thursday October 26, 2023 @05:27AM (#38023491)
That is also not shared by everyone. If you have written enough Rust to have internalized designing for the borrow checker, you don't have to spend much time in a design phase.

The only time I find I have to "fight the compiler" is when I write concurrent code, and you can sidestep a lot of issues by starting with immutable data and message passing through channels as a primitive. It's a style you have to get used to, but once you build up a mental library of patterns you can reasonably be as fast in Rust as you are in Python.

Re:Was Rust Worth It? by raincole on Thursday October 26, 2023 @05:09AM (#38023397)
Of course it's possible. You just need to write Python very slowly :)
Re:Was Rust Worth It? by actionfromafar on Thursday October 26, 2023 @06:23AM (#38023781)
Everyone has their breaking point. I start to write Python very slowly around after 10k lines or so. Can't remember where I put stuff...
Re:Was Rust Worth It? by pg_1234 on Thursday October 26, 2023 @05:47AM (#38023590)
> For anything larger than (very) small programs, Rust requires an upfront design stage, due to ownership, that it's not required when developing in GC'ed languages.

Every language requires this (if you want robust code), most just let you skip it upfront ... but you pay dearly for doing so later.

Re:Was Rust Worth It? by api on Thursday October 26, 2023 @06:28AM (#38023810)
I have to second the OP: ownership isn’t that hard. I just get used to structuring a program in certain ways. Having written a lot of C++ helps because the things Rust won’t let you do are often unsafe or a source of leaks and bugs in C++.

Having an editor with rust-analyzer running is massively helpful too since ownership issues get highlighted very quickly. I can’t imagine dealing with any language larger than C without a smart editor. It can be done but why?

I still find async annoying though.

My biggest source of friction with Rust (other than async) is figuring out how to write code that is both very high performance and modular. I end up using a lot of generics and it gets verbose.

Re:Was Rust Worth It? by mejutoco on Thursday October 26, 2023 @06:32AM (#38023826)
Couldn't one use Arc and similar boxed types to avoid thinking about memory until later?
Re:Was Rust Worth It? by TylerE on Thursday October 26, 2023 @10:49PM (#38034132)
Why not just something like nim and that point, and straight up ditch 90% of the complexity?
Re:Was Rust Worth It? by mejutoco on Friday October 27, 2023 @09:42AM (#38038316)
I was answering to this other user:

> This is factually impossible.

> For anything larger than (very) small programs, Rust requires an upfront design stage, due to ownership, that it's not required when developing in GC'ed languages.

It seems that is not factually impossible.

Now, answering your question: It could be useful to use boxed types and later optimize it, so you get the benefits of rust (memory safety, zero cost abstractions) later, without getting the problems upfront when prototyping.

Re:Was Rust Worth It? by avgcorrection on Thursday October 26, 2023 @06:46AM (#38023906)
> This is factually impossible.

No it isn’t Both languages comprise much more than their memory management handling. Even if your premise is true, the conclusion does not follow.

Re:Was Rust Worth It? by bmacho on Thursday October 26, 2023 @06:52AM (#38023942)
> This is factually impossible.

Factually it's not. It may be true that in a very very idealized thought-experiment, when someone has a perfect knowledge, never makes mistakes, doesn't have preferences, can type arbitrary fast etc, python needs fewer keystrokes, fewer keywords or such, thus is faster. Who knows. But in reality none of the assumptions above hold, also literally everything plays a much bigger role in development speed anyway.

Re:Was Rust Worth It? by Ar-Curunir on Thursday October 26, 2023 @07:11AM (#38024050)
I mean, it’s easily the same for me. I am way more productive in Rust because I know it very well, and with Python I’m debugging all kind of gotchas.
Re:Was Rust Worth It? by persnickety on Thursday October 26, 2023 @08:22AM (#38024583)
> For anything larger than (very) small programs, Rust requires an upfront design stage, due to ownership, that it's not required when developing in GC'ed languages.

It's nearly the opposite. For larger programs in Python, you need an upfront design stage because the lack of static typing will allow you to organically accrete classes whose job overlap but interfaces differ.

Meanwhile, Rust will smack you over the head until your interfaces (traits) are well-organized, before the program grows enough for this to become a problem (or until you give up and start over).

How do I know? I'm stuck with some larger Python programs that became a mess of similar-but-not-interchangeable classes. RiiR, if I ever have the time.

Re:Was Rust Worth It? by chrisweekly on Thursday October 26, 2023 @08:37AM (#38024714)
RiiR: Rewrite it in Rust
Re:Was Rust Worth It? by robertlagrant on Thursday October 26, 2023 @09:32AM (#38025277)
> For larger programs in Python, you need an upfront design stage because the lack of static typing will allow you to organically accrete classes whose job overlap but interfaces differ.

You can also install pre-commit and mypy, and have static typing.

Re:Was Rust Worth It? by goku12 on Thursday October 26, 2023 @10:24AM (#38026006)
That's the entire point we're making. Rust's type system forces you to deal with the problem early on and saves time towards the end. It's not like that's impossible with Python with addons like mypy. But Rust's type system goes beyond just data types - lifetimes are also a part of the type system. I don't know how you can tack that on to Python.
Re:Was Rust Worth It? by robertlagrant on Thursday October 26, 2023 @11:26AM (#38026848)
> Rust's type system forces you to deal with the problem early on and saves time towards the end. It's not like that's impossible with Python with addons like mypy.

Definitely not - mypy's pretty good these days, and lots of people use it.

> But Rust's type system goes beyond just data types - lifetimes are also a part of the type system. I don't know how you can tack that on to Python.

Well, Python's objects are generally garbage collected rather than explicitly destroyed, so I don't think it'd make sense to have lifetimes? They don't seem a correctness thing in the same way that types do.

Re:Was Rust Worth It? by awused on Thursday October 26, 2023 @01:26PM (#38028813)
Lifetimes and borrowing are very much a correctness thing and aren't just for tracking when memory is freed. While you won't have use-after-free issues in a GCed language, you will still have all the other problems of concurrent modification (data races) that they prevent. This is true even in single-threaded code, with problems like iterator invalidation.
Re:Was Rust Worth It? by tene on Thursday October 26, 2023 @02:18PM (#38029624)
Lifetime analysis matters a lot for way more than just garbage collection.

File handles, iterators, mutex guards, database transaction handles, session types, scoped threads, anything where ordering or mutual exclusivity matters.

Re:Was Rust Worth It? by robertlagrant on Thursday October 26, 2023 @03:49PM (#38030843)
I don't know about all of those, but Python's context managers and built in constructs handle most of those, I think?
Re:Was Rust Worth It? by Too on Saturday October 28, 2023 @08:08AM (#38049198)
Only in the most basic cases. If your handle has to be passed into another function or outlive the current scope of your function, the guardrails end.
Re:Was Rust Worth It? by mcronce on Monday October 30, 2023 @02:28PM (#38073618)
Mutability is a big one for correctness. In Python, any function you pass any (non-primitive) object to might be mutated right out from under you and you have no idea it's happening. In Rust, you have to explicitly provide mutable references, or you need to hand over ownership, in which case you don't care if the callee mutates its argument, because you no longer have access to it.
Re:Was Rust Worth It? by linza on Thursday October 26, 2023 @08:33AM (#38024680)
I think this is a very valuable comment, and the replies don't do it justice.

I strongly agree from my own and my peers experience with the sentiment that latency from zero to running code is just higher in Rust than Python or Go. Obviously there are smart people around and they can compensate a lot with experience.

Re:Was Rust Worth It? by thecodedmessage on Thursday October 26, 2023 @08:51AM (#38024833)
You know what slows me down in Python? The fact that you need to actually go down a code path to make sure you’ve spelled everything right.

But nothing that Rust does slows me down because I’m used to it.

Re:Was Rust Worth It? by sp0ck on Thursday October 26, 2023 @09:08AM (#38025007)
I disagree. I have similar observation. With modern editors and Language Server that are giving immediate feedback writing strongly typed languages doesn't differ than writing python.
Re:Was Rust Worth It? by awused on Thursday October 26, 2023 @01:40PM (#38029037)
Honestly I found myself coding very much the same way in Rust as I did in Python and Go, which were my go-to hobby languages before. But instead of "this lock guards these fields" comments, the type system handles it. Ownership as a concept is something you need to follow in any language, otherwise you get problems like iterator invalidation, so it really shouldn't require an up-front architectural planning phase. Even for cyclic graphs, the biggest choice is whether you allow yourself to use a bit of unsafe for ergonomics or not.

Having a robust type system actually makes refactors a lot easier, so I have less up-front planning with Rust. My personal projects tend to creep up in scope over time, especially since I'm almost always doing something new in a domain I've not worked in. Whenever I've decided to change or redo a core design decision in Python or Go, it has always been a massive pain and usually "ends" with me finding edge cases in runtime crashes days or weeks later. When I've changed my mind in Rust it has, generally, ended once I get it building, and a few times I've had simple crashes from not dropping RefCell Refs.

Re:Was Rust Worth It? by julianeon on Saturday November 04, 2023 @11:34AM (#38141986)
I would flip this around.

If you are only writing small programs where perf doesn't matter, crashing doesn't matter, design doesn't matter - Python will be faster than Rust, because the only thing that matters is how you can write the code from 0 to "done". You can jump right in, the design stage is superfluous & unnecessary. There is nothing to optimize, the default is good enough.

If you are doing slightly more than that, Python and Rust become about even, and the more you need those things, the better Rust becomes.

Re:Was Rust Worth It? by Liskni_si on Thursday October 26, 2023 @07:43AM (#38024285)
What window manager is that, may I ask out of curiousity?
Re:Was Rust Worth It? by goku12 on Thursday October 26, 2023 @08:05AM (#38024439)
Sway. And river, sooner or later. A single Rust program is used for setting up services (using s6-rc on Gentoo), shutdown, reboot, idle inhibit, etc.
Re:Was Rust Worth It? by JohnFen on Thursday October 26, 2023 @10:52AM (#38026365)
It's interesting that you bring up Python. I find Rust unpleasant to program in -- and I also find Python unpleasant to program in.

Now I'm wondering about demographics. Are people who love Python more likely to love Rust as well?