Earlier quoted context omitted.
It took me two hours to compile the esp32 fork of rustc on a 2015 macbook pro. Not ideal, but it works just fine.
That's very interesting! Do you have any pointers on how to do that?
Rust is for Professionals
121–130 of 157 posts
Re: Rust is for Professionals
#122Earlier quoted context omitted.
Do you have a specific language in mind? Honestly, I don't feel that I spend time managing memory in Rust: I use ARC pointers for long-lived shared object (Database connections pool, mailer...) and otherwise the ownership is pretty straightforward during the lifecycle of a request, data is moved from the top layer (HTTP handlers) to the bottom (Repositories to access Database) and back for the response.
> I use ARC pointers for long-lived shared object (Database connections pool, mailer...) Does that mean you basically enforce sequential database reads? Seems like a bottleneck if your server is concurrent
If they're sharing a connection pool then each HTTP request would get its own connection out of the pool, and they'd be concurrent (access to the pool may or may not be serialised depending on the pool's details, sqlx is internally mutated not externally locked for instance).
The mailer might be behind a mutex (its access completely serialised), or the "mailer" might just be the input side of a queue / channel, and the actual mailing work be done in a separate process (that seems way more likely than bounding the request on sending emails really).
Re: Rust is for Professionals
#123> To me, Rust introduced a number of new concepts, like match for control flow, enums as algebraic types, He must be joking.
The author does mention a Haskell/Scala like language missing from their list of languages they have written, but then they do include Erlang which I believe has pattern matching as a fairly core construct? This does lead me to doubt how much Erlang they've written, and in turn how much they've written across all of the languages mentioned.
Erlang has the best pattern matching abilities and it is all around in every single Erlang code I have ever seen.
Re: Rust is for Professionals
#124> To me, Rust introduced a number of new concepts, like match for control flow, enums as algebraic types, He must be joking.
The author specifically and explicitly pointed out 3 times in 2 paragraph that these were new to them , not to the world at large. In fact, they spelled this out very explicitely in the paragraph following the one you selectively quoted: > Many of the new concepts weren't novel to Rust. But considering I've had exposure to many popular programming languages, the fact many were new to me means these aren't common feat…
Re: Rust is for Professionals
#125Re: Rust is for Professionals
#126Earlier quoted context omitted.
Cloning means runtime inefficiency, but the cost is so pathetically small compared to the amount of code we run in Python and Java with their larger footprints. Yes. Clone more.
This is one of the psychological traps I've experienced writing Rust: in Python or Java you can't hope to make things more efficient at a certain point. You couldn't get clever with string re-use if you tried, etc. So you're content to just move forward and be practical. Whereas in Rust you know that it's probably possible to use a &str there instead of a String. If you just bang on it a little longer, you can make i…
That's… not exactly true. `Vec::new` is completely free so that's a different debate, but much as in C++ or C allocations in Rust are much more expensive than in managed languages:
1. system allocators genuinely suck, all of them, though some more than others (iirc macos' is especially bad)
2. managed languages can much more easily specialised allocation strategies (freelists, bump allocators, type-custom allocation strategies), this is either difficult / impossible (no custom allocators) or way more painful (manually pass custom allocators in) in Rust
As a result, allocations in Rust are really tremendously slow by default, it's not too rare to see questions about Rust programs which are slower than managed equivalents, in release mode. Because the rust program is allocation heavy (relatively), it might have 10% the allocations of the non-rust program but the allocations are 100 times more expensive.
Re: Rust is for Professionals
#127Earlier quoted context omitted.
While this can be painful, my basic suggestion -- clone more. The temptation is to never clone, butin C++ people run copy constructors all the time without thinking about it (as they are called automatically).
I've never seen C++ that isn't cautious about copying as little as possible.
Re: Rust is for Professionals
#128Earlier quoted context omitted.
That seems rather trivial, and I'm not sure how you could possibly have any issues with the borrow checker. Just do the first regex search, then escape into a String with regex::escape, then build a regex from the String and search with it. Of course what you are doing is probably wrong since you should use a string matching crate rather than escaping characters and using a regex matching crate.
Since it's so trivial, I would be quite happy for you to implement the feature for me! https://github.com/tree-sitter/tree-sitter/issues/982 Just lol at the idea that you won't run into borrow checker issues when dealing with strings though.
https://play.rust-lang.org/?version=stable&edition=2018&gist...
But what you really want is to get your head around ownership and borrowing, especially when it comes to the scoped RAII that rust has (e.g. freeing a String while a reference to it still exists and is being used would give you the "temporary value dropped while borrowed" error).
Re: Rust is for Professionals
#129Earlier quoted context omitted.
Sure! So I'm trying to implement this feature: https://github.com/tree-sitter/tree-sitter/issues/982#issuec... And here's my branch (you can see the latest commits to see the file I'm modifying): https://github.com/ahelwer/tree-sitter/tree/testfile-separat... I haven't had a chance to go through and add clones everywhere, and will be away at a PT appointment for the next hour or so, but would appreciate any pointers…
The error output for your code is error[E0382]: use of moved value: `suffix` --> cli/src/test.rs:416:48 | 406 | let suffix = FIRST_HEADER_REGEX | ------ move occurs because `suffix` has type `std::option::Option `, which does not implement the `Copy` trait ... 414 | .map(|s| String::from(r"^===+") + &s + r"\r?\n([^=]*)\r?\n===+" + &s + r"\r?\n"); | ---------------------------------------------------------------------…
`Option::deref` is a good choice here.
Re: Rust is for Professionals
#130Earlier quoted context omitted.
This is one of the psychological traps I've experienced writing Rust: in Python or Java you can't hope to make things more efficient at a certain point. You couldn't get clever with string re-use if you tried, etc. So you're content to just move forward and be practical. Whereas in Rust you know that it's probably possible to use a &str there instead of a String. If you just bang on it a little longer, you can make i…
> The clone()s and the Vec::new()s are all explicit, making them feel heavier than those other languages, when in reality they're still quite a bit lighter. That's… not exactly true. `Vec::new` is completely free so that's a different debate, but much as in C++ or C allocations in Rust are much more expensive than in managed languages: 1. system allocators genuinely suck, all of them, though some more than others (ii…
Edit: I do know that languages where strings are immutable use that fact to do lots of optimization (automatically sharing "copied" strings and just cloning reference-counters, for example), but you can accomplish some of this in Rust too with Rc or even persistent data structures if you really want to. And of course there are cases where it's more efficient to actually mutate a string, which these languages can't do. But it sounds like you're talking about something else?