News for hackers. Stuff that matters.
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.