News for hackers. Stuff that matters.
Re:The use of `class` for things that should be simple free ... by vanderZwan on Thursday May 28, 2020 @06:52AM (#23335826)
I like the approach Wouter van Oortmerssen uses in Lobster:

    class Animal:
        alive = true

    class Cat : Animal
        def hello(): print "meow"

    class Dog : Animal
        barked = 0

    def hello(d::Dog):
        print "bark!"
        barked++

    let d = Dog {}
    d.hello()

    let a:Animal = d
    a.hello()
In other words, A.B(C) is just syntactic sugar for B(A, C), and class definitions are just syntactic on top of that. The relation between OO and regular functions and stateful objects is completely transparent (the only real gotcha I can see is that a.hello() still works here because it was assigned a subclass where this method is defined). This makes it easy to store B for later usage, like you wanted to do in your example, and reason about its behavior.

[0] http://strlen.com/lobster/

Re:The use of `class` for things that should be simple free ... by beagle3 on Thursday May 28, 2020 @07:25AM (#23336039)
This is also the approach taken by Nim and D, and it is known as the UFCS (Uniform Function Call Syntax)[0], and I agree - it's the best of all worlds.

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

Re:The use of `class` for things that should be simple free ... by vanderZwan on Thursday May 28, 2020 @07:26AM (#23336047)
Ah, I wondered where it originated. Thank you for that bit of info!
Re:The use of `class` for things that should be simple free ... by amw-zero on Thursday May 28, 2020 @09:15AM (#23336843)
I think Swift does this too?