1

If I have a function that just sets a value like this:

  function setBytes(
    bytes32 _value
  ) public {
    testBytes = _value;
  }

Should this kind of functions return a value or should the function remain without a return if the function is called from another contract? In some code examples, I have seen that this kind of functions returns true. Like this:

  function setBytes(
    bytes32 _value
  ) public returns(bool success) {
    testBytes = _value;
    return true;
  }

What is the best practice in such cases and what is the purpose of returning true?

2

There are of course many opinions about this.

In my opinion a function should return a boolean if it's unsure whether the operation will succeed or not and when it's important to know whether it succeeded. I don't see any benefit in returning anything if the function will surely succeed (such as setting a value). In theory even just setting a value may fail due to running out of gas but returning a boolean wouldn't help anything there anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.