Live data from Hacker News

Rust – A hard decision pays off

pinecone.io

381–386 of 386 posts

Re: Rust – A hard decision pays off

#381

Earlier quoted context omitted.

> The unique safety features of Rus are all about memory safety, which is not something you have to worry about at all in Python Rust gets safety with its ownership system. The ownership system brings strong guarantees around who is mutating / reading any given object. Python has uncontrolled ownership. Any function can generally mutate / store any variable you pass in. This can definitely cause bugs if a rouge funct…

wrong, rust is about exclusive ptr access, nothing more. you cannot do ReadOnly in rust.

Why not? Isn't that &T like a read only wrapper of T?

Re: Rust – A hard decision pays off

#382
post #321
post #253

Earlier quoted context omitted.

I am curious which web framework do you use? Also do you use an ORM like diesel?

We use a mix of axum, and tonic/tower, depending on if the service is internal (grpc) or external (http). And no, we do not use an ORM like diesel, since we primarily use ScyllaDB. We wrote our own - it's very nice. We have a fully type-safe scylla/cassandra client, that does static validation of the queries (which we define as annotated structs), and also, when the service starts up, it validates that the schema tha…

Would love to see how your ORM compares with Catalytic, the Rust ORM for ScyllaDB.

https://www.scylladb.com/2022/02/15/introducing-catalytic-an...

Re: Rust – A hard decision pays off

#383

Earlier quoted context omitted.

I had the same experience with go, 100x performance improvements on data crunching scripts with roughly the same code. Worst part of writing it in python was simple misspellings in the last stages of the computation breaking things.

> Worst part of writing it in python was simple misspellings in the last stages of the computation breaking things. I'm not sure I understand. Was the typo in something like a dict key? Or did you add two of the wrong variables together? How did another language protect you from this? I fail to see how you couldn't also add two of the wrong variables (with the correct type) together in a different language.

Python (out of the box) will only complain about missing variables or methods at runtime.

Re: Rust – A hard decision pays off

#384
post #379

Earlier quoted context omitted.

Forgive me for asking instead of looking, I'm still getting into rust; why do you map instead of getting the result? path.extension().map(|ext| ext == "bundle").unwrap_or(false) vs (path.extension() == "bundle").unwrap_or(false) or further up .map(|e| e.map(|e| e.path())) vs .map(|e| e.path()) Is the .map keeping any value wrapped in an iterator so you can map again? I thought it was interesting what you wrote looks…

`extension()` gives you an `Option`, remember `Path` might not be a file or file could be without extension. Why not `((path.extension() == Some("bundle"))`? I don't know, it didn't work, and I didn't want to spend too much time on it. `read_dir` gives us an iterator over `Result `, so `e` in that map is a `Result` and not a `DirEntry`. It's two different "map" functions - on Option and Result it maps "T", but on Ite…

Thanks for the insight

Re: Rust – A hard decision pays off

#385

Earlier quoted context omitted.

Forgive me for asking instead of looking, I'm still getting into rust; why do you map instead of getting the result? path.extension().map(|ext| ext == "bundle").unwrap_or(false) vs (path.extension() == "bundle").unwrap_or(false) or further up .map(|e| e.map(|e| e.path())) vs .map(|e| e.path()) Is the .map keeping any value wrapped in an iterator so you can map again? I thought it was interesting what you wrote looks…

Not your parent, but I do know the answer. extension() returns an Option , because not every file has an extension https://doc.rust-lang.org/stable/std/path/struct.Path.html#m... map on option says "run this closure on the value if it's Some, or do nothing if it's None https://doc.rust-lang.org/stable/std/option/enum.Option.html... So after the map, we now have an Option . The unwrap_or method will say "give me the v…

Awesome thanks, I wasn't on a machine to play around with it at the time.

Re: Rust – A hard decision pays off

#386
post #381

Earlier quoted context omitted.

wrong, rust is about exclusive ptr access, nothing more. you cannot do ReadOnly in rust.

Why not? Isn't that &T like a read only wrapper of T?

try to do ReadOnly yourself, and then put Cell into it, or RwLock, or Mutex, or Atomic, or crossbeam channel, ...

it LOOKS like it's possible but it can be broken easily. again, because rust is not really about (i)mutability, it's about mem-safety - and all of those can be safely mutated with &T

Post reply on HN