DEV Community

Cover image for Pitch me on Go
Ben Halpern
Ben Halpern

Posted on

Pitch me on Go

Part of a new series! Feel welcome to dip in and weigh in on a past question.

Let's say I've never used Golang before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.

Discussion (46)

Collapse
natescode profile image
Nate

Pro

  • can be learned in a day
  • can be very fast
  • simple concurrency model
  • single binary output
  • grear standard library
  • good dependency management

Cons

  • sorta functional but lacking
  • bit verbose for more complex code
  • smaller ecosystem
Collapse
codewander profile image
codewander

Coming from scala, clojure, elixir viewpoint, the golang ecosystem is huge and many vendors provide bindings. From a python, node view, golang feels a little smaller.

Collapse
aceix profile image
the.Aceix

Man, u've bee sleeping in dough; niche background

Thread Thread
natescode profile image
Nate

"Sleeping in dough" never heard that idiom before. Language of origin?

Thread Thread
codewander profile image
codewander • Edited on

I have worked in scala and haskell. I haven't used elixir or clojure at work. I used the expression "coming from" to refer to the general perspective of those communities.

Thread Thread
aceix profile image
the.Aceix

Sorry, that means earning some good money

Collapse
peerreynders profile image
peerreynders
  • sorta functional but lacking

First time I've seen that as a euphemism for procedural.

Go FAQ: Why build concurrency on the ideas of CSP?:
"Experience with several earlier languages has shown that the CSP model fits well into a procedural language framework.".

It's a procedural language with a built in coordination model (for something functional you have go with something like Erlang or Elixir).

Collapse
natescode profile image
Nate

Haha yup exactly. It's definitely a euphemism.

Collapse
highcenburg profile image
Vicente Reyes

What's the basis for learning Go in a day?

Collapse
wesen profile image
Manuel Odendahl

I like pointing people who already know programming to "Effective Go". If you have no experience with concurrency and threading, that will take some additional learning. Don't go in there just YOLOing channels and goroutines left and right.

My rules for goroutines:

  • know when, where and why a goroutine is created
  • for every goroutine, make sure it can properly be cancelled
  • for every goroutine, think and design how it would report errors
  • for every goroutine, know exactly when it finishes, and how its results are handled
  • use errgroup to start goroutines, and write actual goroutine bodies as Run(ctx *context.Context, args...) error
Collapse
natescode profile image
Nate

Based on my own experience, as an experienced developer. It is a very simple language. The go playground is a great way to learn. Only the currency model is different than most languages.

Thread Thread
citizen428 profile image
Michael Kohl

It is a very simple language.

While I agree with the overall statement, Go also has a fair few foot guns because the main priority of the Go team has always been keeping the language implementation simple (see New Jersey style), even if that sometimes comes at the cost of simplicity of usage.

Thread Thread
peerreynders profile image
peerreynders

It is a very simple language

"It must be familiar, roughly C-like. Programmers working at Google are early in their careers and are most familiar with procedural languages, particularly from the C family. The need to get programmers productive quickly in a new language means that the language cannot be too radical."

Go at Google: Language Design in the Service of Software Engineering

In Rich Hickey's terms it tends more towards easy (familiar) rather than simple.

Thread Thread
natescode profile image
Nate

True.

Collapse
dominikbraun profile image
DB • Edited on

Go being learnable in a day is a huge misconception about the language. Basic syntax yes, but it takes months to figure out proper package- and project structures.

Collapse
codewander profile image
codewander

Why so long?

Thread Thread
dominikbraun profile image
DB

The language is very opinionated on how to implement things - for example, reading a file or running a web server. There's only one way to do this in Go.

But Go is very un-opionionated when it comes to your code layout and project structure: There is no "default structure", you can create packages as you want, you create files as you want, you can place multiple types and functions within a single file, you can define interfaces inside the package that uses the interface or inside the package that provides the concrete implementation of the interface...

It just takes a time to figure out how to properly structure the code. Go is very liberal in this concern and each project should use a structure that fits best.

Thread Thread
codewander profile image
codewander • Edited on

Why is it unopinionated on how to organize types and functions within modules?

Thread Thread
dominikbraun profile image
DB

In other languages, say, Java, you'd create a file Order.java for your Order class. There's no such convention in Go. You can create a file called order.go containing an Order type, but other types, constants and functions may also be in that file. Go simply doesn't have any restrictions regarding the code structure, and that allows for the best-fitting solution for your use case on the one side but also many possibilities each with their own pros and cons on the other side.

Thread Thread
codewander profile image
codewander

Thanks.

I was more curious about why the leadership is opinionated about error handling, but isn't as opinionated about module conventions.

I understand that in both functional and procedure languages, there is a much larger degree of freedom in how you group together items inside of modules. I haven't done a lot of c programming, but I assume it has very well established patterns for organizing modules by now.

Collapse
natescode profile image
Nate

I meant language basics. Of course everything else takes much longer. I should've clarified. Just saying it is fairly simple.

Collapse
denisgolius profile image
Denis

There are very few libraries for ML and AI... So Python/Scala/C++ and maybe Julia are the most usable for now.

Collapse
codewander profile image
codewander • Edited on

Super fast pr reviews because there are very few choices to make. I don't love go, but that seems like it's strongest selling point relative to scala. It kind of reminds me of the goals of "basic English".

Collapse
citizen428 profile image
Michael Kohl

It's Stockholm Syndrome as a (micro-)service meets the Plan 9 Cinematic Universe.

Of all the languages I regularly use Go is probably the one I'm least excited about. That's exactly why I use it when I do. It's good at some very specific things (networked services, CLI tools), pretty easy to pick up, hard to forget and has decent tooling. Static binaries (with optionally embedded assets) and easy cross-compilation are nice too.

Collapse
wiseai profile image
Mahmoud Harmouch

In brief, GO is a blazingly fast, statically typed programming language that outperforms so many damn dynamically typed languages.

FYI: There is a go version of docker-compose called compose v2. Worth a try. You will never regret that.

Collapse
cpustejovsky profile image
Charles Clinton Pustejovsky III • Edited on

Most if not all languages can be used to be build distributed microservices. With it's focus on package oriented design and concurrency primitives, Go was actually made to build distributed systems. Given how much companies need to scale, it makes Go an excellent tool in their arsenal.

Go also has made the brave decision to remove powerful abstractions like inheritance, function overloading, etc. These may be nice, but they can often bite us in the ass later, and I don't think any developer is trustworthy enough to not to abuse them, especially when they're on a deadline and it's a Friday afternoon.

I think Go is amazing for problems dealing with I/O and where a long term solution is needed.

It may not be the best option for something where you need to be as memory efficient as possible.

Also, as much as I dislike NodeJS, I'd use it over Go for prototyping. An opinionated, statically typed language isn't great for throwing together a disposable prototype.

Collapse
iamschulz profile image
Daniel Schulz

Just look at the mascot.

Collapse
wesen profile image
Manuel Odendahl • Edited on

Pros:

  • get shit done
  • very readable
  • lots of nice libraries
  • all libraries that do async work are easily integratable
  • easy cross compilation + static binaries
  • opinionated toolchain
  • easy to integrate code generation
  • go mod + workspaces finally make it nice
  • faster than most things out there, good enough for serious embedded work

Cons:

  • kind of user hostile (terse tool output)
  • dependency management was a shitshow for a long time (kind of solved)
  • people gloss over the fact that you can easily make big big concurrency booboo if you don't know what you are doing
  • very verbose (github copilot helps a lot)
Collapse
mrwormhole profile image
Talha Altınel • Edited on

well that's easy: Look at the motto "Go will make you love programming again, we promise"

I was easily lost after the burnouts with 7-8 different+bloated languages and hostile communities. If you don't follow CoC of Go, you are not counted as a Go developer. The community and fhe founders of the language made a huge difference and a fresh start in my whole life.

Collapse
raddevus profile image
raddevus

Uh, no one mentioned the real reason to use Go :

Easy to deploy!

1) build 2) give user Executable (single file).

Collapse
perelson profile image
Andrew Perelson

This. Easy cross compile and easy to deploy.

Collapse
drsensor profile image
drsensor • Edited on
  • Fast compile. In fact time of running go run is on par with JIT-ed scripting language like Javascript (node/deno) or Python
  • Unlike scripting language, it produce static binary (though the size is still bigger than Rust, C++, or Zig)
  • Beware of dependency that interop with C or static library (FFI). It can give you bottlenock caused by cgo. There is several solution for this like using gccgo or converting C code via c2go. Those will remove the bottleneck but it's not always works (depend on the dependency you use or C code you want to convert)
  • Coming from Python? Check out Go+
Collapse
pandademic profile image
Pandademic

WARNING: I'm super biased , Go is my favorite language.

PRO:

  • easy cross compiling support
  • reasonably simple language*
  • great dependency management**
  • amazing standard library
  • simple concurrency
  • single binary output
  • hard to forget
  • a wide variety of libraries
  • awesome mascot

CON:

  • not the best environment setup , the first few times around anyway

NOTES:
("1 astrix") reasonably ... somethings take getting used to
("2 astrix") if your environment is setup properly , also , it takes some getting used to

Collapse
acoh3n profile image
Arik • Edited on

Probably my favorite thing about Go is that it's lacking features. While just about every other language is competing for feature parity with other languages, Go seems to be true to keeping to its original philosophy of simplicity over a bunch of features. This makes for code that is generally quite readable and understandable by others because there aren't ten thousand ways to do every thing.

Collapse
k_penguin_sato profile image
K-Sato • Edited on

Easy! The Gopher logo is super cute!

image

Collapse
karanpratapsingh profile image
Karan Pratap Singh

It's very productive language with very powerful concurrency. I also released my course on it recently!

Collapse
leob profile image
leob

They've FINALLY added generics ... :)

Collapse
baenencalin profile image
Calin Baenen

Is Rust gonna be ðe next in your series? :þ

Collapse
alesbe profile image
alesbe

Pitch me on a functional programming language like Haskell or Clojure for the next time! I've never tried functional programming so it could be a nice starting point :)

Collapse
femolacaster profile image
femolacaster

There is a typo, Ben. You mean GO not TypeScript. I would drop my pitch soon.

Collapse
wiseai profile image
Mahmoud Harmouch

Assuming you heard about the most infamous Bill Gates or someone else's words: "I always choose a lazy person to do a hard job, because a lazy person will find an easy way to do it." I am now pretty convinced that even leaders are lazy people too, most likely would be classified as "Lazy Leadership", but in a good way, do you know what I mean? But, It could be a strong indicator of high intelligence as the independent shows.

Collapse
ben profile image
Ben Halpern Author

Fixed, thanks!

Collapse
wiseai profile image
Mahmoud Harmouch

I am going to cite this image in my upcoming research as an inevitable proof of the evolution theory.

wat dat dog doin'

Collapse
wiseai profile image
Mahmoud Harmouch

Yo! what is this community all about? It appeals to me like a mere Reddit page. It made me chuckle as I looked it up. Hahahaha.

Thread Thread
ben profile image
Ben Halpern Author

A fun test ground 😄