2

Within the Solidity Docs it's pretty much implied from various bits of example code that a function declaration needs a returns declaration to return an object, but doesn't seem to be actually explained why. Is this because of type checking? What other languages use return declarations? Where is this bit of Solidity syntax derived from? Thanks

2

Is this because of type checking?

Yes, Solidity is statically typed.

What other languages use return declarations?

Some popular ones are C, C++, Java: int main() { ... } says that the function main returns an int.

Where is this bit of Solidity syntax derived from?

The Go language has the return type after the function; I'm not sure if Go is the origin of this though.

Solidity is Javascript-like, so function name() { ... }. Appending returns probably keeps the Javascript feel more, instead of prepending like uint function name() { ... }. Also, in Solidity, tuples can be returned and having them prepended would make readability more difficult to scan code for the names of functions.

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.