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
Scaevolus
Apr 16, 2007

"Go is an open source programming language that makes it easy to build simple, reliable, and efficient software."

Go was created by several Google employees frustrated with programming large-scale systems in Java or C++. They designed a language with features to specifically fight technical debt and complexity.

Features that make programming in Go faster:
  • Simple, regular syntax
  • Garbage collection and memory safety
  • Lightweight threads (goroutines), message-passing (channels), and anonymous functions with simple syntax for easy concurrency and asynchronous programming
  • Static typing with type inferences for declarations
  • Interface-based structural typing (compile-time duck typing)
  • Fast compiles to native binaries (Windows/Linux/OSX), statically linked for zero-dependency deployments
  • Excellent standard library, including unit-testing, benchmarking, and profiling packages
  • Easy integration with C libraries
  • Backwards compatibility promise: code you write today will continue to work with future Go 1.x releases
  • Built-in development tools:
    • Integrated build system (gobuild)
    • Automatic code formatting (gofmt)
    • Lightweight documentation generator (go doc)

The designers strive to make a simple language with the minimal features necessary for effective development. I find this results in surprisingly concise code and a pleasant development experience. Many people coming from dynamic languages like Python and Ruby find it expressive and comfortable.

Contributing to the language is very easy, with a well-funded and responsive core team at Google making daily improvements.

Resources:
A Tour Of Go is an excellent interactive tutorial.
Effective Go is a more in-depth introduction.
Documentation index

Negatives:
  • "Go" is a terrible search term, you have to use "Golang" instead to find results.
  • The built-in dependency management system is simple and doesn't work well for more complex use cases like versioned dependencies.
  • There's no support for generics, which isn't as painful as it sounds, but can be frustrating.
  • It's a very new language (first publicly released in 2009, Go 1.0 released in 2012), so available libraries can be limited if you stray from mainstream usage of writing servers or system software.

Previous Go thread

Adbot
ADBOT LOVES YOU

spongeh
Mar 22, 2009

BREADAGRAM OF PROTECTION
How is Go for game dev? I've found a couple of bindings, but nobody seems to support SDL2 yet. I seemed to have the impression that even though it's now 1.0, there's not a whole lot of use, but it may be more server-oriented which I'm not really looking at.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Can't have a thread on Go without starting it off with On Go.

I've dabbled in it a bit. I've found it to be mostly disappointing. They still seem to believe that dynamic linking is the devil, so it's hard to write a solid Go library.

Interfacing with legacy C with bindings and such is also quite a bit more painful than need be.

Baby Nanny
Jan 4, 2007
ftw m8.

Suspicious Dish posted:

Can't have a thread on Go without starting it off with On Go.

I've dabbled in it a bit. I've found it to be mostly disappointing. They still seem to believe that dynamic linking is the devil, so it's hard to write a solid Go library.

Interfacing with legacy C with bindings and such is also quite a bit more painful than need be.

Is it? I've dabbled with cgo (http://golang.org/cmd/cgo/) a few times and it wasn't too bad. Go has been making some steady progress as of late and if you haven't checked it out since 2009 it might be a fun weekend project to code some personal stuff in it over a weekend or two. Coming from a python webdev background I'm really enjoying it.

Scaevolus
Apr 16, 2007

spongeh posted:

How is Go for game dev? I've found a couple of bindings, but nobody seems to support SDL2 yet. I seemed to have the impression that even though it's now 1.0, there's not a whole lot of use, but it may be more server-oriented which I'm not really looking at.
Not the best. The garbage collector hasn't been tuned for realtime applications, and the library support is spotty.

Haunts was an attempt to make a game in Go, but the developer was contracted for a year, and had development troubles after that. One of the updates blames Go's poor dependency management.

floWenoL
Oct 23, 2002

So I've been writing a raytracer in Go. Here are some quick thoughts:

- Go is a nice middle ground between C++ (good performance, but difficult and error-prone) and higher-level languages like Javascript and Python (easy to work with, but slow as poo poo). The easy handling of concurrency is a nice win, too.
- Go's standard library made it convenient to, e.g. read in JSON files for configs and output PNG files for the rendered image. Support for an HDR format (like OpenEXR) doesn't exist yet, though, but probably not too difficult to write.
- It's a pain in the rear end to debug Go code with GDB, especially with the default settings that make it impossible to peek at the values of some local variables. I've basically resorted to printf-style debugging (better for raytracers, anyway).
- The only C++ feature I really miss is operator overloading (so that I can add/subtract vectors, etc.). The dearth of built-in data structures (hashtable / vector) is annoying, but it hasn't been a serious problem yet.
- OS X support lags -- profiling support is buggy/nonexistent, and gcc-go doesn't support Darwin.

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

Suspicious Dish posted:

They still seem to believe that dynamic linking is the devil, so it's hard to write a solid Go library.

I don't follow, how does not having dynamic linking make it hard to write a good library?

And besides, dynamic linking is coming eventually, it's just not that important to the go team because of what they use it for.

duck monster
Dec 15, 2004

SavageMessiah posted:

I don't follow, how does not having dynamic linking make it hard to write a good library?

And besides, dynamic linking is coming eventually, it's just not that important to the go team because of what they use it for.

Because a heck of a lot of library writing for new languages is about bindings for tried and tested existing C libs.

Has someone got a SWIG thinger working for GO yet?

edit:
:siren: TOOT TOOT http://www.swig.org/Doc2.0/Go.html TOOT TOOT :siren:

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
cgo dynamically links to existing C libraries.

You just can't create Go libraries that can themselves be dynamically linked†.

The statement remains a non sequitur, without further explanation. Though, presumably, it refers either to distribution or being able to dynamically load plugins to applications/libraries.


† Ian Lance Taylor recently said that he would like to make this a priority for Go 1.4 on the dev mailing list.

etcetera08
Sep 11, 2008

Go rules and my company moved to an exclusively Go backend from some old Python and it's been great. Slightly better performance than Python, much easier deployment, static typing, first class testing, good docs, solid std lib. If it had not horrible package management and fewer bugs on OS X I'd recommend it unreservedly. Oh, and generics.

My Rhythmic Crotch
Jan 13, 2011

I have been looking for a new language to try, and I'm on Go now after trying D. I'm stuck on this bit of code:
code:
package main

import "fmt"
import "reflect"

type Master struct {}

func (master *Master) Execute(i int, j int) {
	fmt.Println("did something")
}

func Invoke(any interface{}, name string, args... interface{}) {

	inputs := make([]reflect.Value, len(args))
	for i, param := range args {
		inputs[i] = reflect.ValueOf(param)
		fmt.Println(param)
	}
	
	reflect.ValueOf(any).MethodByName(name).Call(inputs)
}

func main() {
	Invoke(Master{}, "Execute", 1, 2)
}
It panics like so:
code:
panic: reflect: call of reflect.Value.Call on zero Value
But I don't understand why. It seems to be building the list of inputs to pass to Call, so I don't understand why it thinks the inputs are a "zero Value" :raise:

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
Interestingly it panics in the go playground (http://play.golang.org/p/wH-StrUZcT) but runs correctly locally

edit: well, no, misread the code. It doesn't print did something, but it doesn't panic.

edit2: the code didn't copy paste into vim correctly, panics locally as well. Having a fabulous day.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
it was something simple: Master{} needs to be &Master{} as the execute method isn't defined on values of master and reflection unlike go proper doesn't automatically take the pointer.

http://play.golang.org/p/SLTLkRn7dk

My Rhythmic Crotch
Jan 13, 2011

Wow, nice catch. Thanks for that.

Azazel
Jun 6, 2001
I bitch slap for a living - you want some?
Been using Go professionally for over a year now. Love it.

Here's a fancy Riak database driver I wrote: https://github.com/riaken/riaken-core

My Rhythmic Crotch
Jan 13, 2011

Another oddity: http://play.golang.org/p/BMtgxj-0Af

Unmarshaling any number always gives me a float64 :raise:

Is there a way to force encoding/decoding an integer? I'm reading the json encoder but not seeing it.

Copland
Apr 27, 2014

Azazel posted:

Been using Go professionally for over a year now. Love it.

What kind of projects do you use it for? I love the philosophy of Go, but what has always kept me from putting the effort into learning it was thinking that I wouldn't get much mileage out of it in my day-to-day life.

Just so you know where I'm coming from, I use Ruby a lot to automate workplace tasks. Most of the code I write is imperative, but I do take advantage of the methods that come with the standard classes.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
If you don't give it anything more specific to encode into, that's what you're going to get.

http://play.golang.org/p/Vauuun8fRP

This is documented: http://golang.org/pkg/encoding/json/#Unmarshal

Azazel
Jun 6, 2001
I bitch slap for a living - you want some?

Copland posted:

What kind of projects do you use it for? I love the philosophy of Go, but what has always kept me from putting the effort into learning it was thinking that I wouldn't get much mileage out of it in my day-to-day life.

Just so you know where I'm coming from, I use Ruby a lot to automate workplace tasks. Most of the code I write is imperative, but I do take advantage of the methods that come with the standard classes.

Standard boring work stuff has been along the lines of RESTful microservice APIs using net/http, gorilla/mux, etc. No more wasting time with web frameworks, configuring web servers, unicorns, or rainbows. I've tinkered with realtime game servers communicating over TCP and/or my cgo ENet wrapper (buggy!) quite a bit recently. The standard library is so small and easy to remember, I'm more inclined to write one off scripts in Go than a scripting language these days.

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

Copland posted:

What kind of projects do you use it for? I love the philosophy of Go, but what has always kept me from putting the effort into learning it was thinking that I wouldn't get much mileage out of it in my day-to-day life.

I use Go a bit at my job as well. I tend to reach for it for things where I previously used ruby - to write little development tools and scripts. The fact that it produces statically-linked executables makes it much easier for me to hand them out to other folks who might not have the same stuff installed. I've been doing a lot of development on a device that runs a very stripped down linux on ARM and it's really nice to be able to easily make tools or scripts to try poo poo out in a rational language (not sh) and then trivially cross-compile them.

EDIT: Also, for those not in the know - Gophercon was last week. Apparently videos of the talks should be up in 2-3 weeks.

SavageMessiah fucked around with this message at 16:47 on Apr 29, 2014

Copland
Apr 27, 2014

SavageMessiah posted:

The fact that it produces statically-linked executables makes it much easier for me to hand them out to other folks who might not have the same stuff installed.

Between this and the simple standard library mentioned by Azazel, I think I will give it a try. It really does sound right up my alley.

I just hope that I don't run into too many frustrations with it on the Mac.

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

Copland posted:

Between this and the simple standard library mentioned by Azazel, I think I will give it a try. It really does sound right up my alley.

I just hope that I don't run into too many frustrations with it on the Mac.

I do pretty much all of my personal programming on a Mac and haven't run into any bugs or problems with Go there.

etcetera08
Sep 11, 2008

My Rhythmic Crotch posted:

Another oddity: http://play.golang.org/p/BMtgxj-0Af

Unmarshaling any number always gives me a float64 :raise:

Is there a way to force encoding/decoding an integer? I'm reading the json encoder but not seeing it.

json doesn't have the concept of other number types. http://golang.org/pkg/encoding/json/#Unmarshal
You can, however, force it to use Numbers. http://golang.org/pkg/encoding/json/#Decoder.UseNumber

Azazel
Jun 6, 2001
I bitch slap for a living - you want some?

Copland posted:

I just hope that I don't run into too many frustrations with it on the Mac.

I develop exclusively on Mac, cross-compiling my linux server builds with zero problems. You'll be fine.

Save yourself some trouble when you setup your environment by reading this: https://code.google.com/p/go-wiki/wiki/GOPATH

Bozart
Oct 28, 2006

Give me the finger.
I've got to say that I'm really loving this language. It is simple enough to follow easily (particularly coming from Scala) and the std lib is just a fantastic learning tool.

Coffee Mugshot
Jun 26, 2010

by Lowtax
If you're going to write Go code, please do read the language specification: http://golang.org/ref/spec. It is simple and straightforward. Also, stop trying to write code from your pet language in Go syntax.

EDIT: Another thing not mentioned in the OP. ALWAYS use gofmt to format your code before uploading it anywhere or w/e. Most of the popular editors have support for doing this on save.

Also, you probably won't run into any problems with Go on Mac, given that Rob Pike and Robert Griesemer exclusively develop Go on macbooks.

Coffee Mugshot fucked around with this message at 23:03 on May 1, 2014

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
a weird thing about go is that it uses its own linker and calling convention which is bizarre for a language that wants to replace c++

theres an ok ffi though

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal
The talks from Gophercon are starting to come online here: http://confreaks.com/events/gophercon2014

Huragok
Sep 14, 2011

Voted Worst Mom posted:

If you're going to write Go code, please do read the language specification: http://golang.org/ref/spec. It is simple and straightforward. Also, stop trying to write code from your pet language in Go syntax.

For the love of all that is sweet and holy, please do this. If other popular languages had a tool (from inception of the language) like this then my eyes would not have to bleed every time I had to look at the source of something. Sometimes it's so bad that it triggers a "context switch" in my head.

Scaevolus
Apr 16, 2007

SavageMessiah posted:

The talks from Gophercon are starting to come online here: http://confreaks.com/events/gophercon2014

Rob Pike(Keynote) posted:

Larry Page suggestion "function" be spelled "func".

Q: What are your plans regarding versioning and dependency management?
A: That's something that the open-source community is handling. We're not doing that.

Q: Are there any plans for generics?
A: There are no plans for generics.

Scaevolus fucked around with this message at 21:34 on May 7, 2014

Deus Rex
Mar 5, 2005

This thread ought to "go" ... back to GBS that is! :c00l:

etcetera08 posted:

json doesn't have the concept of other number types. http://golang.org/pkg/encoding/json/#Unmarshal
You can, however, force it to use Numbers. http://golang.org/pkg/encoding/json/#Decoder.UseNumber

JSON's only concern with numbers is their parse; their representation upon deserialization is an implementation decision. An implementation typically uses 64-bit floats only for compatibility with the lowest common denominator prosumer of JSON: Javascript.

Deus Rex fucked around with this message at 22:24 on May 7, 2014

etcetera08
Sep 11, 2008

Deus Rex posted:

This thread ought to "go" ... back to GBS that is! :c00l:


JSON's only concern with numbers is their parse; their representation upon deserialization is an implementation decision. An implementation typically uses 64-bit floats only for compatibility with the lowest common denominator prosumer of JSON: Javascript.

OBVIOUSLY I meant "encoding/json" when I said "json," hence the proceeding link.






















Thanks for the clarification.

Jaded Burnout
Jul 10, 2004


Huragok posted:

For the love of all that is sweet and holy, please do this. If other popular languages had a tool (from inception of the language) like this then my eyes would not have to bleed every time I had to look at the source of something. Sometimes it's so bad that it triggers a "context switch" in my head.

I find it very difficult to read both BNF and the arch lexicon used in these and other language specs.

It's great as an implementation reference but as something supposed to teach me idiomatic Go it's just about the last thing I want to sit down and read.

Bozart
Oct 28, 2006

Give me the finger.
I am starting to suspect that the real reason they chose the name "go" was because it would allow an infinite number of puns :tinfoil:

Coffee Mugshot
Jun 26, 2010

by Lowtax

Arachnamus posted:

It's great as an implementation reference but as something supposed to teach me idiomatic Go it's just about the last thing I want to sit down and read.

Well, nothing about the specification really teaches you how to write idiomatic Go so that's warranted. The best way to learn that is probably reading Effective Go and literally reading through parts of the standard library you find interesting. It's just profound to me that I can even sit down and scarf down a language specification without necessarily learning a whole new set of paradigms.

Anyways, I think the post you quoted was referring to using the `gofmt` tool to format your code.

Bozart
Oct 28, 2006

Give me the finger.
So, I wrote up a function which takes a channel, and returns a new interface which can replay the values in the original channel, and only pulls values from the original channel lazily. Maybe some of you have some suggestions / criticisms of it? I wrote it after some guy on the go-nuts irc channel said it wasn't possible, gently caress that guy. :argh:

http://play.golang.org/p/Ou4HbvKIay

actually, this is so much better:

http://play.golang.org/p/H4awi7EmSY

Bozart fucked around with this message at 05:52 on May 13, 2014

Jaded Burnout
Jul 10, 2004


Voted Worst Mom posted:

Well, nothing about the specification really teaches you how to write idiomatic Go so that's warranted. The best way to learn that is probably reading Effective Go and literally reading through parts of the standard library you find interesting. It's just profound to me that I can even sit down and scarf down a language specification without necessarily learning a whole new set of paradigms.

Anyways, I think the post you quoted was referring to using the `gofmt` tool to format your code.

Ah. They didn't quote that bit in their quote. Now it makes more sense.

minidracula
Dec 22, 2007

boo woo boo
For shame, Go thread. 1.3 was just released and there's no post? :smith:

Mr. Glass
May 1, 2009
The new analysis features in godoc are awesome. :stare:

Adbot
ADBOT LOVES YOU

greatZebu
Aug 29, 2004


In particular, channel peer annotations are fantastic.

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