buzz-language / buzz

👨‍🚀 buzz, A small/lightweight statically typed scripting language
https://buzz-lang.dev
MIT License
1.22k stars 34 forks source link

Remove implicit `this` argument #98

Open giann opened 1 year ago

giann commented 1 year ago

Since buzz is supposed to be unambiguous do we need implicit this argument for objects' methods?

object Person {
    str name,

    fun sayHello(str to) -> print("Hello {to} from {this.name}");
}

would become

object Person {
    str name,

    fun sayHello(Person this, str to) -> print("Hello {to} from {this.name}");
}
notcancername commented 1 year ago

Wouldn't this incorrectly suggest a copy is being made?

giann commented 1 year ago

No, objects, lists and maps are always passed by reference and not copy.

hexaredecimal commented 1 year ago

Wouldn't it be better if the type of "this" can be omitted and inferred from the object block because the Object is a type... right...? In this case "Person" is?

giann commented 1 year ago

If we do this, it means we don't have "methods" anymore, just functions associated with the object. this becomes a user convention and buzz would see it like a normal function argument.

Also I try to avoid inferring when I can help it. One of buzz tag lines is that it's unambiguous, meaning very few implicit behaviors.