Earlier quoted context omitted.
> maybe the site's reading time estimator is broken No, it's just made for prose, not tutorials.
Yep, code is a lot of "words" which throws off the estimate. I need to address this, but I don't think completely ignoring code blocks is really the solution there.
A half-hour to learn Rust
121–130 of 342 posts
Re: A half-hour to learn Rust
#122Earlier quoted context omitted.
I've only had a passing acquaintance with C and C++, so I've never used aliases. I just googled it... why the heck would you copy pointers? That's insane! In my example, a, b, and c were variables, not pointers.
You keep using this word, variables. I don't think it means what you think it means. At least in my book pointers are still variables (as in "a pointer variable"), and a variable is any named value, whether it's a scalar or a pointer or a nth-pointer, or what its storage is. But you mean that in your example there is no way to affect the previous value, right? > I just googled it... why the heck would you copy pointe…
Pointers are used reference things allocated from the heap, and never anything else, unless you're insane. Pointers get directly handled in linked lists, trees, etc.
If at all possible, pointers should be avoided otherwise.
Values passed to a procedure can be done by value (the default in Pascal), or by reference (VAR parameters).
I don't see why anyone wouldn't copy values by default... it is the only sane way to do things.
Re: A half-hour to learn Rust
#123Re: A half-hour to learn Rust
#124Earlier quoted context omitted.
if I say a = 2; b = a; c = a; There's no pointer in there, just 2.
That will work fine, because 2 is 'Copy', so it can be copied trivially (as are structs consisting only of Copy members which are marked as Copy). Roughly speaking anything with a pointer in it isn't Copy, though many objects will implement Clone, which basically just means you need to explicitly call .clone() to make a copy instead of it happening implicitly.
Someone needs to explicitly nail down the mission statement of Rust... because to me it seems to be
"Rust will introduce pointers where they don't need to be, and then try to protect you from the results with obsessive rules"
Re: A half-hour to learn Rust
#125Earlier quoted context omitted.
You keep using this word, variables. I don't think it means what you think it means. At least in my book pointers are still variables (as in "a pointer variable"), and a variable is any named value, whether it's a scalar or a pointer or a nth-pointer, or what its storage is. But you mean that in your example there is no way to affect the previous value, right? > I just googled it... why the heck would you copy pointe…
Variables can be varied... you can increment, decrement, do whatever you want with them. They keep track of things. Pointers are used reference things allocated from the heap, and never anything else, unless you're insane. Pointers get directly handled in linked lists, trees, etc. If at all possible, pointers should be avoided otherwise. Values passed to a procedure can be done by value (the default in Pascal), or by…
Variables by themselves are not much. They inherit the properties of the type they are bound to. So what you can do with them can be as restrictive or as permissive as the type allows. That type can be a pointer/reference as well.
Re: A half-hour to learn Rust
#126Earlier quoted context omitted.
> I don't understand why b=a; c=a; You know how C has a problem with aliases? (multiple variables referencing the same thing)? Which introduce bugs, prevent optimizations, etc? Well, Rust tries to prevent this, and make more explicit (and known to the compiler) when you do this...
I've only had a passing acquaintance with C and C++, so I've never used aliases. I just googled it... why the heck would you copy pointers? That's insane! In my example, a, b, and c were variables, not pointers.
Pointer aliasing is not always obvious.
Re: A half-hour to learn Rust
#127Earlier quoted context omitted.
That will work fine, because 2 is 'Copy', so it can be copied trivially (as are structs consisting only of Copy members which are marked as Copy). Roughly speaking anything with a pointer in it isn't Copy, though many objects will implement Clone, which basically just means you need to explicitly call .clone() to make a copy instead of it happening implicitly.
2 is Copy? It's an integer, could be 2.0 if you wanted to make it a float. Someone needs to explicitly nail down the mission statement of Rust... because to me it seems to be "Rust will introduce pointers where they don't need to be, and then try to protect you from the results with obsessive rules"
Hope it helps!
Re: A half-hour to learn Rust
#128Re: A half-hour to learn Rust
#129A half-hour to learn Rust Jan 27, 2020 · 51 minute read · rust maybe the site's reading time estimator is broken? sarcasm intended. But seriously, it is good to have people writing things like this.
Re: A half-hour to learn Rust
#130Earlier quoted context omitted.
That will work fine, because 2 is 'Copy', so it can be copied trivially (as are structs consisting only of Copy members which are marked as Copy). Roughly speaking anything with a pointer in it isn't Copy, though many objects will implement Clone, which basically just means you need to explicitly call .clone() to make a copy instead of it happening implicitly.
2 is Copy? It's an integer, could be 2.0 if you wanted to make it a float. Someone needs to explicitly nail down the mission statement of Rust... because to me it seems to be "Rust will introduce pointers where they don't need to be, and then try to protect you from the results with obsessive rules"
What '2 is Copy' means precisely that Rust WILL NOT 'introduce pointers where they don't need to be' - 2 is fine to 'alias' because it's a primitive type and so a copy is made when you do that, (i.e. the type implements the 'Copy' trait). However when you do that with complex types that do not implement Copy, you're moving ownership to the new variable so cannot use the old one any more.