Create versatile Microservices in Golang – part 1 of 10 part series


Create versatile Microservices in Golang – part 1 of 10 part series
http://ift.tt/2zVIkiu

Submitted November 20, 2017 at 08:20PM by ewanvalentine
via reddit http://ift.tt/2z36OmG

Advertisements

How do you or your team format long function / method signatures?


How do you or your team format long function / method signatures?

I've been implementing some types that perform IO (e.g. database queries, API calls, etc.), and as a result have been passing around things like a context. Along with a receiver, the function name, and a context, it doesn't leave you with much space left to fit in the rest of your parameters and/or return type on a line.

I try to stick to below 100 characters on a single line, because a lot of the time I work with 2 code editors sat side-by-side.

For longer function / method signatures, do you chop down your parameters? Or do you just leave it all on one line? Or do you do something else maybe? (I mean, if you cannot possibly make the names of things shorter too).

func (s *SomethingLong) WithAReasonableName(ctx context.Context, param1 string, param2, param3 int) (WithAReasonableName, error) { // ... } func (s *SomethingLong) WithAReasonableName( ctx context.Context, param1 string, param2 int, param3 int, ) (WithAReasonableName, error) { // ... } 

That second approach is a lot easier to fit in, but sometimes I wonder if it's harder to read? Also, it's a bit more difficult to do that in an interface declaration too…

Submitted November 20, 2017 at 06:58PM by SeerUD
via reddit http://ift.tt/2AWSooN