DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

How can I learn to like Golang? (and use it a lot)

I don't Golang because,

  • I cannot set nil a variable (unless it is a pointer, but not sure if it is recommended to do so?)
  • GoDoc is restricted to // and isn't Markdown friendly. gofmt doesn't recognize /** */.
    • Actually, VSCode formatter can give colors to JavaDoc/JSDoc styled /** */ as well.
  • Centralized ~/go/pkg/packages/github.com/<NAME>/<PROJECT> structure, instead of my custom ~/projects/<PROJECT> structure
    • Actually, sometimes it is a monorepo, so ~/projects/<PROJECT>/packages/backend
  • Golang maker don't like vendorizing, like what node_modules do.

Rust's Cargo seems to be more happy with me, but it is a different language.

Top comments (21)

Collapse
 
stojakovic99 profile image
Nikola Stojaković

No need to like something you just don't like. I've tried Go dozens of times and gave up. I feel too limited writing it and prefer Rust and C++ for system programming.

Collapse
 
benzo profile image
Ben

If these are the only things to not like about Go, that is pretty good for a programming language.
Go is standardised by design. Its “limitations” is more a fact of simpler design. Working on multiple projects with many developers, Go code always looks the same. There are not many ways to be super clever and fancy which leads to easier collaboration and improved readability.

Collapse
 
lffg profile image
Luiz Felipe Gonçalves

Totally agree with you. The only real problem I see with Go is the lack of generic types. That one is a harsh.

At least they are planning to add it in the future.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

I haven't tried Golang much, but I still have to compare Golang to Kotlin, if I want it strict.

For non-strict, I would still use TypeScript.

Perhaps Generics mean some convenient inheritance???

Thread Thread
 
lffg profile image
Luiz Felipe Gonçalves

Here is the TypeScript documentation about genetics:
typescriptlang.org/docs/handbook/g...

I’ve never used Kotlin, but I believe that it has generic-like features, like Java.

Collapse
 
ryands17 profile image
Ryan Dsouza • Edited

+1 for this. The lack of generics make writing more code which is why I prefer how TypeScript and Rust has handled the type system.

Collapse
 
serhatteker profile image
Serhat Teker

Agree; those what makes Go Go and what makes Go so good.

Collapse
 
robbiegm profile image
RobbieGM

That sounds like a fancy way to say "Go lacks many important features"

Collapse
 
benzo profile image
Ben

Generics I agree. What else are those important features that you miss?

Thread Thread
 
robbiegm profile image
RobbieGM • Edited

I was mostly talking about generics, but it also lacks proper exceptions, enums, and two ways to assign a variable (var and :=) among other things

Thread Thread
 
mikeschinkel profile image
Mike Schinkel

Lacking proper exceptions is one of Go's best features. Consider:

Collapse
 
louy2 profile image
Yufan Lou

There is no way to go back to a incomplete, unsound, and generally haphazard type system like that of C++, Golang, Python, JavaScript once I have had a taste of the type system of an ML, i.e. that of Rust, OCaml, F#, or Haskell.

Collapse
 
gayanhewa profile image
Gayan Hewa

I like working with Go lang, for most of the stuff you have mentioned.

  • Use of nil
    Coming from a background in PHP, I have dealt with code where null is misused immensely. So with go, I know that usage is limited. And I always have to depend on the default values for each type.

  • GoDoc has a simplified structure.
    And it's not overly bloated. I only have to document stuff that is public from a package.

  • Centralized
    This is no longer the case since we are moving away from GOPATH

  • Dependency management
    node_modules is one of the worst things I have worked with, I still work with node / Typescript for work. I still don't like it. With go, I used to use dep but since deprecating GOPATH, I have moved all my projects to use go mod

It's a given that some of these things might not appeal to everyone. I guess it's going to be a common thing, based on the experience we have with different programming language ecosystems. One major thing I prefer Go is due to the standard library.

Collapse
 
rhymes profile image
rhymes

Hi Pacharapol!

I cannot set nil a variable (unless it is a pointer, but not sure if it is recommended to do so?)

Though by default variables are "zeroed", you can still do it, by using the empty interface:

var i interface{}
// the variable is empty
i = 10
// now its value is 10
Enter fullscreen mode Exit fullscreen mode

Centralized ~/go/pkg/packages/github.com//

not really true anymore if you use go modules, packages will be in your project's directory. See blog.golang.org/using-go-modules

Golang maker don't like vendorizing, like what node_modules do.

go mod vendor. See github.com/golang/go/wiki/Modules#... and go help mod

Hope this helps :)

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

Thanks. I might try Golang again. There seems to be a lot of packages in Golang as well, actually, just like Python.

There is still an issue with GoDoc, as I mentioned above. And it mostly correlate with Swagger Codegen, as well as comment highlighting. But it is not that some languages like Python doesn't have this problem as well.

Nowadays, I rely a lot on Fastify's Request + Response validation --> and it seems that someone have ported in to Golang for me -- github.com/danielgtaylor/huma/

Again, yeah, Golang has so many packages that it might be worth it.

TBH, if I want strictness, I still have to compare Golang to Kotlin.

Collapse
 
rhymes profile image
rhymes • Edited

There is still an issue with GoDoc, as I mentioned above. And it mostly correlate with Swagger Codegen, as well as comment highlighting. But it is not that some languages like Python doesn't have this problem as well.

If there's one suggestion I can leave you with is not to try to bend Go to be similar to other languages :D Just "go with the flow" (no pun intended)

You won't find Go code with /* syntax anyway. You can find more info on Godoc here: blog.golang.org/godoc

Nowadays, I rely a lot on Fastify's Request + Response validation --> and it seems that someone have ported in to Golang for me -- github.com/danielgtaylor/huma/

I'm not familiar with Fastify or Huma but Go is pretty awesome at JSON validation having those inline tags:

type Data struct {
  Something string `json:something`
}
Enter fullscreen mode Exit fullscreen mode

which tell the JSON serializer to map the field automatically :D

I think Go is worth a try, at least! Start with gobyexample.com/ :-)

Collapse
 
louy2 profile image
Yufan Lou

I do not think Golang is a language worth learning if it is not for work. It does not add anything new to your knowledge. This is on purpose. It has avoided many modern programming language features in exchange for fast compile times, faster new developer on boarding and simpler cross-compiling support. For expanding your horizon on how to express ideas, Haskell really is THE eye-opener.

On the other hand, if you can see past your preferences and stop worrying, Golang generally takes well care of you. Decide on a domain problem and code away. You may find lack of distracting language features actually helpful.

Collapse
 
wagslane profile image
Lane Wagner

"go mod vendor" vendors packages.

Since go 1.11 you don't need to use the gopath.

Why would you want to nil a variable? Use the zero value... That's what it's for.

You gripes come from some misunderstandings.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

Why would you want to nil a variable? Use the zero value... That's what it's for.

Of course, so that's how it is designed, right?

I still dislike GoDoc style and integration with VSCode is not as powerful and color as JSDoc or JavaDoc. Even RustDoc's /// feels better.

GoDoc hates multiline commented markdown, to be exact.

If you view this in VSCode, it will be broken -- towardsdatascience.com/setting-up-...

Collapse
 
wagslane profile image
Lane Wagner

I mean, yeah Godoc doesn't support markdown, but I argue that's a good thing. Comments should be brief and to the point, not formatted novels

Thread Thread
 
pclundaahl profile image
Patrick Charles-Lundaahl

+1. If your code needs multi-paragraph comments, I think your code probably needs to be clarified.