7 ms·
This is great but I do wish that people could see Rust as more than a better C/C++. It's an amazing language for web services and CLIs. It's not just that it d
by insanitybit 3y ago
This is great but I do wish that people could see Rust as more than a better C/C++. It's an amazing language for web services and CLIs.
It's not just that it doesn't have a GC. It also doesn't have some of the worst features of OOP, it also has a sane std library, it also has an expressive type system, etc. Rust helps you write better code, even when compared to languages like Java or Python.
- CGamesPlay 3y agoI agree with this but the ownership model is really a huge learning curve for somebody who wants to make an application where it's OK if it crashes when there's a bug. It would be cool if there was a "relaxed rust" which provided interop with standard rust, but used some designated smart pointer for everything automatically (at the crate level, for example). I'm not sure how/if this could work, but I think it would make transitioning from GC languages -> Rust much easier.
- hgomersall 3y agoYou can more or less do this - just wrap everything in arc mutexes and clone everywhere (or use Rc for strictly single threaded). I'm sure someone will point out where it doesn't work but I suspect it would work fairly well but with obvious costs.
- CGamesPlay 3y agoExactly, but I'd like to see it done automatically (possibly via a special glyph enabled via crate config?), so that users of this "relaxed rust" don't have to think about ownership at all, but can still participate in the rest of the Rust ecosystem, and there's a clear "off-ramp" to standard rust.
- ssokolow 3y agoD tried that. The fact that so much of its ecosystem non-optionally depended on the optional garbage collection was part of what killed its chances for adoption beyond "like Java or C#, but without a giant corporation pushing for it".
- qaq 3y agoAny sign of async functions in traits without the macro? One kindah would expect first class async support for web services and honestly something like Swift prob. has better balance between usability and speed for most web services.
- hgomersall 3y agoYeah, it's expected this year: https://blog.rust-lang.org/inside-rust/2023/05/03/stabilizing-async-fn-in-trait.html https://blog.rust-lang.org/inside-rust/2023/05/03/stabilizin...
- qaq 3y agoasync fn do_health_check_par<HC>(hc: HC) where HC: HealthCheck + Send + 'static, HC::check(): Send, // <-- associated return type { tokio::task::spawn(async move { if !hc.check().await { log_health_check_failure().await; } }); } Hmm I think for 95% of the people sticking to something like Swift would work out better for them
- hgomersall 3y agoAre you saying 95% of use cases require spawning new tasks within the trait implementation based on argument futures? Or are you making a more general comment about rust generics? The MVP looks about as clean as I could hope for most use cases.
- qaq 3y agoI am saying that in web services you will frequently use async functions that look like async fn do_blah(db_repo: impl DBRepo ...) {...} and are executed on async-std or Tokio
- hgomersall 3y agoThat will work. It only needs the additional bounds if you want to spawn that as a new task.
- toyg 3y agoThe trade-off in complexity and loss of productivity (particularly at prototype time) are just not worth it.
- vgatherps 3y agoThis really depends on your use case for it, as all things - it’s hard to just make blanket statements like this
- toyg 3y agoOn par with "Rust helps you write better code" in the parent comment.
- insanitybit 3y agoNot at all. I added this context: > It also doesn't have some of the worst features of OOP, it also has a sane std library, it also has an expressive type system, etc. You made a baseless assertion, I at least gave examples of features/antifeatures that helped me draw my conclusion.
- maxbond 3y agoPersonally I regard Rust as strictly less complex than most other languages (to use - not to learn). The space of programs you're searching through is smaller and more constrained (there are fewer valid Rust programs then valid Python programs, and we can make stronger statements about the behavior of a valid Rust program). Ergo, simpler. Internalizing those constraints so they aren't generally slowing you down takes an investment however. Recently I had a vexing silent bug in a prototype, where I was intermingling strings and ints as keys in a dictionary, and thus not writing to the correct keys. Normally I would be more careful than that, but it was a quick and dirty proof of concept. Because this involved JSON deserialization, Python's modest static type checking couldn't catch it. That just wouldn't have happened in Rust. (But of course, I wouldn't have had the particular ML libraries I needed, either, so Python remains the best option for this project.)
- kaba0 3y agoIt’s as amazing for web services as C++. There might be some niche use case, but would not be my first, nor second choice there. It is still a low-level language, and while it is expressive, that doesn’t stop the low-level constructs from leaking to high level abstractions — which is not a negative in itself, that’s the purpose of the language. It’s just a hard tradeoff when it comes to anything not needing low level considerations.
- junon 3y agoAnecdotally, async Tide (an HTTP framework for rust) outperforms any other HTTP framework or library I've ever used in the C/C++ space, including H2O. Pair that with minimal memory issues with Rust, and guaranteed none if the framework avoids unsafe blocks.
- insanitybit 3y agoWhat's low level about Rust is that memory operations are exposed somewhat. So you don't just have copies or automatic memory management, you have pointers. It's not really that hard, and actually it's wayyyy easier to understand than a lot of the weird reference rules in other languages. For example, lots of people trip on `append` in Go because it tries to hide pointer semantics. Having to write `&` sometimes is just not burdensome and it's frankly sad that so many professional developers, many with so-called computer science degrees, seem to think that a basic understanding of computers is too high a burden.
- pharmakom 3y agoAll true but it’s not as productive as a GC language from the ML family. If you don’t need the performance / latency guarantees I’m not sure it’s worth it.
- flooow 3y agoThe way I have seen it explained before: Rust is not the perfect applications language, but there actually aren't any good mainstream applications languages out there, so Rust is perhaps the best we've got. What I want: * Powerful, strict typesystem (typeclasses, sum types, type-inference, closures) * Constrained mutation, no 'spooky action at a distance' * Safe multithreading * Fast * Memory-safe * Native binaries * Large, deep ecosystem * Great tooling * Jobs Rust comes closer than most.
- kaba0 3y agoFunnily enough, Haskell also fulfills all the listed qualities.
- codethief 3y agoHow many jobs are out there where they expect you to know Haskell?
- pjmlp 3y agoMore than for Rust, given its age.
- flooow 3y agoNot sure that this is true now, but willing to bet my career that this won't be true in 3 years.
- pjmlp 3y agoDepends on how much people feel like writing userspace code with the usability of a language designed for kernel, drivers and GPPGU programming. https://wiki.haskell.org/Haskell_in_industry https://wiki.haskell.org/Haskell_in_industry
- pkolaczk 3y agoRust can have some bad effects on your brains. I noticed I can't read Java code as easily as before. E.g. yesterday I had to read it multiple times before I understood what was going on and why they are calling setters on an item that goes out of scope: List<Something> list = ...; for (...) { Something item = new Something(); list.add(item); item.setFoo(...); item.setBar(...); }
- amclennon 3y agoWould you say...your Java is getting rusty?
- jszymborski 3y agoHaha I think that's just normal slow context-switching. I always start writing semi-colons in python after writing PHP for too long.