News for hackers. Stuff that matters.
Re:Announcing Rust 1.20 by copx on Thursday August 31, 2017 @01:46PM (#15142187)
"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.

Re:Announcing Rust 1.20 by kibwen on Thursday August 31, 2017 @01:50PM (#15142238)
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 subsumes classes themselves).
Re:Announcing Rust 1.20 by copx on Thursday August 31, 2017 @02:04PM (#15142362)
>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 by dbaupp on Thursday August 31, 2017 @02:12PM (#15142443)
Having aggregate data types and syntactically having methods seems like a very facile definition of "OOP", versus the conventional uses referring to Smalltalk style message passing or inheritance and overrides. Other than being able to call functions as x.foo() rather than foo(x) or foo x or similar, languages like Haskell and C seem to satisfy the requirements for being OOP, which seems to make "OOP" completely useless as a category.

In any case, this point is been argued at length for every language, including Rust.

Re:Announcing Rust 1.20 by sanxiyn on Friday September 01, 2017 @04:12AM (#15146932)
I actually think having syntactic methods is an important (if not the most important) part of "OOP". You compared x.foo() with foo(x), but that's the wrong comparison. The correct comparison is that when x if of type Tree, x.foo() vs tree_foo(x). Otherwise you get name clashes.

That is, I think the essence of "OOP", OOP-as-used, not any theoretical OOP, is function name resolution depending on type. That and syntax. So first, you write x.tree_foo() instead of tree_foo(x) which is purely syntactic. And then you shorten x.tree_foo() to x.foo(), because x is a tree, which is a great semantic help.

According to this definition, Haskell and C are not "OOP", which matches common understanding.

Re:Announcing Rust 1.20 by pdpi on Friday September 01, 2017 @02:58PM (#15151466)
Function name resolution isn't OOP, it's attaching a namespace to a type. The _really_ important part is dynamic dispatch. You can have proper OOP without method syntax, it just looks awkward to our eyes. In fact, in Objective C,

    [obj doStuff: foo withBar: bar]
gets desugared into

    objc_msgSend(obj, NSSelectorFromString(@“doStuff:withBar:”), foo, bar)
Re:Announcing Rust 1.20 by sanxiyn on Saturday September 02, 2017 @01:29AM (#15154470)
I already agreed function name resolution isn't OOP. My argument was that it is "OOP", with quotes. My supporting evidence is that people consider C++ without any dynamic dispatch as "OOP", with quotes.
Re:Announcing Rust 1.20 by dbaupp on Friday September 01, 2017 @10:20AM (#15148502)
That's a great point and one I hadn't considered, thanks!
Re:Announcing Rust 1.20 by mikebenfield on Thursday August 31, 2017 @05:38PM (#15144170)
> 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.

So if I just take C's structs and add the ability to associate structs with functions using a "struct.function" notation, I now have classes? If so, a class isn't a very powerful concept, is it?

Here's an easy way to see the difference between traits and interfaces, and simultaneously see why some people find OOP completely inadequate for their purposes.

Imagine you're implementing several different types that all need to be able to be added. You've got integers, floats, mathematical vectors, and possibly other types. All of them should support an `add` method. But you should only be able add objects of the same type: an integer to an integer, a float to a float, and a vector to a vector. This incredibly simple idea, to my mind almost the simplest thing a person might want to do with a type system, cannot be expressed in most OOP languages using an interface with an `add` method.

But it can easily be expressed using traits (or using Haskell's type classes).

And this is why I never understood why anyone bothers with OOP.

Re:Announcing Rust 1.20 by everheardofc on Friday September 01, 2017 @03:05AM (#15146705)
Because nobody bothers with "OOP" or "FP" because there is not a single cannonical implementation of these that everyone agrees on.

What you're talking about has nothing to do with neither.

Any language that has generics can have self types or whatever you want to call them. It's a matter of whether the language has a strong static typesystem and most FP-style languages have these and a minority of OOP-style languages has them too.

The reason why I use C++ has nothing to do with a preference for OOP. It's because all the widely used alternatives have terrible performance.

I hate dealing with C++ projects. I hate dealing with memory leaks and segfaults. But that doesn't stop me from creating more of them and working on existing ones.

All of that because the resulting memory footprint and performance are worth it.

Re:Announcing Rust 1.20 by mikebenfield on Friday September 01, 2017 @09:54AM (#15148311)
You seem to be trying to argue with me, but the points you're making are pretty much orthogonal to the ones I made. If you think OOP is not a meaningful concept, you should be arguing with the comment I was replying to, not me.
Re:Announcing Rust 1.20 by vvanders on Thursday August 31, 2017 @02:16PM (#15142474)
Rust doesn't have inheritance which is one of the key pieces of OOP.

Traits just provide a single level of indirection and if you want to do anything more complex you'll need to use composition to achieve it.

Re:Announcing Rust 1.20 by kccqzy on Thursday August 31, 2017 @04:33PM (#15143680)
By that definition, Haskell is an OOP language too, because Haskell has type classes (traits/interfaces) too, and you can have associated methods/associated types too.
Re:Announcing Rust 1.20 by leshow on Thursday August 31, 2017 @05:35PM (#15144147)
It's not though, AFAIK the x.foo() syntax is just sugar for

let a = Foo; Foo::bar(&a); // if bar takes &self

Plus, there is no concept of inheritance. I don't see how that meets any definition of OOP unless you make the definition so weak as to be meaningless.

Re:Announcing Rust 1.20 by pdpi on Friday September 01, 2017 @07:50AM (#15147600)
> Oh and calling an interface a "trait" does not change its fundamental nature either.

Traits are a form of ad hoc polymorphism and behave closer to Haskell's typeclasses than they do to interfaces and subtype polymorphism.

Re:Announcing Rust 1.20 by saghm on Thursday August 31, 2017 @05:36PM (#15144163)
Depending on the language, interfaces can be a lot less powerful than traits. Traits can have default implementations for some methods (meaning you don't have to explicitly implement all of them), and in some cases they can be completely derived automatically. They're really more similar to Haskell's typeclasses than traditionally OO interfaces.
Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @01:51PM (#15142244)
I, at least, don't really think of Rust as having classes. Rusty design patterns don't really look like many traditional OOP design patterns. This is often a hurdle for new Rust programmers. Chapter 17 of the book (https://doc.rust-lang.org/book/second-edition/ch17-00-oop.ht...) is trying to grapple with this question.

Part of the difficulty here is nailing down what "class" even means, exactly. Rust doesn't fit into either of the three major schools of OOP, which I personally nickname the "smalltalk school", the "java school", or the "javascript school".

Re:Announcing Rust 1.20 by zaphar on Thursday August 31, 2017 @02:15PM (#15142466)
Obviously Rust is in the 4'th school which I like to call "The Rust School".

All kidding aside, I think for any regular working day programmer Rust is obviously OOP. The debates are really just which parts of which favorite school of OOP you think Rust is inspired by.

But what really matters is that Rust gives you:

* Encapsulation

* Polymorphism.

* And Code Reuse.

Which are the only three things anyone who reaches for OOP is really looking for anyway. As fun as the PL theory discussions are. (Kind of a Hobby for me at least) I think those are the bits that actually matter to the people who truly need an answer to the question "Is Rust OOP or not?"

Re:Announcing Rust 1.20 by kibwen on Thursday August 31, 2017 @02:33PM (#15142639)
I agree that it's better to focus on encapsulation/polymorphism/reuse, but the reason why I personally object to the idea that "for any regular working day programmer Rust is obviously OOP" is because inheritance is usually taught above all of these as the fundamental property of OOP.

I doubt I'm the only one whose high school and college exposure to OOP was to model "Dog is-a Mammal, Cow is-a Mammal, Mammal is-a Animal", and if a newcomer to Rust tries to do the same as their "hello world" then they're going to be greatly frustrated. Again, this isn't to say that the phrase "Rust is OOP" is necessarily incorrect, only that it's going to backfire if we going around shouting it, due to misaligned expectations.

Re:Announcing Rust 1.20 by GolDDranks on Thursday August 31, 2017 @02:47PM (#15142758)
Agree 100%. And I think that what is commonly thought of OOP (the Java model) suffers greatly from real-life analogies like that. Not everything fits into neat hierarchies – not in real life and not in code.

I also think that the concept of "class" suffers from a great amount of un-orthogonality. A class packages together a memory representation, an encapsulation boundary, an interface that defines functionality and a unit of type parametrisation. I find the way how Rust separates modules as the unit of encapsulation, traits as the unit of functionality and structs as the units of memory representation, very elegant.

Now if one could type-parametrise modules...

Re:Announcing Rust 1.20 by zaphar on Thursday August 31, 2017 @02:50PM (#15142773)
Ahhh the elegance of SML rears it's beautiful head :-)
Re:Announcing Rust 1.20 by pjmlp on Thursday August 31, 2017 @05:01PM (#15143883)
That only happens when the teachers do a bad job not explaining interfaces, protocols, components, categories.... or as Rust puts them, traits.
Re:Announcing Rust 1.20 by zaphar on Thursday August 31, 2017 @02:38PM (#15142689)
Is-A does not and should not imply Inheritance. It merely implies polymorphism. I didn't get formally trained so I can't comment on what college/high school's teach but if they teach that Is-A relationships imply Inheritance then claiming Rust is OOP seems like a good way to educate the mis-educated regarding the difference.
Re:Announcing Rust 1.20 by leshow on Thursday August 31, 2017 @05:42PM (#15144211)
What kind of polymorphism? Traditional OOP is subtype polymorphism. You can't really do that in Rust. It's main polymorphism is parametric and ad-hoc polymorphism a la Haskell. If that's considered OOP then OOP is so broad it's not a useful term
Re:Announcing Rust 1.20 by pjmlp on Friday September 01, 2017 @02:27AM (#15146568)
What is traditional OOP?

The Simula, Smalltalk, Lisp, SELF or BETA model?

Yes, OOP is broad, just like FP also is.

Re:Announcing Rust 1.20 by kibwen on Thursday August 31, 2017 @04:10PM (#15143484)
I don't think that "is-a" is formally defined anywhere. In my school experience, using Java specifically, "is-a" was used to teach the `extends` keyword, while "has-a" was used to teach the `implements` keyword.
Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @02:23PM (#15142532)
> Obviously Rust is in the 4'th school which I like to call "The Rust School".

Ha! But yeah, if you're going to claim Rust is OOP, I would argue that makes the most sense.

> what really matters is that Rust gives you:

Right, this is the "Java School" definition. However, when people talk about OOP this way, when they say "polymorphism", they mean "subtype polymorphism" not "parametric polymorphism." Take https://docs.oracle.com/javase/tutorial/java/IandI/polymorph... as an example. Rust's only sub-typing is for lifetimes.

> As fun as the PL theory discussions are.

I definitely agree that in some senses, this is academic. But at the same time, practitioners can be mis-led by using terms in a different way than they're used to. This is sort of the argument I'm making above; since many practitioners see "polymorphism" as being equal to "subtype polymorphism", calling other types of polymorphism "polymorphism" is a more academic, less user-focused distinction.

Re:Announcing Rust 1.20 by zaphar on Thursday August 31, 2017 @02:43PM (#15142728)
Oh dear. That java tutorial just reads wrong to me but that's probably because I've been burned too many times by conflating polymorphism with code reuse in the form of inheritance.

I think the working programmer doesn't know or care though. They care about whether you can reuse code in some way. And whether you can substitute multiple implementations of an object act as one particular type.

The specifics of how you reach either of those goals is all they want to know and the pedantry that us language geeks love to engage in just blows right past them.

Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @02:49PM (#15142767)
It's possible we've just interacted with different people; I've spoken to a lot that assume inheritance, specifically, and we get questions about it often.

Anyway, thanks for a good discussion!

Re:Announcing Rust 1.20 by zaphar on Thursday August 31, 2017 @03:00PM (#15142838)
It's highly possible. I almost never get to work with people who geek out over language theory :-D

I have to come to HN for that instead.

Re:Announcing Rust 1.20 by tree_of_item on Thursday August 31, 2017 @03:06PM (#15142887)
> Encapsulation, Polymorphism, And Code Reuse.

These are three incredibly vague terms that pretty much every programming language can be said to provide. I can't understand how you think OOP is defined by this.

Do you think Haskell programmers are unable to reuse code? That they don't have any form of polymorphism? That they can't hide implementation details of functions, data structures and modules?

This is the kind of argument that convinces me that OOP is completely bunk. Its adherents can't even explain what it is!

Re:Announcing Rust 1.20 by protomikron on Thursday August 31, 2017 @06:13PM (#15144409)
> These are three incredibly vague terms that pretty much every programming language can be said to provide. I can't understand how you think OOP is defined by this.

I do not want to defend OOP, but I would like to add that object-orientated languages are often to be expected to support these 3 things (encapsulation, inheritance and polymorphism) - at least many sources list these properties as must-have to be considered object-orientated.

> This is the kind of argument that convinces me that OOP is completely bunk.

Agreed. E.g. functional programming has a sound foundation (λ-calculus), but in object-oriented land if often sounds a little bit hand-wavy.

Re:Announcing Rust 1.20 by zaphar on Thursday August 31, 2017 @03:12PM (#15142942)
I wouldn't call myself an adherent. If anything I'm an adherent to the idea that Objects are just another Closure and vice versa. The interesting distinctions are in how they achieve those same goals.

But most working programmers don't care about the debate at all in my experience. When they say they are looking for an object oriented language what they are really saying is:

    I am looking for a language that has a syntax where you
    can declare an object and call methods on that object 
    usually with a dot but sometimes with an ->.
They don't actually care about much more than that most of the time.
Re:Announcing Rust 1.20 by tree_of_item on Thursday August 31, 2017 @03:17PM (#15143014)
> I'm looking for a language with "objects" and a syntax like <this>

But why? That's such a weird thing to look for. Clearly there's a reason they think they want "objects", but what is it? And why the focus on what syntax these objects have?

Re:Announcing Rust 1.20 by zaphar on Thursday August 31, 2017 @05:15PM (#15143997)
I'm not arguing this is a good thing. But I am saying that for the vast majority of programmers out there they use that pattern as a way of determining if they have those three attributes. It's cargo cult programming in a sense but it's also the only signal they've ever known.
Re:Announcing Rust 1.20 by leshow on Thursday August 31, 2017 @05:45PM (#15144232)
I think calling Rust that would confuse people more than anything. They will look for their traditional inheritance style relationships and be frustrated that there is not really any support for it. Better to teach the features that Rust actually has, than to try and fit some uber generic definition of "Objects" that's not going to serve newcommers.
Re:Announcing Rust 1.20 by imtringued on Friday September 01, 2017 @05:20AM (#15147129)
Code organisation. Classes are basically used as datatype specific namespaces.

In Haskell you have to deal with the possibility of record types sharing the same field names.

Re:Announcing Rust 1.20 by naasking on Thursday August 31, 2017 @03:21PM (#15143060)
> Which are the only three things anyone who reaches for OOP is really looking for anyway.

Those are 3 characteristics of modularity, not object or class-specific in any meaningful sense. Rust isn't really a classic object-oriented language, but it is a modular language with object-like abstractions.

Re:Announcing Rust 1.20 by nicoburns on Friday September 01, 2017 @11:35AM (#15149336)
I'd argue that Rust is pretty close to being "javascript school" OOP, except with the addition of strong typing.

JavaScript code bases use a lot of classes, but while JavaScript supports inheritance, it's use isn't particularly idiomatic. What is idiomatic is duck typing (checking for the presence of method or property on an object). This is basically the same as using traits, except without compile time correctness guarantee. You even have things like `Symbol.iterator`[0], which allow an arbitrary object to work with a `for..of` loop, exactly like `impl Iterator` in Rust.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:Announcing Rust 1.20 by copx on Thursday August 31, 2017 @02:44PM (#15142734)
Well, to me Rust code looks fundamentally like any other OO language e.g.

    let mut window: PistonWindow = WindowSettings::new(
            "piston: hello_world",
            [200, 200]
        )
        .exit_on_esc(true)
        .opengl(OpenGL::V2_1)
        .build()
        .unwrap();
If you wrote that in C++ or Java or Python or.. it would /could look fundamentally the same. You create a window object and then call a bunch of its methods (mutating its state). That's OOP.

I think the Rust people just desperately try to disassociate themselves from the OOP label because OOP is not hip anymore. "So 90s" and all that.

I think that's childish. If you use a broad definition of OOP according to which C++, Smalltalk, Java, and Python are all OOP languages said definition certainly covers Rust too.

To be fair, even the C++ crowd doesn't like to use the term OOP anymore and instead say things like "generic programming".. but at the end of the day they too are instantiating classes.

Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @02:54PM (#15142794)
> it would /could look fundamentally the same.

Yeah, the usage does, but the definition does not, the implementation does not, and the features are very different.

For example, "new" is just a convention here, not an actual constructor, as Rust does not have constructors.

> You create a window object and then call a bunch of its methods (mutating its state). That's OOP.

It depends on what you mean by "object". If structs are objects, then OOP boils down to only "you can use x.y() instead of y(x)", which I don't think is a good way to think about programming languages or their features. YMMV, of course.

> I think the Rust people just desperately

I can assure you, that's not the case for me at least; I love OOP languages enough to have both Ruby and Perl logos tattoo'd onto my body.

I don't like saying Rust is OOP because of said definitions elsewhere in the thread, as well as people struggling to map their OOP patterns over. If they hear "Rust is OOP", they expect to be able to do OOP-like things, and when they can't, that's a big frustration. Enough so that we had to add that book chapter.

Re:Announcing Rust 1.20 by kibwen on Thursday August 31, 2017 @02:57PM (#15142817)
"OOP" has suffered since the 90s of being a somewhat vague term in practice (much to the chagrin of Smalltalkers), but making it even more overbroad just to make it apply to Rust will only drive the term further into uselessness. It's not about being "hip", it's about using terminology that's usefully precise. (For the record, I also think "functional programming" is a uselessly broad category these days, having become a victim of its own success.)

It's uncontroversial to state that Rust has methods, which are usually associated with OOP. It's also uncontroversial to state that Rust is utterly incapable of defining inheritance hierarchies, which are also usually associated with OOP. If we're going to argue about it, we might as well try to agree on terms that will let us say things that are meaningful.

Re:Announcing Rust 1.20 by copx on Thursday August 31, 2017 @03:56PM (#15143360)
It actually is the consensus in the OOP world these days that composition is preferable to inheritance in most cases.

Declaring class inheritance to be the defining feature of OOP just because it was fundamental to 1990s Java courses makes about as much sense as to say extreme late-binding is a fundamental aspect of OOP, like Alan Kay does, and thus neither Java nor C++ are OOP languages. Yippee! Suddenly they are no longer boring, old OOP anymore either! Thanks Alan!

You mention FP being a broad category. Indeed it is. Haskell is all about expressive static types, meanwhile Erlang couldn't care less about types. Yet I dare to argue that this broad definition is not "useless" because both Erlang and Haskell default to immutable data and pure functions, and that defines FP more than anything.

Practically meaning that Erlang and Haskell tend to be massively closer to each other than they are to imperative languages.

The same is the case here. Rust is massively closer to C++ than to Haskell. Mutable ADTs+methods+interfaces, as opposed to free functions and (immutable) "raw" data defines the code style way more than questions like subtype vs. parametic polymorphism

If you think that the fact that your dog does not "inherit" from mammal but instead has the mammal "trait", means you are doing a fundamentally different kind of programming, you are wrong. Such differences are of lesser importance in practice.

Re:Announcing Rust 1.20 by kibwen on Thursday August 31, 2017 @04:22PM (#15143594)
> It actually is the consensus in the OOP world these days that composition is preferable to inheritance in most cases.

No argument there. :)

> Yet I dare to argue that this broad definition is not "useless" because both Erlang and Haskell default to immutable data and pure functions, and that defines FP more than anything.

I think this illustrates what I'm trying to get at: if one's task is to further the tenets of functional programming, then going around espousing "functional programming" as a general concept is less direct than just cutting to the chase and evangelizing for immutability and/or purity directly, especially when one considers that e.g. Common Lisp is neither immutable nor pure, but will be what plenty of people's minds jump to when they think of FP.

Re:Announcing Rust 1.20 by dbaupp on Thursday August 31, 2017 @02:52PM (#15142786)
> I think the Rust people just desperately try to disassociate themselves from the OOP label because OOP is not hip anymore.

No, it's mostly driven by the differing semantics despite happening to have similar syntax. Syntax is a surface polish that people focus on a lot, but doesn't drive the core language behaviour.

Re:Announcing Rust 1.20 by sidlls on Thursday August 31, 2017 @03:32PM (#15143164)
Generic programming and Object Oriented programming may overlap in the margins but are different concepts.

Personally I like Rust's better. It feels more like a "better C with generics" than C++ is.

Re:Announcing Rust 1.20 by tatterdemalion on Thursday August 31, 2017 @01:56PM (#15142299)
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 by steveklabnik on Thursday August 31, 2017 @01:58PM (#15142315)
> 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 by dbaupp on Thursday August 31, 2017 @01:50PM (#15142234)
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.

Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @01:52PM (#15142255)
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 :)

Re:Announcing Rust 1.20 by EmanueleAina on Thursday August 31, 2017 @02:07PM (#15142396)
Maybe "In previous Rust versions you could already define traits, ..."?
Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @02:30PM (#15142618)
Re:Announcing Rust 1.20 by tomjakubowski on Thursday August 31, 2017 @02:42PM (#15142722)
> Rust keeps approaching C++'s feature set..

If there's one thing we C++ programmers can agree on, it's that having tons of features makes C++ a pleasure to work with... ?

Re:Announcing Rust 1.20 by jmcomets on Thursday August 31, 2017 @03:57PM (#15143364)
I used to be a huge fan of C++. I loved how you could work with a somewhat OO language while still wielding dark powers like: manual memory management, mix-n-match polymorphism (aka. virtual inheritance), templates, type-erasing.

Then I got a full time job working with a large C++ codebase. Since then I've been dealing with:

- uninitialized variables / members

- NULL checks

- buffer overflows, especially with C-strings

- (mutable) global variables

- exception safety

All these things don't exist in (safe) Rust. I'm sold.

Foot note: the only thing I'm really missing in Rust right now is specialization in generics, which is being worked on here: https://github.com/rust-lang/rust/issues/31844.

Re:Announcing Rust 1.20 by PopsiclePete on Thursday August 31, 2017 @06:27PM (#15144509)
That's my main beef with C++. You read a book and it's beautiful - no uninitialized memory, safety, no C arrays/strings, RAII everywhere, it's clean, fast.....then you get to the "real world" and realize that 99% of C++ programmers are pretty f###ing horrible at their job and should've just stuck to naked C because at least then you'd be able to pin-point the bugs easier.

So C++ is a wonderful language - in a world that only exists in the creators' heads, or on committee tables, or on brand-new, post C++03 codebases. Basically - nowhere.

Re:Announcing Rust 1.20 by gcp on Friday September 01, 2017 @04:22AM (#15146964)
Most large C++ code-bases predate C++11, which was really game-changing.
Re:Announcing Rust 1.20 by ryl00 on Thursday August 31, 2017 @09:22PM (#15145435)
But isn't that the case with basically ANY programming language? Once its use becomes widespread, escaping the confines of the highly skilled early adapters, you can be sure a whole lot of dodgy code will be written in it.
Re:Announcing Rust 1.20 by xfer on Thursday August 31, 2017 @10:53PM (#15145756)
Not really, because the language doesn't make it difficult to write dodgy code and gives you no power to easily find such dodgy code. In other safe languages either you simply can't write these kind of dangerous code or it should be easier to catch them with just keyword search. In C++ you need powerful static analysis and some dynamic instrumentation to hopefully catch them.
Re:Announcing Rust 1.20 by trapperkeeper74 on Thursday August 31, 2017 @02:59PM (#15142837)
Maybe by "pleasure" they mean "obscurity, gotchas and complexity are pleasurable because they trip up newbies and lend themselves to job security."
Re:Announcing Rust 1.20 by pjmlp on Thursday August 31, 2017 @04:58PM (#15143858)
Regarding languages with OOP support, but lacking class methods.

- Object Pascal (in the TP days)

- Modula-3

- Oberon, Oberon-2, Active Oberon, Oberon-07

- Component Pascal

You need to resort to plain functions/procedures instead.

Re:Announcing Rust 1.20 by jandrese on Thursday August 31, 2017 @01:49PM (#15142226)
Now you have me wondering what use a class is without methods or variables. It's just a namespace?
Re:Announcing Rust 1.20 by dbaupp on Thursday August 31, 2017 @01:52PM (#15142250)
"class methods" are specifically static methods, meaning they don't have a self/this object. Rust's closest equivalent to classes has always allowed normal methods and variables (as well as class/static methods, just not class/static "variables").
Re:Announcing Rust 1.20 by e12e on Thursday August 31, 2017 @02:09PM (#15142419)
Threadsafe (no externally visible mutable data) singleton instance?
Re:Announcing Rust 1.20 by jandrese on Thursday August 31, 2017 @02:47PM (#15142755)
Isn't all data (outside of unsafe blocks) in Rust already threadsafe? Isn't that one of the big selling points of the language?
Re:Announcing Rust 1.20 by wahern on Thursday August 31, 2017 @03:38PM (#15143215)
Rust isn't inherently thread-safe; not like in the way Java is thread-safe because of how the JVM's memory model is defined.

Rust makes it really difficult to share mutable data. But once you do that, such as by smuggling a pointer _through_ an unsafe block, all bets are off, even for code outside an unsafe block.

Also, as with Java there will always be bugs in the compiler and runtime. Rust programs were susceptible to StackClash just as much as C applications.

No matter what language you use, if you minimize shared mutable data you'll minimize thread-safety issues.

Re:Announcing Rust 1.20 by CrystalGamma on Thursday August 31, 2017 @03:56PM (#15143361)
If you use a C FFI in any language, including Java, all kinds of safety are off. Unsafe Rust is equivalent to C (with a lot of mandatory lints) in terms of safety, so Rust is not really less safe.
Re:Announcing Rust 1.20 by alphaalpha101 on Friday September 01, 2017 @02:39AM (#15146616)
Not necessarily. There is no actual reason that you couldn't be required to prove to the compiler that your code is safe.

That proof might be parameterised by a proof that some external FFI function was safe, which you might not be able to actually prove and have to assume, but then you would have your assumptions well-documented.

As it is, you have to justify the safety of your unsafe blocks to other programmers using comments, which kind of sucks.

Still better than every other fast language in this area though so I can't complain much.

Re:Announcing Rust 1.20 by jandrese on Thursday August 31, 2017 @04:02PM (#15143418)
I get that all bets are off once an unsafe() block is in play, but in the intended use case it seems like it should be safe.
Re:Announcing Rust 1.20 by kibwen on Thursday August 31, 2017 @04:15PM (#15143524)
You are correct there. Though we can quibble over the definition of "thread safety", concurrent memory safety is a subset of memory safety, which safe Rust enforces (or at least intends to enforce, modulo bugs).
Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @03:49PM (#15143301)
It is data-race free. That's one definition of "threadsafe", but there could be others; it's a pretty broad term.