Closed jolestar closed 6 months ago
I prefer Context
as first argument
I prefer
Context
as first argument
I agree with too. In this way, the verifier can easily determine whether the first function is of type Context, but it becomes a bit more complicated if it is the last one.
For example, in C++ class functions, a this pointer
is implicitly added during compilation, and this this pointer
becomes the first parameter of the function.
prefer first
I think the main reason Sui uses TxContext
as the last argument is that this argument is a system argument and the user doesn't have to care about it.
For example, when passing command line arguments, the user needs to skip the first Context
argument, and then do the count.
If we make Context
the last argument, the user doesn't need to skip it.
But in rooch, we support both signer
and Context
as system arguments.
So, the example should look like this:
public entry fun my_entry(ctx: &mut Context, signer: &signer, a: u64, b: string::String, c: vector<u8>, ){
}
vs
public entry fun my_entry(a: u64, b: string::String, c: vector<u8>, ctx: &mut Context, signer: &signer){
}
I prefer
Context
as first argumentI agree with too. In this way, the verifier can easily determine whether the first function is of type Context, but it becomes a bit more complicated if it is the last one.
This is only about the code-style convention, not about the verifier. Currently, the verifier and MoveosVM support Context
in any position.
I prefer
Context
as first argumentI agree with too. In this way, the verifier can easily determine whether the first function is of type Context, but it becomes a bit more complicated if it is the last one.
This is only about the code-style convention, not about the verifier. Currently, the verifier and MoveosVM support
Context
in any position.
During compilation, check if the first parameter of the gas_free
function is Context.
If the Context parameter can be supported at any position in the function parameters, then the rust code needs to be slightly modified. it's a small problem.
This is only about the code-style convention, not about the verifier. Currently, the verifier and MoveosVM support
Context
in any position.During compilation, check if the first parameter of the
gas_free
function is Context. If the Context parameter can be supported at any position in the function parameters, then the rust code needs to be slightly modified. it's a small problem.
The gas_free
validate function is like implementing an interface
. The implementation should follow the interface function's signature.
I prefer the parameters at the end, because the first thing a function needs to pay attention to is the ordinary parameters. You don't need to worry about whether there is a context at all times. If you need it, you will add it.
Most people favor Context as the first argument, so follow that convention.
And 10xhunter also contributes a view. Go also puts Context
as the first argument (https://go.dev/blog/context-and-structs). As the first argument, it can support variable-length arguments in the future (https://gobyexample.com/variadic-functions).
The
Context
should be the first or last argument? This is just a code-style convention.Or
The
TxContext
in sui is the last argument.https://github.com/MystenLabs/sui/blob/1292544b58bb8558063a44992e79ba952c2a6d37/sui_programmability/examples/defi/sources/pool.move#L129-L138
Part of #921