Optional `shared` keyword for public actor methods with caller?
For simplicity and consistency, it could make sense for the shared keyword to always be optional for public actor methods. This would increase readability and reduce confusion about when the keyword is needed, e.g. when adding a caller to an existing method.
For example, instead of the following:
public shared ({ caller }) func abc() { ... };
It could make sense to allow:
public ({ caller }) func abc() { ... };
This is an observation from reviewing the Motoko training samples. Is there anything from a technical standpoint that prevents us from making this change?
Might be worth trying but my hunch is that this ambiguous with the special case of
public
Though that is a arguably useless (since
The relevant bit of the grammar describing these modifiers is:
<shared_pat_opt> ::=
That's a good point. I remember coming across this a few years ago.
Example snippet (runnable):
module {
let msg = 123;
public (msg)
}
For anyone reading this, note that the module in the above example does not actually include any public fields despite the public keyword.
Since the current grammar allows statements such as public 5 (but seemingly only at the end of an object/module/class), any usage of this is likely unintentional, so we may want to factor this out either way.