10

Solidity allows for unnamed function params, how to use them?

contract C {

 // omitted parameters
 function func(uint k, uint ) returns(uint) {
    return k;
 }

}
Daniel Que
  • 783
  • 7
  • 21
Roland Kofler
  • 11,638
  • 3
  • 44
  • 83
  • 1
    +1 for bringing up an interesting topic unused method parameter, for return parameter see my answer. – Abhiram mishra Jul 04 '16 at 18:53
  • Frankly I suspect it is only a sideeffect for creating the unnamed return parameter. It was easier to say in this BNF both are a parameter and I allow also input parameter but they will go to dev/null... If not I will be happy to know a new feature... – Roland Kofler Jul 04 '16 at 18:57

2 Answers2

3

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

Abhiram mishra
  • 1,922
  • 1
  • 13
  • 23
0

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.

ferit
  • 507
  • 5
  • 25