Thoughts on Rust, a few thousand lines in
1–10 of 183 posts
Re: Thoughts on Rust, a few thousand lines in
#2This is often a Bad Idea, as you get unstable sorts and you are right back to the same problem.
- Explanation: How do I get the minimum or maximum value of an iterator containing floating point numbers? — https://stackoverflow.com/a/50308360/155423
- Example: https://play.integer32.com/?version=stable&mode=debug&editio...
See also:
- How to do a binary search on a Vec of floats? — https://stackoverflow.com/q/28247990/155423
Instead, use a wrapper type or raise a panic.
Re: Thoughts on Rust, a few thousand lines in
#3Haskell does it too, for the same reason/purpose / with the same effect.
Re: Thoughts on Rust, a few thousand lines in
#4Re: Thoughts on Rust, a few thousand lines in
#5> Unlike nearly every language I’ve ever used, Rust actually encourages variable shadowing. Haskell does it too, for the same reason/purpose / with the same effect.
It's not the same as the Rust example because you're shadowing an ivar to a local, but since `self.` is implicit you're still shadowing.
Re: Thoughts on Rust, a few thousand lines in
#6This makes me want to add `p90`, `p50` and so on to jq...
Re: Thoughts on Rust, a few thousand lines in
#7> Unlike nearly every language I’ve ever used, Rust actually encourages variable shadowing. Haskell does it too, for the same reason/purpose / with the same effect.
Swift does, but typically for Optional promotion. You see stuff like `guard let delegate = delegate else { return }` inside functions all the time, shadowing a property with a local & promoting the type from Optional to T. It's not the same as the Rust example because you're shadowing an ivar to a local, but since `self.` is implicit you're still shadowing.
You'll see the same in Rust
fn example(name: Option) -> Option {
let name = name?;
Some(name.len())
}
Or fn example(name: Option) {
if let Some(name) = name {
println!("{}", name.len());
}
}
A main difference is the requirement to use `Some`, which allows for the flexibility to apply to any enum.> but since `self.` is implicit
To make sure I'm following, do you mean that Rust's `self.` is implicit in Swift?
Re: Thoughts on Rust, a few thousand lines in
#8Earlier quoted context omitted.
Swift does, but typically for Optional promotion. You see stuff like `guard let delegate = delegate else { return }` inside functions all the time, shadowing a property with a local & promoting the type from Optional to T. It's not the same as the Rust example because you're shadowing an ivar to a local, but since `self.` is implicit you're still shadowing.
> for Optional promotion You'll see the same in Rust fn example(name: Option ) -> Option { let name = name?; Some(name.len()) } Or fn example(name: Option ) { if let Some(name) = name { println!("{}", name.len()); } } A main difference is the requirement to use `Some`, which allows for the flexibility to apply to any enum. > but since `self.` is implicit To make sure I'm following, do you mean that Rust's `self.` is…
struct S {
var string: String
func doSomething() {
// These two lines are equivalent.
print(string)
print(self.string)
}
}Re: Thoughts on Rust, a few thousand lines in
#9 let foo = "...";
let foo = parse(foo);
let foo = escaped(foo);
Is it really shadowing or mutation of foo?I would consider this shadowing (something you can do in OcaML):
let foo = "..." in
let foo = parse(foo) in
let foo = escaped(foo) in
dosomething(foo);;