Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

compilation - Reasoning for order of function declaration syntax such as access modifier and return type across different languages

I am used to seeing functions declared using a pattern something like below:

<access-modifier> <return-type> <function-name> (<parameter(s)>)
{
     <code>
}

I associate the above pattern of keywords with C-based languages, but have seen languages such as Python and JavaScript that are less verbose where the return type is determined by the compiler and functions are marked simply with "def" or "function", which seems cleaner and maybe even easier to learn like below:

<function-keyword> <function-name> (<parameter(s)>) 
{
     <code> 
}

But I just started learning Solidity and am curious if there is a reason why the order of the keywords to define a function are mixed around like below:

<function-keyword> <function-name> <access-modifier> <return-keyword> (<parameter(s)>)
{
     <code>
}

Maybe it is simply a different syntax, but it seems more verbose and less standard, so I figured there could be an interesting technical reason for this, such as perhaps the order of the keywords allowing faster compilation time or something I wouldn't even think of, and I am just curious about it, but couldn't find anything online regarding this. Thanks for any thoughts somebody can share with this newer dev!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...