This comes from a post on r/odinlang. I see there’s many different opinions and speculation flying around in the comments.
A decent explanation is found in the FAQ, for those that don’t know:
Odin also has the concept of import names for packages: this means procedures are declared within different scopes, meaning it would not make any sense syntactically.
One of Odin’s goals is simplicity and striving to only offer one way to do things, to improve clarity.
x.f(y)meaningf(x, y)is ambiguous asxmay have a field calledf. It is not at all clear what this means.
It seems the Reddit commentors pine for the namespaces and organisational benefits of dot notation around functions. I’m not personally too invested in OOP, but just stepping back and thinking loosely and creatively for a moment, I wonder if virtual packages could define scopes…
#package foo{
add :: proc(bing: int, bong: int) -> int
}
main :: proc() {
foo.add(1, 2)
}
…where the above is essentially two packages in one file. I guess as long as these ‘sub-packages’ were isolated within a file it could, internally, work as an imported package, like a package folder in the directory but which is lexically in the file which imports it - I’m not pushing it, I just like theory-crafting.
One comment I found interesting, both because it seems to technically provide a ‘method’ (ha) for people wanting this, and because I:
a) Didn’t know -> was a symbol in Odin
b) Don’t understand how foo is called with just one argument
is the following snippet, which frankly I don’t understand, but it compiles and prints 20:
package main
import "core:fmt"
MyStruct :: struct {
bar: int,
method: proc(this: ^MyStruct, bla: int) -> int,
}
foo :: proc(this: ^MyStruct, bla: int) -> int {
return bla * this.bar
}
main :: proc() {
my_struct: MyStruct
my_struct.bar = 10
my_struct.method = foo
fmt.println(my_struct->method(2))
}
Anyways please share your thoughts.