mleku on Nostr: yeah, go's `:=` operator often gets overused but it's neat for constructor functions, ...
yeah, go's `:=` operator often gets overused but it's neat for constructor functions, notably maps must be dynamically allocated so if a complex type has them it must have a constructor/initializer
i personally have some style rules i try to stick to, similar to yours:
- always give a name to return values that helps you understand what the function does at a glance - this one i had a brief argument about with Ian Lance Taylor of all people
- prefer to use a "var" declaration of a variable if the type is a value or slice (both don't need initialization) and the reason is that it allows you to inline a function call with assignment to its return value variables and most usually an error check clause, because most of teh time in Go you should return an error unless there is no error case for the function (such as those constructors, even then sometimes they do have failure modes, entropy consuming especially always makes me crazy what do i do if the system entropy is ded? lol, doesn't seem like a case i can handle, probably should just panic instead of error because all bets are off with /dev/random no workee
i personally have some style rules i try to stick to, similar to yours:
- always give a name to return values that helps you understand what the function does at a glance - this one i had a brief argument about with Ian Lance Taylor of all people
- prefer to use a "var" declaration of a variable if the type is a value or slice (both don't need initialization) and the reason is that it allows you to inline a function call with assignment to its return value variables and most usually an error check clause, because most of teh time in Go you should return an error unless there is no error case for the function (such as those constructors, even then sometimes they do have failure modes, entropy consuming especially always makes me crazy what do i do if the system entropy is ded? lol, doesn't seem like a case i can handle, probably should just panic instead of error because all bets are off with /dev/random no workee