Golang thread

Redpill me on golang, Sup Forums. Let's say I'm coming from Rails. Is it worth learning? Can it replace Ruby in general?

Other urls found in this thread:

gopl.io/
gobyexample.com
golang.org/doc/effective_go.html
twitter.com/SFWRedditImages

A lot of people use Rails 'front end' and Go for the backend/systemy shit. For example the site memorycorruption.com is done this way.

Go is really good tool for specific things. Depends what you want to do, get the Kernighan book gopl.io/

Go is one of the best programming languages out there. For every criticism of Go, there are ten more criticisms for the alternatives to Go.

It's a meme

Assume I've only ever used Rails and nothing else. What's the canonical way of building a basic website that just lets you add to and display stuff from a database?

>Is it worth learning?
yes
>Can it replace Ruby in general?
yes

It'll take you a weekend to learn you a Go if you're coming from another language.

gobyexample.com
golang.org/doc/effective_go.html

You've probably never even used it.

Go is the best language of this generation.

the standard library has quite a bit of good stuff for basic websites. there are some very good third party libraries that are amazing for creating scalable web applications.

Go really is quite good.

Go is great If you wanna replace ruby on rails
Its alright for making small automation scripts
Thats pretty much all of its use case

bump

/thread

Then again, once Crystal rises - if Crystal rises - it can't replace that one, because muh generics and macros and LLVM backend.

What does it offer that Python or Java don't?

Simplicity, speed, and easy concurrency.

Both are achievable in Python or Java.

Elixir is replacing Ruby

Go is retarded and dying

>Can it replace Ruby in general?
Yes but don't expect being able to use magic libs that do 90% of your work like in Ruby.

...but you can, with third party libraries.

Yeah but they're not as "magic" as the Active Record's ORM for example.

NO

GENERICS

>muh generics
I bet you don't even know what this means.

it means you will never be able to write a piece of reusable code in go.

Spoken like someone who has never written anything in Go.

Sounds like you don't know SHIT about programming.

Spoken like someone who has never written anything of substantial size in their life.

Spoken like someone who hasn't either.

Generics create needless complexity and take a fuckton of time either at runtime or compile time.

t. someone who has never written anything of worth

t. Someone who is grasping at straws.

Interfaces, reflection, and type assertions eliminate the need for generics. If you had half a fucking brain you'd know this.

keep telling yourself that. Bad hacky implementations used for pseudo generics will never be the real thing and will never work like the real thing.

>work like the real thing
Yeah, I enjoy the fact that I don't have to wait literal hours for my program to compile because someone though generics were a good idea. Keep living in the past, grandpa.

Have you considered purchasing a computer built after 2006?

>he thinks the solution to monumentally slow compile times is to just buy faster hardware.

buy all the fastest hardware you want, you'll still have horrendous compile times when dealing with generics*.


* in an actual production environment, which I'm sure you have no actual experience in, otherwise you'd know what I'm talking about.

>i don't know how to use this feature or compile my programs properly
>ban generics

you the kinda nigga to create include loops.

>well those straws aren't gonna grasp themselves!

Generics allow you to do things like iterate through types that are considered "generic" arrays, even if that type isn't specified exactly within the functions. Generics can be unsafe and with a language like Go, you need lots of safety. Network programming requires lots of error checking and for code to be concise.

Generics ARE hacky code generation you fucking retard. You're using generics as a crutch because you aren't a good coder.

Look at Rust

Woah back up, people are still using ruby?

>"coder"
back to redd!t

All that RoR shit written a few years ago aint gonna maintain itself.

>Go is really good tool for specific things
Back-end.

Is it advisable to write a web app using just the stdlib? I'm looking for something like Rails or even just Flask but I'm not sure what my options are in Go.

Any suggestions on reading material?

So I want to write a game server

would it be more fun to write it in C/C++ or Go?

>inb4 "you're posting in a Go thread"

I thought GO was specifically good for micro services like API back ends

The 'go' in golang stands for 'garbage-oriented'

Do you want your server to lag and crash for no apparent reason every 5 seconds? If so, use go. Otherwise, go with literally anything else.

>Go with literally anything else

That makes for a good slogan

Yes and yes.

Fucking stupid.

Reusable code is a meme. Write a fucking library.

What are you on about?

Go's networking package is beautiful, so you'll be fine.

>garbage collection

>being a code ricer
>thinking you have better taste than the unix authors

enjoy your uncontrollable lag spikes

Go > D > JavaScript > Rust > C > Python > Ruby > Perl > Lua > Bash > PHP > C++ > Java

actually go's gc has a time-bounded mark & sweep pause, and most mark & sweep pauses are less than a millisecond even for big heaps

you can use even use go in a real time system provided its pause constraint is within your own constraints

golang? more like goylang.

Hello rob pike. Come to rub someone's spike?

The Go GC is optimized for latency, but not throughput. If you have hard constraints in both areas I don't think Go is the right tool for the job.

Unfortunately, the rest of the language is so mindnumbingly retarded (taking all the bad parts of previous languages, with none of the good) that go is never the right tool, for any job.

I don't think the design of the concurrency aspect was bad, as well as the choice to use OO with interfaces. That being said, there's obviously alot of pain points in the language which would not make me want to choose it for most potential uses.

root@sv3 ~ $ cat hello.go
package main

import "fmt"

func main() {
fmt.Println("Hello World")
}
root@sv3 ~ $ go build hello.go
root@sv3 ~ $ ls -lh hello
-rwxr-xr-x 1 root root 1.5M Dec 6 00:07 hello


1.5 megs for a simple hello world...

Solution: don't create garbage in your event loop or whatever. You wouldn't do it in C.

Sure you can try to do stuff like memory pools and other optimizations to ensure that the GC performs exactly the way you want it to, but at that point are you really benefiting that much from it over just writing it in C/C++?

>I don't think the design of the concurrency aspect was bad
That's really the best part of the language. That's the selling point of the language and also the reason that Rust initially looked very promising (but then Rust's designers fucked it all up).

>taking all the bad parts of previous languages, with none of the good
What are you even talking about? 0 examples.

>go is never the right tool, for any job.
Why, then, do I invariably reach for go when writing a new program? The one exception is writing GUIs, in which case I usually reach for Tcl/Tk or C with libiup.

It's unreasonable, yes. Pike's bug report of "binaries too large and still growing" is still active.

>do stuff like memory pools and other optimizations
No, just use the compiler's escape analysis switch, which will tell you what code is incurring heap allocations. In most programs, heap allocations are rare, and you soon learn to identify patterns that incur heap allocations.

Don't do retarded things like returning pointers to objects that are local to functions, since that's a pattern which necessarily gets moved to heap.

The stdlib is the "standard", but it's verbose.

Look at Gin. It is a lightweight framework for web servers.
It really lends to short code. There is middleware available for common needs like setting secure http headers, managing session cookie data, csrf protection, etc.

Writing your own authentication system is the norm.

[user@x220t /tmp] cat out.go ok
package main

import "fmt"

func main() {
fmt.Println("Hello World")
}% [user@x220t /tmp] go build out.go ok
[user@x220t /tmp] du -hs out ok
1.6M out
[user@x220t /tmp] strip out ok
[user@x220t /tmp] du -hs out ok
1000K out
[user@x220t /tmp] ./out ok
Hello World

Sadly strip breaks Go binaries on Windows. Go follows the PE standard more closely than Windows.

so build with upx or dynamically linked with gccgo if filesize is such a concern, but I personally don't think it is. I work in c++, and would be happy to have go build speed in exchange for binary size

it's statically linked.