Live data from Hacker News

When in Go, do as Gophers do

talks.golang.org

81–90 of 93 posts

Re: When in Go, do as Gophers do

#81
post #2

I've never known a language with so much discussion on why what you are doing isn't idiomatic as Go. I'm enjoying using Go for the few small services I'm using it for but it seems that a language which has to constantly fight it's users to reinforce what it considers idiomatic has some core issues.

Don't forget the constant reminder that leaving out is just simplicity, even if it means you're writing a lot of if statements and extra code.

Re: When in Go, do as Gophers do

#82

Earlier quoted context omitted.

> Given that every single error check there is just > passing up the error, is it really that different from > having exceptions that propagate along with RAII style > resource cleanup? Yes, it's fundamentally different. The whole point is to make those error blocks visible, so future maintainers are forced to deal with the reality that those invocations are fallible. Maybe there's a way to make the error handling le…

Except, you know, just mindlessly typing out "if err != nil { return }" does not somehow force enlightenment upon the user. The error blocks are so uniform in their banality that future maintainers treat them the same way that error handling is treated in every other language.

The fundamental difference is that each separate error is accounted for rather than 4 lines all being treated as error points so you never know which could throw.

Re: When in Go, do as Gophers do

#83
post #33

Earlier quoted context omitted.

That's not really idiomatic. You should be adding context to the error you return, or a new error.

Given its prevalence all across Go code, are you _sure_ it's not idiomatic? Hell, look at the presentation in the link: http://talks.golang.org/2014/readability.slide#11 . If the oracle of idioms does not write idiomatic code, then wtf is idiomatic code?

You don't think people simplify some error handling to fit code on slides?

Re: When in Go, do as Gophers do

#84
post #13

Earlier quoted context omitted.

> I've never known a language with so much discussion on why what you are doing isn't idiomatic as Go. Python is another language where there is a lot of talk about idiomatic code ('Pythonic'). C++11 and C++14 also have a lot of idiomatic discussion since the community's trying to move to a different style with the latest enhancements. Not sure if this is a signal of core issues.

Python is another language where there is a lot of talk about idiomatic code ('Pythonic'). I wonder what an appropriate adjective could be for idiomatic Go code. Gonic? Gonian?

Gophers say idiomatic go. We don't need a fancy shorthand for it (also all the viable possibilities are terrible ;).

Re: When in Go, do as Gophers do

#85
post #79

Earlier quoted context omitted.

Go does not require it. Interface compliance is statically checked. This is a debugging trick because Go interfaces use structural subtyping instead of explicitly declaring which types implement an interface. This is a calculated design decision with several trade offs. There is nothing "sad" about it.

How do you list all interfaces a give type supports just by looking at it? Both by design, as well as, by accident (usually it different method semantics). You don't need to teach me Go, I was into it before 1.0 given its Oberon influences, and like everyone on gonuts that disagrees with the design gets told, I went elsewhere.

> How do you list all interfaces a give type supports just by looking at it?

That question doesn't make any sense. I can write a new interface that an existing type supports and then use that type as that interface. That's the awesome power of go interfaces. Using existing types for things their original creators couldn't have thought of.

Re: When in Go, do as Gophers do

#86
post #31

Earlier quoted context omitted.

So it's a static typing check ? the code won't even compile if the ColumnWriter struct doesn't implement the interface ?

Yes. It won't compile. This check is not really needed as the code would fail when a function which accepts scan.Writer would fail (compilation) if ColumnWriter is sent and if it doesn't satisfy the interface. However, this is easier to debug.

Yeah, this type of check is nice if you intend to implement an interface, but don't actually use the type as that interface in your package. This will give a compile time error if your type doesn't satisfy the interface. You could write a test for it too, but this is a little simpler and harder to miss.

Re: When in Go, do as Gophers do

#87
post #40
post #14

Earlier quoted context omitted.

Feel free to enlighten us specifically about how they are better.

In Go, you're not returning a sum type, so it's down to the programmer to remember that the "real" return value is likely toxic waste when its copassenger the error return value is non-nil.

Ok thanks for filling in the blank.

Re: When in Go, do as Gophers do

#88
post #85
post #79

Earlier quoted context omitted.

How do you list all interfaces a give type supports just by looking at it? Both by design, as well as, by accident (usually it different method semantics). You don't need to teach me Go, I was into it before 1.0 given its Oberon influences, and like everyone on gonuts that disagrees with the design gets told, I went elsewhere.

> How do you list all interfaces a give type supports just by looking at it? That question doesn't make any sense. I can write a new interface that an existing type supports and then use that type as that interface. That's the awesome power of go interfaces. Using existing types for things their original creators couldn't have thought of.

> That question doesn't make any sense.

You are a consultant playing fireman in a Fortune 500 corporation.

Your task, in case you accept it, is to fix a performance problem no one from in-house teams has been able to track down.

The code is developed in three sites, all in separate time zones, with an overall size of 40 developers ideally churning code 8 hours a day.

Now dive in into this code and fix the issue.

It is a fixed price project of one week.

This is an example how code navigation is valuable.

> That's the awesome power of go interfaces.

Like any language that supports structural typing, nothing awesome about it.

Re: When in Go, do as Gophers do

#89
post #88
post #85

Earlier quoted context omitted.

> How do you list all interfaces a give type supports just by looking at it? That question doesn't make any sense. I can write a new interface that an existing type supports and then use that type as that interface. That's the awesome power of go interfaces. Using existing types for things their original creators couldn't have thought of.

> That question doesn't make any sense. You are a consultant playing fireman in a Fortune 500 corporation. Your task, in case you accept it, is to fix a performance problem no one from in-house teams has been able to track down. The code is developed in three sites, all in separate time zones, with an overall size of 40 developers ideally churning code 8 hours a day. Now dive in into this code and fix the issue. It i…

If, somehow, figuring out what interfaces a type implements is valuable, I would use a tool, like this one:

https://github.com/dominikh/implements

Re: When in Go, do as Gophers do

#90
post #89
post #88

Earlier quoted context omitted.

> That question doesn't make any sense. You are a consultant playing fireman in a Fortune 500 corporation. Your task, in case you accept it, is to fix a performance problem no one from in-house teams has been able to track down. The code is developed in three sites, all in separate time zones, with an overall size of 40 developers ideally churning code 8 hours a day. Now dive in into this code and fix the issue. It i…

If, somehow, figuring out what interfaces a type implements is valuable, I would use a tool, like this one: https://github.com/dominikh/implements

Thanks for pointing it out.
Post reply on HN