I've been implementing some code using struct functions and must say I'm completely happy with the calling side. On the receiving side (the function itself), a patterns is appearing that might be avoided. Currently struct functions look like this:
func void myStruct_init(MyStruct* this) {
this.a = 1;
this.b = 2;
// ..
}
This is just a small piece of code, but the thing that starts to itch in bigger functions is the frequent appearance of the
this.
To make it feel more like (for example) a C++ class, we could add the struct members in the function namespace. Then all the
this keywords could go (unless ambiguous). This would have some consequences:
- name duplicates between module and struct members is allowed (since can distinguish with module.a and this.a)
- name duplication between struct members and function arguments is not allowed (cannot distinguish somehow)
I don't think since is a problem, since it's not a problem in object-oriented languages as well. Any feedback is welcome,
Cheers,
Bas