You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of now (go <= 1.17) every function definition needs to declared function parameters as required. We cannot have any default value assigned to the function, for achieving this, the developer needs to adds conditions inside the function, and the user-caller of the function, if not interested in the param, must pass nil as value, and if the parameter is not a pointer type, he is required to pass a zero-literal of that specific type. All of this can be handled by introducing a new feature in go2 that supports specifying a default value in function declaration. The benefits of this:
Less code for sure, as many conditions inside the beginning of the functions would be eliminated, as they are not necessary anymore
Compatible with existing code-bases, as it introduces no breaking changes to the current code-bases of go1.*
More readable codes, less obligatory type-specific zero-values for function invocations
More welcoming to new developers landing form other languages, as most of them support this feature
Regarding the compile cost, others might have some points.
The text was updated successfully, but these errors were encountered:
mostafatalebi
changed the title
proposal: spec: allow having default values for function declaration
proposal: spec: allow having default values for function declaration - Go2
Jan 23, 2022
As of now (go <= 1.17) every function definition needs to declared function parameters as required. We cannot have any default value assigned to the function, for achieving this, the developer needs to adds conditions inside the function, and the user-caller of the function, if not interested in the param, must pass nil as value, and if the parameter is not a pointer type, he is required to pass a zero-literal of that specific type. All of this can be handled by introducing a new feature in go2 that supports specifying a default value in function declaration. The benefits of this:
Regarding the compile cost, others might have some points.
The text was updated successfully, but these errors were encountered: