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
Mao Zedong Thot
Oct 16, 2008


Voted Worst Mom posted:

It doesn't matter what gofmt does because it does it consistently and that's the point. There are some bugs but that's not one of them.

Yeah, caring about how gofmt is formatting your poo poo indicates you don't understand how great gofmt is.

I have been writing a bit of golang recently, and I find it decently enjoyable. For the most part I can appreciate the language for what it is and isn't, it fills a like-C-but-not niche pretty well. I will bandwagon missing generics though, having to use (literally) the exact same code in 3 spots because I'm doing the same thing to 3 maps with a different value type is shameful (though map[string]interface{} is an even worse solution).

Adbot
ADBOT LOVES YOU

Mao Zedong Thot
Oct 16, 2008


Deus Rex posted:

That's not a very strong argument. If gofmt formatted each of your files into a single line, would you still feel that way?

It's possible to simultaneously feel that a tool like gofmt is a great idea, and also that the formatting decisions it makes are problematic at times.

Sure, my point is simply that it Just Works and is Pretty Good and why the hell does anybody feel like bikeshedding the smooshing of x*x.

Tangential hilarity, re: someone asking for map/filter:

https://groups.google.com/forum/#!msg/golang-nuts/RKymTuSCHS0/MylwD97xYqUJ posted:

The modern programmer thinks a newline is a thousand times harder to
type than any other character. If instead you take a newline as only
one keystroke, which it is, the fact that your program might not fit
on one line is a bearable burden.

-rob

https://groups.google.com/d/msg/golang-nuts/RKymTuSCHS0/BXbkvn3ckOkJ posted:

I would say the Go designers are frightened of newlines. In particular the one in front of the hanging brace.

Mao Zedong Thot
Oct 16, 2008


Go is really good for infrastructure stuff. We write and use a ton of tooling in Go both stuff we've written (logging, config mgmt, virtualenv fuckery, load balancing) and OSS like etcd, terraform, etc.

Anybody that's spent much time with our Go code really starts to loathe the hundreds of thousands of lines of python we have. As our team has grown we get bit more and more by bullshit that comes out of bigger teams mixed with weak types, no compilation, etc. Not to mention we end up CPU bound in a ton of places.

Go rulez basically.

Mao Zedong Thot
Oct 16, 2008


Mr. Crow posted:

How are the analytics libraries for go these days? Anything similar to pandas in Python?

Yeah, pretty good example of thing that is probably awful in golang. Stick to pandas :/

Mao Zedong Thot
Oct 16, 2008


Winkle-Daddy posted:

Uhhhhh, stupid question about how channels work and my Google-fu is failing me this afternoon.

Let's say I'm creating a hypothetical data struct that's a bunch of hostnames/platforms. Now let's say I want to ping each of these once and just return a confirmation that a certain host was completed back to the main function.

My first inclination is to do something like this:
code:
package main

import (
	"fmt"
)

type hostInfo struct {
	hostname string
	platform string
}

func pinger(data hostInfo, done chan hostInfo) {
	// Code to do some ping stuff...
	done <- data
}

func main() {
	pchan := make(chan hostInfo)
	someData := []hostInfo{}
	someData = append(someData, thingie{"10.1.1.1", "linux"})
	someData = append(someData, thingie{"10.1.1.2", "linux"})
	someData = append(someData, thingie{"10.1.1.3", "linux"})
	someData = append(someData, thingie{"10.1.1.4", "linux"})
	for _, v := range someData {
		go pinger(v, pchan)
	}
	close(pchan)
	for data := range pchan {
		fmt.Printlf("Finished with %s of type %s.", data.hostname, data.platform)
	}
}
This code just exits immediately and I assume it's because I have nothing receiving on "pchan", but I thought the range built in would receive on a channel until it's closed, but it doesn't appear to be working quite like I'd expect.

This is just a stupid simple example to help me understand how these things work. In a real example I am quite certain my design would be significantly different.

You're closing your channel before you read it.

You probably want to do something like this:

code:
func main() {
.......
	for _, v := range someData {
		go pinger(v, pchan)
	}
	defer close(pchan)

	for i := 0; i < len(someData); i++ {
		select {
		case data := <-pchan:
			fmt.Printf("Finished with %s of type %s.\n", data.hostname, data.platform)
		}
	}
}

Mao Zedong Thot
Oct 16, 2008


Go rules so hard there's not much to say about it. Way more like a reimagined C than Java though. That it's GC'd is a red herring, outside of specific niches GC shouldn't be a thing devs should worry about.

So vendoring is first class now, which rules hard. I got 99 problems but dependencies are never one. What do y'all think of glide vs godep vs? I've mostly used godep, but think it will probably be glide soon.

Mao Zedong Thot
Oct 16, 2008


https://dave.cheney.net/2013/10/12/how-to-use-conditional-compilation-with-the-go-build-tool

You can use `// +build linux` to control which files are built, or just use `_<os>.go` filename suffix. The below works fine with `go build` for example.

main.go
code:
package main

import ()

func main() {
	foo()
}
main_linux.go
code:
package main

import (
	"fmt"
)

func foo() {
	fmt.Println("linux")
}
main_windows.go
code:
package main

import (
	"fmt"
)

func foo() {
	fmt.Println("windows")
}
edit: really you just need `foo_common.go` to be `foo.go` I think

Mao Zedong Thot fucked around with this message at 19:26 on Nov 16, 2016

Mao Zedong Thot
Oct 16, 2008


Winkle-Daddy posted:

So...doing things this way seems to have broken my ability to run automated tests. If I build, and provide as args every file I want to include it works fine. If I try to use build tags to control how things build I get the following error:
code:
go build .
./networking.go:132: undefined: createFSFromTemplate
./networking.go:136: undefined: modFSFromTemplate
./networking.go:140: undefined: cleanMockFS
./utils.go:28: undefined: convertTextToJSON
The functions that are being complained about exist only in the _[os] version of the file. Is there some other magic I can do to make this work or are all my options at this point potential time sinks?

My example builds fine with `go build .` -- it picks up `main_<os>.go` functions. You have networking.go/networking_<os>.go? Try removing the build tags maybe?

Or if you can provide a reproducible example via gist or something I can poke at it.

Mao Zedong Thot
Oct 16, 2008


.............

Mao Zedong Thot fucked around with this message at 17:56 on Jun 27, 2017

Mao Zedong Thot
Oct 16, 2008


MALE SHOEGAZE posted:

in my experience, lamdas / microservices are a function that maps simple problems to complex distributed systems problems

:vince:

Mao Zedong Thot
Oct 16, 2008


Dangerllama posted:

^^ a good post.

The package management piece is in the process of being baked now. I won’t go into the craziness, but there was “dep” for a while, which is now in the process of being replaced with vgo.

Vendoring has worked really well for like multiple years. Go's biggest mistake was showing people `go get` without bashing into their head that it's not how you actually do anything besides "randomly install some cool thing to run".

Mao Zedong Thot
Oct 16, 2008


Check out https://github.com/mitchellh/mapstructure

You still have to traipse your way through an unknown structure, but mapstructure makes it a bit nicer to do.

Adbot
ADBOT LOVES YOU

Mao Zedong Thot
Oct 16, 2008


ErIog posted:

I have a dumb question, but why would you care about the specific pointer to the function? You have tests. Go has idioms for testing you can use to test your stuff. So if those tests are good and they passed, what does testing the pointer get you?

I also have an unrelated super smarty genius question. I want to generate pretty docs for my Go libraries like the standard library has. When I Google I find lots of stuff about running an HTTP server with godoc, and then I find other stuff that's like give us the path to the GitHub and we'll generate docs on the fly. The libraries in question aren't publicly available on Github. They're internal to my workplace, and they will never in a million years be publicly available. Is there something I can do other than launching the godoc HTTP server and spidering with wget?

You could also just run the godoc server internally :shrug:

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