Show HN: GoWork – A Go Distributed Work Library
1–10 of 26 posts
Re: Show HN: GoWork – A Go Distributed Work Library
#2Personal preference, but in this case I'd advise using panic() instead of error. Ignoring errors is rarely a good idea: APIs change, other programmers read their code and don't know about your API, wonder why they ignored the error, &c. You can now also not change your API to ever actually return meaningful errors from that function anymore.
Meanwhile, if the failure mode is so well-defined, just put that in the documentation: "panics if the secret key is not exactly 32 characters long." Let the user of your library worry about it---they will have to, anyway: if they don't, they get an error they have to deal with, and suddenly they're dealing with it after all.
EDIT: From a quick glance, it looks like master gets results back from workers using .Get()? Is it easily possible for master to "select" a bunch of workers and get the first completed one? If you use (or at least somehow allow the use of) channels for this, you get all the built-in Go goodness for this kind of control. Even for dynamic number of channels, the reflect package has a dynamic .Select that handles it for you. I.e.: provide a channel that I can }.
Re: Show HN: GoWork – A Go Distributed Work Library
#3> Error is only returned by this function when the secret isn't 32 characters so as long as your secret is definitely 32 characters you can safely ignore the err returned by this function. Personal preference, but in this case I'd advise using panic() instead of error. Ignoring errors is rarely a good idea: APIs change, other programmers read their code and don't know about your API, wonder why they ignored the error…
The package author means the error will be nil when the secret is 32 characters long; he doesn't mean you can completely ignore checking it.
Regarding when to use panic: "The convention in the Go libraries is that even when a package uses panic internally, its external API still presents explicit error return values." http://blog.golang.org/defer-panic-and-recover
Panics should only be used in cases of programmer error or when the process is in an unrecoverable state.
Re: Show HN: GoWork – A Go Distributed Work Library
#4> Error is only returned by this function when the secret isn't 32 characters so as long as your secret is definitely 32 characters you can safely ignore the err returned by this function. Personal preference, but in this case I'd advise using panic() instead of error. Ignoring errors is rarely a good idea: APIs change, other programmers read their code and don't know about your API, wonder why they ignored the error…
I strongly disagree. The package author means the error will be nil when the secret is 32 characters long; he doesn't mean you can completely ignore checking it. Regarding when to use panic: "The convention in the Go libraries is that even when a package uses panic internally, its external API still presents explicit error return values." http://blog.golang.org/defer-panic-and-recover Panics should only be used in ca…
But that's exactly what will happen. This comment will lead to ws, _ := gowork.NewServer("32 character secret"). Which is a worse situation than a panic(). I understand the normal rule for this, but "a foolish consistency..". In this case, the init value being 32 long can be compared to "the init value must be non-nil." A lot of non-error APIs will panic() if you pass nil, even in the stdlib.
Doing panic() here will lead to less room for error and confusion, in my opinion. Especially because the error is explicit and loud (panic()), it's worth considering breaking the rules for.
Re: Show HN: GoWork – A Go Distributed Work Library
#5Earlier quoted context omitted.
I strongly disagree. The package author means the error will be nil when the secret is 32 characters long; he doesn't mean you can completely ignore checking it. Regarding when to use panic: "The convention in the Go libraries is that even when a package uses panic internally, its external API still presents explicit error return values." http://blog.golang.org/defer-panic-and-recover Panics should only be used in ca…
> The package author means the error will be nil when the secret is 32 characters long; he doesn't mean you can completely ignore checking it. But that's exactly what will happen. This comment will lead to ws, _ := gowork.NewServer("32 character secret"). Which is a worse situation than a panic(). I understand the normal rule for this, but "a foolish consistency..". In this case, the init value being 32 long can be c…
The package author should modify the phrasing of that comment.
Re: Show HN: GoWork – A Go Distributed Work Library
#6Earlier quoted context omitted.
> The package author means the error will be nil when the secret is 32 characters long; he doesn't mean you can completely ignore checking it. But that's exactly what will happen. This comment will lead to ws, _ := gowork.NewServer("32 character secret"). Which is a worse situation than a panic(). I understand the normal rule for this, but "a foolish consistency..". In this case, the init value being 32 long can be c…
If a developer is frequently ignoring returned errors, then they have larger problems and it's their fault. Panic was not added to assist lazy programmers. Even though some API has solidified, an author could later add different return errors. Heck, if that function was calling other functions with returned errors, then the list of possible unique errors increases greatly. You should never ignore an err because you t…
Also, in terms of the top comment in this chain, the work server (master) never gets work from the workers, the workers push completed work back to the server, maybe this isn't clear within the current docs. All communication between the worker and server has to be coordinated by the application implementing the library.
Re: Show HN: GoWork – A Go Distributed Work Library
#7> Error is only returned by this function when the secret isn't 32 characters so as long as your secret is definitely 32 characters you can safely ignore the err returned by this function. Personal preference, but in this case I'd advise using panic() instead of error. Ignoring errors is rarely a good idea: APIs change, other programmers read their code and don't know about your API, wonder why they ignored the error…
I strongly disagree. The package author means the error will be nil when the secret is 32 characters long; he doesn't mean you can completely ignore checking it. Regarding when to use panic: "The convention in the Go libraries is that even when a package uses panic internally, its external API still presents explicit error return values." http://blog.golang.org/defer-panic-and-recover Panics should only be used in ca…
ws := gowork.MustNewServer(key).AddParams(...)Re: Show HN: GoWork – A Go Distributed Work Library
#8Earlier quoted context omitted.
I strongly disagree. The package author means the error will be nil when the secret is 32 characters long; he doesn't mean you can completely ignore checking it. Regarding when to use panic: "The convention in the Go libraries is that even when a package uses panic internally, its external API still presents explicit error return values." http://blog.golang.org/defer-panic-and-recover Panics should only be used in ca…
An idea is to include a function in the library called MustNewServer() that panics instead of returning an error. A usability perk of having single return is that the function can be chained, i. e., ws := gowork.MustNewServer(key).AddParams(...)
Re: Show HN: GoWork – A Go Distributed Work Library
#9Earlier quoted context omitted.
I strongly disagree. The package author means the error will be nil when the secret is 32 characters long; he doesn't mean you can completely ignore checking it. Regarding when to use panic: "The convention in the Go libraries is that even when a package uses panic internally, its external API still presents explicit error return values." http://blog.golang.org/defer-panic-and-recover Panics should only be used in ca…
An idea is to include a function in the library called MustNewServer() that panics instead of returning an error. A usability perk of having single return is that the function can be chained, i. e., ws := gowork.MustNewServer(key).AddParams(...)
Re: Show HN: GoWork – A Go Distributed Work Library
#10if err != nil { return err }
you don't need to put a else after the closing }.