Solidity allows for unnamed function params, how to use them?
contract C {
// omitted parameters
function func(uint k, uint ) returns(uint) {
return k;
}
}
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communitySolidity allows for unnamed function params, how to use them?
contract C {
// omitted parameters
function func(uint k, uint ) returns(uint) {
return k;
}
}
I could answer the returns
parameter anonymity.It takes a return statement to return some value from the function for not having a parameter name.
Whereas having a named parameter in the returns
, we don't need a return statement.Whatever value is assigned to the named parameter in the return argument would be returned at the end of the function execution automatically.
function func(uint k, uint ) returns(uint myValue) {
myValue=404;
}
404 is returned automatically without even having a return statement. I hope it helps partially
Increases readability.
If your logic doesn't require some of the parameters, omit naming those parameters to make it obvious that your logic doesn't depend on them.