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
Both resultString and err belong to the scope of the if/else statement here. This is a handy way to manage functions that return errors (almost all of them) but isn't generally used routinely due to scope; often if erris nil, you want to do something with resultString, but doing it in the else block is awkward, so instead code will usually read
resultString, err := foo()
if err != nil {...}
...
The project as it is now doesn't handle this consistently, so I'm setting a guideline and leaving it as an issue to be fixed:
IF all values returned by the function are specifically related to the handling of an error returned by that function, then an initializer should be used.
OTHERWISE, regular syntax should be used.
I will be digging around for this for the time being, but it's a good place to start if you're unfamiliar with Go and want to familiarize yourself with syntax.
The text was updated successfully, but these errors were encountered:
Go allows for the initialization of variables before
if
statements. For example, if we have a functionfoo() (string, error)
, you could:if resultString, err := foo(); err != nil {...} else {...}
Both resultString and err belong to the scope of the if/else statement here. This is a handy way to manage functions that return errors (almost all of them) but isn't generally used routinely due to scope; often if
err
is nil, you want to do something withresultString
, but doing it in theelse
block is awkward, so instead code will usually readThe project as it is now doesn't handle this consistently, so I'm setting a guideline and leaving it as an issue to be fixed:
I will be digging around for this for the time being, but it's a good place to start if you're unfamiliar with Go and want to familiarize yourself with syntax.
The text was updated successfully, but these errors were encountered: