buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Remove implicit `this` argument

Open giann opened this issue 3 years ago • 4 comments

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}");
}

giann avatar Nov 18 '22 15:11 giann

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

notcancername avatar Sep 22 '23 17:09 notcancername

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

giann avatar Sep 22 '23 18:09 giann

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?

hexaredecimal avatar Sep 22 '23 22:09 hexaredecimal

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.

giann avatar Sep 23 '23 02:09 giann