News for hackers. Stuff that matters.
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.