Git Product home page Git Product logo

Comments (4)

stevedonovan avatar stevedonovan commented on July 1, 2024

Yes, it does 'undermine' the message, so the message must be clarified. Traits are like modern Java interfaces, and may have default methods. (Case in point, Iterator - only have to define next(), get the rest for free). And this is a form of implementation inheritance, although not defined on the data. There's also a limited form of inheritance from Deref (String gets all the methods from &str for free).

I suppose I'm trying to shake the dogma tree here ;) Let me clarify this further! I suppose I wanted to hammer the point that there are no classes, just data + traits. But you can do similar tricks.

from gentle-intro.

stevedonovan avatar stevedonovan commented on July 1, 2024

Traits are like abstract C++ classes that don't have any data members, so additional virtual methods can be provided that only depend on other virtual methods. Except they can also be used as type constraints in generic functions. Allows for more flexible design trade-offs - don't have to always do polymorphic route.

from gentle-intro.

orvly avatar orvly commented on July 1, 2024

Okay, it's much clearer now, thanks. I like the explanation in your comments. I think the key phrase is "this is a form of implementation inheritance, although not defined on the data." Adding this before or after the ShowWindows example would help, IMO.

Another thing: there's a broken link in the next to last paragraph, in the "Here is a rather promising minimal Windows GUI framework" sentence.

from gentle-intro.

stevedonovan avatar stevedonovan commented on July 1, 2024

Thanks for the comments, exactly the feedback I need! I was a bit down on traditional OOP, because the two forms of inheritance get confused. Java/C# at least separate out interfaces to avoid the tangled problem of multiple full inheritance. There's a simpler language inside Rust, but it would be more awkward. E.g. implementing Iterator would be a real bastard if there weren't provided methods. There's also Deref coercion where (for example) String inherits all the methods defined on &str. So let me mention these things up front, and not introduce any new concepts in the example. By the way, if you can think of any other OOP scenarios that could do with an example, I'm interested.

from gentle-intro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.