Hacker News new | ask | show | jobs
by geenat 1356 days ago
Love go as a platform.. self contained binaries have been a miracle for ops..but have a few big hangups about using the language full time because of the sucky ergonomics.

* No optional/named parameters. Writing a whole function per parameter for function chaining is excessive. This would not be difficult to add to the compiler (i've done it and have seriously considered using the fork) but it seems like the team is just stubborn about adding stuff like this.

* No default struct values. 0 isn't good enough in real world scenarios.. have fun writing BlahInit(...) for everything.

* Would be nice to get the question mark syntax for error handling. Error handling shorthand for if err != nil would also be very welcome.

3 comments

> No default struct values

I love Go too but this does drive me nuts, especially when parsing JSON and wanting to set sane defaults for missing values. Like, for example, booleans that should default to "true".

For that use case, I think that you can assign your defaults before passing your target struct to the unmarshaller.

The unmarshaller will iterate on the json input and set struct fields when json fields are found. This means that struct fields that don't match the json are ignored, and values you have set before will be left as is.

While true, this approach doesn’t work for nested structs, which are instantiated by the parser.
Write a DefaultFoo function which returns a Foo with default values set. Then unmarshal into that.
I think if Golang would have been invented a couple of years later it def would have had sum types. But then, Rust probably wouldn’t have had its insane tooling that is most likely inspired by golang
It’s not like sum types weren’t known a decade before that. Or generics. They just didn’t care.
These issues were also brought up immediately when the language was first shown, alongside nulls, tuples, error handling, etc…
what imperative language had them?
I doubt it. It seems quite apparent that Thompson just wanted to take another stab at creating the next generation in the B -> NB (New B) -> C -> Go family tree. It would have likely been named D if the name wasn't already taken.

Pike slapped his Newsqueak's CSP paradigm on top and the rest is history.

Go is basically an AOT compiled version of Limbo with the method syntax and UNSAFE package from Oberon-2, and they stopped there.
> I think if Golang would have been invented a couple of years later it def would have had sum types.

How to combine sum types and a precise garbage collector?

They're not mutually exclusive. Scala and Haskell had them for a long time now, and Java got them relatively recently.
How can a precise garbage collector work when it does not know if a value is or is not a pointer?
I agree. I wonder if we'll start to see other languages target the Go platform, like with the JVM.