News for hackers. Stuff that matters.
Re:I Don't Use Classes by dhimes on Thursday March 12, 2020 @12:07PM (#22558236)
That sounds like a class.
Re:I Don't Use Classes by paulmd on Thursday March 12, 2020 @12:36PM (#22558624)
Yep. This whole discussion just seems like a C vs C++ styleguide slapfight.

Having the functions that operate on the struct attached directly to the struct declaration, vs having some functions that the first parameter is the struct on which the function operates, doesn't seem like a particularly meaningful distinction to me. OK, you like C-style programming in favor of C++-style programming, congrats. It's still a class either way.

Re:I Don't Use Classes by damnyou on Friday March 13, 2020 @01:03AM (#22564889)
The distinction you describe is not meaningful, but the key feature that separates classes from other forms of code organization/polymorphism, like typeclasses as in Haskell/Rust, is not that. It is inheritance.
Re:I Don't Use Classes by nicoburns on Thursday March 12, 2020 @12:51PM (#22558802)
I guess it's kind close to a C++ class. It's pretty different to a class in a language like Java, because all classes in Java are heap allocated and behind references.

Enums are are the better example of non-class types. For example, you can have:

    enum StringOrInt {
        String(String),
        Int(u32),
    }
And you can go ahead and implement methods on that type. Classes have "AND-state", not "OR-state". But a Type in general can have either kind of state.
Re:I Don't Use Classes by htns on Thursday March 12, 2020 @01:35PM (#22559410)
That's equivalent to wrapping an enum in a class. Emulations of type hierarchies without OO often fail like this, having a A-or-B be literally the same type so losing out on type safety/forcing constant rechecking of the discriminant.
Re:I Don't Use Classes by afiori on Friday March 13, 2020 @05:06AM (#22565807)
That can be done in Rust by having two different types implement the same interface
Re:I Don't Use Classes by dmkolobov on Thursday March 12, 2020 @03:31PM (#22560795)
It's a product type[0], containing a single inner type of `u32`. Sometimes classes look like product types.

[0] https://en.wikipedia.org/wiki/Product_type

Re:I Don't Use Classes by naasking on Thursday March 12, 2020 @12:45PM (#22558728)
Data types are not classes.