Add Inheritance
But you can only remove properties from subclasses
Add inheritance, but all properties must be private
there must be inheritance tax, indeed
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
What if instead inheritance, you could cherrypick some behavior from a class e use it on yours?
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?
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.
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!