GulfOfMexico icon indicating copy to clipboard operation
GulfOfMexico copied to clipboard

Add Inheritance

Open valoeghese opened this issue 1 year ago • 7 comments

But you can only remove properties from subclasses

valoeghese avatar Jun 08 '24 11:06 valoeghese

Add inheritance, but all properties must be private

SkyaTura avatar Jun 20 '24 04:06 SkyaTura

there must be inheritance tax, indeed

JUSTIVE avatar Jun 21 '24 06:06 JUSTIVE

I feel strongly against it Inheritance is a feature so messed up only Java Devs can use it. Therefore, I believe it is not a good idea for any serious project

schaier-io avatar Jun 21 '24 17:06 schaier-io

What if instead inheritance, you could cherrypick some behavior from a class e use it on yours?

SkyaTura avatar Jun 21 '24 18:06 SkyaTura

Maybe we can have a look into how it works in nature. The default there is that you will inherit different traits from one parent and others from the other parent.

So maybe it is a solution to inherit from two classes simultaneously and choose at random which behaviour is used?

schaier-io avatar Jun 21 '24 18:06 schaier-io

Maybe if the parent class could specify different sets of traits to be inherited based on randomness and combination of factors.

For instance, it's random for the child to be of a type annotated by a unsigned 1 digit number.

A class could annotate that only children with X or Y type inherit the traits.

No kidding, this would be awesome.

SkyaTura avatar Jun 22 '24 01:06 SkyaTura

Inheritance sux, why not just have unbound class coercion where any class can be coerce to another class and thereby function like that class, in fact anything could be coerced to any other thing and now have the functions etc. defined by that.

class Player {
   const var health = 10!
   fn damage(amount) {
      healt -= amount!
   }
}

class Tree {
   const var health = 100!
   fn grow(amount) {
      health += amount!
   }
}

class Bucket {
   const var health = 0!
   const var amount = 0!
   fn isFull(amount) {
      return amount === 500!
   }

   fn fill(value) {
      amount += value!
   }

   fn pour(value) {
      amount -= value!
   }
}

const const player = new Player()
const const tree = new Tree()
player.damage(5)!

const const playerAsTree = player is Tree // In other languages 'is' is often used as a check, but here its a command! so we state that player IS! a Tree!
playerAsTree.grow(5)! // this is fine.

const const treeAsBucket = tree is Bucket
treeAsBucket.fill(500) // this is fine.
print(treeAsBucket.isFull()) // true - also fine
print(treeAsBucket.health) // 10 - this is fine, both bucket and tree has a variable named health so that is keept, and the amount variable is added

const const treeAsBucketAsTree = treeAsBucket is Tree
print(treeAsBucketAsTree.health) // 10 - and still fine
print(treeAsBucketAsTree.amount) // Error: amount is not defined on Tree

I think the above feature would make any form of inheritance (YUK) completely pointless. You can do whatever you want!

jeme avatar Jul 03 '24 06:07 jeme