This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Instance and Static functions #3
Jomy10
started this conversation in
Syntax & language features
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the following struct:
Declaring functions (methods)
declaring a function (method) for this struct could go in one of the following ways (not sure which one is best)
Extending the struct
With a reference
Discusion
I think
ext
(as in extend) might be cleaner, but
(dog &dog)` is more explicit and forces you to use the variable in your function, making for much cleaner code (no accessing variables directly that belong to the struct)Static vs instance
My current idea is the following:
So calling these would look like this:
I really like this idea as it makes it very explicit that
IsAnimal
is a static method (like you would haveDog::isAnimal()
in Rust anddog.bark()
)Another idea would be the following syntax:
I'm not sure what is the best.
Beta Was this translation helpful? Give feedback.
All reactions