Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Eela6
May 25, 2007
Shredded Hen
It depends on what you're trying to do with the parallelism. Generally speaking heavy parallelism comes up most in numerics, which for which go is a bad choice of language.

On the other hand if you've just got some work you'd like to spread across multiple processors that's easy enough to do with go. I'm not the biggest fan of go but I find it's concurrency model better than most.

Eela6 fucked around with this message at 18:08 on Jun 30, 2017

Adbot
ADBOT LOVES YOU

Eela6
May 25, 2007
Shredded Hen

Furism posted:

I finally have some time and a project idea to learn Go. I want to make a True Random Number Generator by reading raw files from a webcam aimed at a nearby tree. I figure I could diff images, hash that, etc.. This probably exists already but oh well.

Any pointers, word of advice, or should I just head into it? I'm not a very good developer, programming is more of a hobby and I'm only average in C#.

Go is a bad language for numerics. That said, it's as good a project as any to learn Go with; if it's what you want to do, go for it.

Eela6
May 25, 2007
Shredded Hen

Furism posted:

Well honestly the other contender is Rust, but it seemed exceedingly complicated for an amateur like myself. Go is easy, I've been told.

Go is probably the easiest C-family language to pick up. If you want to pick up another statically typed, compiled language, Go is a good choice. Go's biggest advantages are easy compilation to native machine code, better-than-usual concurrency model, and a programming model focused on simplicity: it's lightweight syntax, lack of exceptions, & extremely rigid typing help enforce that what 'what you see is what you get'.

Go's biggest disadvantages are it's lack of generics, it's limited syntax, it's almost complete lack of syntactic sugar, and it's incredibly anemic handling of numerics (the math standard library is almost a joke).

As such, Go tends to excel in highly-concurrent, 'simple' backend work that needs to be deployed across many different environments. It tends to be weakest in scientific & mathematical computing.

Coffee Mugshot posted:

Go and Rust are fine for making some amateur TRNG. Try it out and report back.

:agreed:

Eela6
May 25, 2007
Shredded Hen

Walked posted:

So I've been using go a lot lately for toolmaking and it's been pretty great for that.

I've been using VS Code and it's been pretty good, but want to be sure I'm not missing a better Dev environment for go.

Is anything else going to do better than VS Code + plugins?

My coworkers and I are split pretty evenly between vscode, atom, and gogland.

VsCode is my personal favorite of the three, at least for now. I find gogland to be a little slow and buggy for now, though it seems to be rapidly improving.

Eela6
May 25, 2007
Shredded Hen
I'm working with an API that serves JSON in response to GET requests. Great!

The problem is, it represents true as "T" and false as "N".
Go code:
type Restaraunt struct {
	ID        string   `json:"id,omitempty"`
	FoodTypes []string `json:"food_types,omitempty"`
	IsOrganic bool     `json:"is_organic,omitempty"`
}
JavaScript code:
{
    "id": "saddfae09ru234"
    "food_types": ["japanese", "sushi"]
    "is_organic": "N",
}
Is there some way to easily unmarshal these strings into boolean values? Ideally, I would also be able to unmarshal true, false, and nil/empty to the appropriate values.

The logic I want is basically this, but I'm not so good with the json package
Go code:
func booleanVal(b []byte) (val bool, ok bool) {
	switch string(b) {
	case "true", "Y":
		return true, true
	case "false", "N", "":
		return false, true
	default:
		return false, false
	}
}

Eela6
May 25, 2007
Shredded Hen

rt4 posted:

In Java-like languages, I'm accustomed to catching exceptions, then throwing a new exception in a "chain" so that I get information about every level of the stack trace. Does Go have this capability? I haven't found one, so I've created this pattern in my modules instead:

code:
if err != nil {
		return errors.New("mail API request failed: " + err.Error())
	}
This provides an error specific to this particular function while preserving the error from the function it called. Is there a better way to do it?

Sort of. The traditional golang way is to use fmt.Errorf for the same purpose, so you don't gave to call err.Error()

Eg,
code:

return fmt.Errorf("mail api request failed: %v", err)

You still have to build your trace manually, though.

Eela6
May 25, 2007
Shredded Hen

homercles posted:

I'm building a tool that does a lot of computation through lots of goroutines, and pipelining chunks of work in N:M relations. Before I start optimising, I want to know, for each goroutine:
  • How much time it is waiting on channels to return data
  • How much time it is running
  • How much time it is pending to run because other goroutines are currently running
Is it possible to get these goroutine stats in a concise manner?

Sounds like you want to use go test -blockprofile .

The following might be helpful:
https://golang.org/cmd/go/#hdr-Description_of_testing_flags
https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs
https://golang.org/pkg/runtime/pprof/

Eela6
May 25, 2007
Shredded Hen

Small White Dragon posted:

I'm new to GO, and working through the tutorial. I noticed that you can do:

x, y := <- ch1, <- ch2

As well as

x, ok := <- ch

Isn't this sort of thing ambiguous? Can you not have multiple right hand arguments that return multiple values?

You can't have multiple right hand arguments that return multiple values. This removes the ambiguity at the expense of expressiveness, which is very go, fwiw.

Try it yourself at the go playground

Eela6
May 25, 2007
Shredded Hen

rt4 posted:

Are there any tools available to automatically generate a module file for an existing project? I'd really like to ditch this GOPATH stuff, but I also don't feel like enumerating my dependencies by hand.

If you're using modules, `go build` will do what you want automatically


https://github.com/golang/go/wiki/Modules posted:

Version Selection
If you add a new import to your source code that is not yet covered by a require in go.mod, any go command run (e.g., 'go build') will automatically look up the proper module and add the highest version of that new direct dependency to your module's go.mod as a require directive. For example, if your new import corresponds to dependency M whose latest tagged release version is v1.2.3, your module's go.mod will end up with require M v1.2.3, which indicates module M is a dependency with allowed version >= v1.2.3 (and < v2, given v2 is considered incompatible with v1).

Adbot
ADBOT LOVES YOU

Eela6
May 25, 2007
Shredded Hen

rt4 posted:

Oh, I just need a go.mod and the compiler handles the rest? That's lovely

Let me know your experience. At {CORPORATION} we're still using `dep` and go 1.10, so I haven't played around with it myself.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply