Earlier quoted context omitted.
It is. It's not going to replace Python, and if maintenance is the metric, then "rewrite it in rust" is not the right move. But I do think Rust will gain traction, be a round a long time, and slowly become a complement to existing C/C++ ecosystems through wrapping and binding. I'm just not sure the other way will materialize. Until Rust can be used to feed back into C/C++ ecosystems and long-standing projects (like t…
At this point Rust is not the prmary ecosystem for anything. The important and exciting new things are written in C++, not Rust. Rust has no advantages over C++ once you know C++.
Rust is for Professionals
101–110 of 157 posts
Re: Rust is for Professionals
#102"(...) Rust feels more like Python than C. (...)" This feels like a very powerful assertion. Does the rest of the HN audience agree with this? If this is true, how long did it take?
I'm a bit confused by this take. With Rust you're constantly thinking low level details, like which type of reference something is. I would place it closer to C than Python, but closer to C++ than either.
- Match ergonomics, so that you have to think about borrowing less in patterns
- The compiler providing suggestions for those cases where you must specify them
- Type inference
- Iterators letting you write fairly functional code
Things like having to write &*foo[..] or .as_mut_ref() are indeed "warts" when you don't care about those details, but they happen uncommonly enough that it isn't perceived as an onerous cost.
Re: Rust is for Professionals
#103Earlier quoted context omitted.
If you don't mind sharing snippets for the diagnostics you couldn't figure out, I would love to see them in case we can mechanically suggest the appropriate code, but in general a well placed .clone(), .cloned() or .collect() will be what you want. Likely what's happening is you're iterating over a sequence (you can think of options as a sequence of only one iteration as well), but that iterator is over borrows of th…
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…
diff --git a/cli/src/test.rs b/cli/src/test.rs
index ac4807bf..8b9882ab 100644
--- a/cli/src/test.rs
+++ b/cli/src/test.rs
@@ -410,16 +410,17 @@ fn parse_test_content(name: String, content: String, file_path: Option)
.map(|b| String::from_utf8_lossy(b).to_string())
.map(|s| escape_reserved_regex_chars(&s));
- let suffixHeaderPattern : Option = suffix
+ let suffixHeaderPattern : Option = suffix.as_ref()
.map(|s| String::from(r"^===+") + &s + r"\r?\n([^=]*)\r?\n===+" + &s + r"\r?\n");
- let suffixDividerPattern: Option = suffix
+ let suffixDividerPattern: Option = suffix.as_ref()
.map(|s| String::from(r"^---+") + &s + r"\r?\n");
- let headerRegex = suffixHeaderPattern
- .and_then(|s| ByteRegexBuilder::new(&s[..]).multi_line(true).build().ok())
- .as_ref()
- .unwrap_or(&HEADER_REGEX);
+ let headerRegexFromSuffixHeaderPattern = suffixHeaderPattern.as_ref()
+ .and_then(|s| ByteRegexBuilder::new(&s[..]).multi_line(true).build().ok());
+
+ let headerRegex = headerRegexFromSuffixHeaderPattern
+ .as_ref().unwrap_or(&HEADER_REGEX);
// Identify all of the test descriptions using the `======` headers.
for (header_start, header_end) in headerRegexRe: Rust is for Professionals
#104Earlier quoted context omitted.
I believe the "subset of correct code" refers to things like the current non-support for things like let (left, right) = (&mut foo[..split], &mut foo[split..]); where you have to rely on things like foo.split_at_mut(split), which are implemented as unsafe under the cover. I see these are limitations but not show-stoppers in any way.
It's surely not a showstopper when it's on one line, but again the problem in practice is that those slices may be other operations or hidden behind other APIs, and happening at different depths in a complicated call tree, and you get an error only up at the top when what you're doing looks "clearly correct". Yes, sure, the rule in question may be simple in the abstract (it's a compiler, after all -- they're just sof…
Re: Rust is for Professionals
#105Earlier quoted context omitted.
If you don't mind sharing snippets for the diagnostics you couldn't figure out, I would love to see them in case we can mechanically suggest the appropriate code, but in general a well placed .clone(), .cloned() or .collect() will be what you want. Likely what's happening is you're iterating over a sequence (you can think of options as a sequence of only one iteration as well), but that iterator is over borrows of th…
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…
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");
| ------------------------------------------------------------------------------- `suffix` moved due to this method call
415 |
416 | let suffixDividerPattern: Option = suffix
| ^^^^^^ value used here after move
|
note: this function consumes the receiver `self` by taking ownership of it, which moves `suffix`
--> /Users/ekuber/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:451:38
|
451 | pub fn map U>(self, f: F) -> Option {
| ^^^^
error[E0716]: temporary value dropped while borrowed
--> cli/src/test.rs:419:23
|
419 | let headerRegex = suffixHeaderPattern
| _______________________^
420 | | .and_then(|s| ByteRegexBuilder::new(&s[..]).multi_line(true).build().ok())
| |__________________________________________________________________________________^ creates a temporary which is freed while still in use
421 | .as_ref()
422 | .unwrap_or(&HEADER_REGEX);
| - temporary value is freed at the end of this statement
...
425 | for (header_start, header_end) in headerRegex
| ----------- borrow later used here
|
= note: consider using a `let` binding to create a longer lived value
You need to change line 413 to turn `suffix` into an `Option` to avoid taking ownership of it: let suffixHeaderPattern: Option = suffix
.as_ref()
.map(...);
and you need to change the `headerRegex` extraction to turn it also into an `Option` from an `Option` by using `.as_ref()` before the `.and_then` call, which lets you avoid the `&s[..]` reborrow, that only lives until the end of that closure: let headerRegex = suffixHeaderPattern
.as_ref()
.and_then(|s| ByteRegexBuilder::new(s).multi_line(true).build().ok())
.unwrap_or(HEADER_REGEX.clone());
Edit: I would also consider this to be a diagnostics bug, for at least the first case rustc should have suggested .as_ref(). For the second part, the compiler would ideally have pointed at the `&s[..]` as part of the problem, and the sibling comment has the change you likely want.Edit 2: to further drive the point home that this should be a bug, this is the current output for a similar case while I was trying to minimize this:
error[E0308]: mismatched types
--> src/main.rs:10:22
|
10 | .map(|s| bar(s));
| --- ^ expected `&Struct`, found struct `Struct`
| |
| help: consider using `as_ref` instead: `as_ref().map`
https://play.rust-lang.org/?version=stable&mode=debug&editio...Re: Rust is for Professionals
#106Earlier quoted context omitted.
I believe the "subset of correct code" refers to things like the current non-support for things like let (left, right) = (&mut foo[..split], &mut foo[split..]); where you have to rely on things like foo.split_at_mut(split), which are implemented as unsafe under the cover. I see these are limitations but not show-stoppers in any way.
Yes, but the rule is still complete. What is going on is "place" is currently defined to be local x, or field x.f, or index x[i], but all x[i] are merged to x[*]. Rust's so-called NLL changed definition of "live". The point is, the rule is simple, formal, and complete. It is neither an ad hoc rule nor a best effort prover.
Not to belabor this growing thread, but here's the disconnect. I complained the rules were ad hoc and complicated, you replied that they were simple, and when challenged on an edge case your treatment is to add another clause to re-define a term you used in isolation earlier.
That's what "ad hoc and complicated" means.
Re: Rust is for Professionals
#107Earlier quoted context omitted.
I'm a bit confused by this take. With Rust you're constantly thinking low level details, like which type of reference something is. I would place it closer to C than Python, but closer to C++ than either.
I wouldn't say that thinking about ownership is "low level details". You are (or should?) always having to think about this when building APIs. The difference is that in for example Python you don't have a way to encode that information and enforce it. I would say that the "feeling" of writing on a high-level language comes from a few ergonomic features: - Match ergonomics, so that you have to think about borrowing l…
This isn't strictly true. For instance Swift uses value semantics, which is equivalent to adding an implicit `.copy()` in rust every time most variables are passed around. It obviates a lot of the low-level details, at the cost of performance and control. This is a lot more "python-like" in my opinion, where having to hold these details in your mind is very much against the design priorities of python.
Python wants everything to be implicit, to eliminate tedium wherever possible, and for syntax to barely exist. By contrast Rust favors explicitness, demands a lot ceremony, and is very syntax-heavy. These languages are antithetical in so many ways.
It's fairly subjective, so I would not try to convince you that Rust is more similar to C than Python, but many of the points you brought up apply to virtually every modern mainstream language. It's hard to imagine why Python would come up as a comparison point for Rust unless C and Python were literally the only other languages you had ever programmed with.
Re: Rust is for Professionals
#108Earlier quoted context omitted.
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.
Solving that issue isn't trivial. I just read it and I wouldn't know where to begin, probably because I don't understand the requirements. I think what's being called "trivial" is doing a bit of regex searching. It's probably accurate to call that trivial for an experienced Rust programmer, but if you're just beginning, I don't think it's helpful to call anything trivial. I still remember my first exposure to Rust. I…
https://doc.rust-lang.org/rust-by-example/ and https://github.com/rust-lang/rustlings might be good places to visit to gain that experience, as well as improving the specific diagnostics to be more actionable.
Re: Rust is for Professionals
#109> You see practices cargo culted across the decades (like the 80 character terminal/line width and null-terminated strings, which can both be traced back to Hollerith punchcards from the late 19th century) I limit my lines to 80 chars for more practical reasons. I have a wide-screen 43" monitor and restricting content to 80 columns allows me to have the project/navigation pane + 4 vertical splits side by side. Couple…
It seems like the perpetuation of the use of null-terminated strings is more about interoperability with what came before.
And like you suggest, 80 characters is at the limit of what people generally find comfortable reading. (I rely on editors to word-wrap code on-the-fly rather than insert line breaks manually... maybe that's what was meant? That's a tradeoff, though, since some tools don't do word-wrapping or don't do it well.)
Re: Rust is for Professionals
#110Earlier quoted context omitted.
Solving that issue isn't trivial. I just read it and I wouldn't know where to begin, probably because I don't understand the requirements. I think what's being called "trivial" is doing a bit of regex searching. It's probably accurate to call that trivial for an experienced Rust programmer, but if you're just beginning, I don't think it's helpful to call anything trivial. I still remember my first exposure to Rust. I…
Looking at their current iteration of the code, the problem is not in the regex crate's API, but rather on them not having the ownership system internalized yet. https://doc.rust-lang.org/rust-by-example/ and https://github.com/rust-lang/rustlings might be good places to visit to gain that experience, as well as improving the specific diagnostics to be more actionable.
Yes, I figured that to be the case, but still wanted to say, "Discussions are open for questions, even if they are beginner related, as long as it's related to regex'ing somehow." :-)