Live data from Hacker News

Announcing Rust 1.20

blog.rust-lang.org

11–20 of 277 posts

Re: Announcing Rust 1.20

#11
post #2

"Associated functions" = class methods "Associated constants" = limited version of class variables Rust keeps approaching C++'s feature set.. I am amazed that the above wasn't in Rust to begin with, though. Can't think of any other languages which has classes but no class methods/variables.

Associated consts allows constants to be derived from our trait-constrained parametric polymorphism. C++ currently has no analog to this system (templates can be used, but don't provide a constraint system; concepts are not in C++17 afaik).

At an introductory level, like this announcement, we teach this system by analogy to OO, but its not OO in its core and snide comments like this only reveal the limits of your knowledge.

Re: Announcing Rust 1.20

#12
post #2

"Associated functions" = class methods "Associated constants" = limited version of class variables Rust keeps approaching C++'s feature set.. I am amazed that the above wasn't in Rust to begin with, though. Can't think of any other languages which has classes but no class methods/variables.

Associated consts allows constants to be derived from our trait-constrained parametric polymorphism. C++ currently has no analog to this system (templates can be used, but don't provide a constraint system; concepts are not in C++17 afaik). At an introductory level, like this announcement, we teach this system by analogy to OO, but its not OO in its core and snide comments like this only reveal the limits of your kno…

> concepts are not in C++17 afaik

That's correct, though they have been added to the C++20 draft: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p073...

Re: Announcing Rust 1.20

#13
> An unstable sort could provide this result, but could also give this answer too:

It might just be me, but using "this" twice in the same sentence to refer to two distinct items, one a prior example and one an upcoming example, is somewhat odd. That said, I understood it perfectly fine, it just caused me to stop and ponder the wording for a moment. The following might be more clear:

An unstable sort could provide that result, but could also give this answer too:

Re: Announcing Rust 1.20

#14
post #13

> An unstable sort could provide this result, but could also give this answer too: It might just be me, but using "this" twice in the same sentence to refer to two distinct items, one a prior example and one an upcoming example, is somewhat odd. That said, I understood it perfectly fine, it just caused me to stop and ponder the wording for a moment. The following might be more clear: An unstable sort could provide th…

Sounds great, I've made the change. Thanks! https://github.com/rust-lang/blog.rust-lang.org/commit/92031...

Re: Announcing Rust 1.20

#15
post #6
post #2

"Associated functions" = class methods "Associated constants" = limited version of class variables Rust keeps approaching C++'s feature set.. I am amazed that the above wasn't in Rust to begin with, though. Can't think of any other languages which has classes but no class methods/variables.

You've misread the announcement; Rust has had associated functions since time immemorial. Associated consts aren't class variables, because constants can't vary (that's sort of the whole point of constants...). Rust also doesn't have classes in any recognizable sense (we can argue all day about whether Rust supports "OOP", but the separation of data and behavior into structs and impls respectively pretty thoroughly s…

>Associated consts aren't class variables, because constants can't vary

That's why I wrote "limited version of". Rust's "associated constants" are a subset of C++'s class variables feature. Namely you can only have variables qualified "const" i.e. constants.

>Rust also doesn't have classes in any recognizable sense

What? If you have instantiatable abstract data types with associated methods you have a "class". Calling them "structs" does not change that. There are classes defined with "struct" in C++ and D too.

Oh and calling an interface a "trait" does not change its fundamental nature either.

Rust clearly is an OOP language.

Re: Announcing Rust 1.20

#16
post #5

Earlier quoted context omitted.

NB. associated functions have always existed. Also, to be a little snide: "Modules" = modules "Concepts" = traits C++ keeps approaching Rust's feature set! It's normal and even expected that languages in a similar space will either draw inspiration from each other or converge on similar solutions.

What's funny about this is that I had worded it even less clearly, and it was changed due to feedback: https://github.com/rust-lang/blog.rust-lang.org/pull/192#dis... Guess I didn't go far enough :)

Maybe "In previous Rust versions you could already define traits, ..."?

Re: Announcing Rust 1.20

#17
post #4
post #2

"Associated functions" = class methods "Associated constants" = limited version of class variables Rust keeps approaching C++'s feature set.. I am amazed that the above wasn't in Rust to begin with, though. Can't think of any other languages which has classes but no class methods/variables.

Now you have me wondering what use a class is without methods or variables. It's just a namespace?

Threadsafe (no externally visible mutable data) singleton instance?

Re: Announcing Rust 1.20

#18
Not a Rust programmer, so the answer to this question may be in TFM -- Rust has floats, but it doesn't make available constants for inf and NaN? Are you not guaranteed IEEE754 floats?

    const NAN: f32 = 0.0f32 / 0.0f32;
    const INFINITY: f32 = 1.0f32 / 0.0f32;
Or is that just for the sake of example?

Re: Announcing Rust 1.20

#19

Not a Rust programmer, so the answer to this question may be in TFM -- Rust has floats, but it doesn't make available constants for inf and NaN? Are you not guaranteed IEEE754 floats? const NAN: f32 = 0.0f32 / 0.0f32; const INFINITY: f32 = 1.0f32 / 0.0f32; Or is that just for the sake of example?

https://doc.rust-lang.org/std/f32/

I believe you can do std::f32::NAN

Re: Announcing Rust 1.20

#20

Not a Rust programmer, so the answer to this question may be in TFM -- Rust has floats, but it doesn't make available constants for inf and NaN? Are you not guaranteed IEEE754 floats? const NAN: f32 = 0.0f32 / 0.0f32; const INFINITY: f32 = 1.0f32 / 0.0f32; Or is that just for the sake of example?

It's just for an example - see https://doc.rust-lang.org/std/f32/.
Post reply on HN