News for hackers. Stuff that matters.
Re:New in Go 1.20: wrapping multiple errors by shakow on Sunday December 11, 2022 @09:04AM (#33943260)
> which start make sense as long as you use them and put some thought behind the reasons of the design

Hard disagree. I have been using Go at my company for years, and these features still make no sense to me.

> lack of enums

Not even talking about the eyesore that is the magical const/iota combination (oh yes, your constant definition are scope-dependent, remember to never screw up a copy/paste), go enums are basically C #define. And I think that the consensus has been, for decades, that having badly typed magical constants was not a good thing.

> implicit interfaces

Implicit interfaces are OK when you want to cow-boy your way through through prototyping. When I go back to your code 3 years later, it's a huge obstacle. OK, so you have this function that takes a FooBar. Oh, FooBar is an interface. Great, now I'll have to pull a rickety 3rd-package or ‶just grep bro″ through the whole code base to find what types implement this interface. And God forbid I needed to extend this interface and missed to add the new method to one of the 32 types implementing it, so that it blows on my face in prod at 3AM.

> by popular urban myth

Tell me exactly who finds that nil pointers are a great thing in a high-level language?

Re:New in Go 1.20: wrapping multiple errors by cube2222 on Sunday December 11, 2022 @09:14AM (#33943352)
> And God forbid I needed to extend this interface and missed to add the new method to one of the 32 types implementing it, so that it blows on my face in prod at 3AM.

The language has static type-checking. If to you it's a regular thing that something like this blows up in your face, maybe it's the code base doing too many things dynamically, and not the language?

> Great, now I'll have to pull a rickety 3rd-package or ‶just grep bro″ through the whole code base to find what types implement this interface.

Or just use any of the popular Go code editors/plugins which give you a "show me all implementations".

In general, implicit interfaces let structures and functions require much less by defining their needed functionality subset, instead of requiring the whole "domain interface" from somewhere else.

If you have a struct that only needs to list an S3 bucket, it's nice to accept an interface that only requires listing, and not the other 30 methods the AWS library "full" interface has. This makes understanding what a piece of code is doing much easier, while simplifying mocking as well.

I do agree that enums, or even better, sum types, would be desirable. It's not a big issue in my day to day, though.

Re:New in Go 1.20: wrapping multiple errors by shakow on Sunday December 11, 2022 @09:33AM (#33943533)
> The language has static type-checking.

No it does not, at least not completely. When you carry around pointers to struct implementing interfaces, it does not check for anything at compile time.

> Or just use any of the popular Go code editors/plugins which give you a "show me all implementations".

Does not work all the time, hence my use of the ‶rickety″ adjective.

> This makes understanding what a piece of code is doing much easier, while simplifying mocking as well.

That's a design problem, not an interface problem. Split you giant 30-methods interface into smaller ones if need be, that the whole point of interfaces: not be a 1-1 mapping to methods, but a semantic (sub)group of them.

Re:New in Go 1.20: wrapping multiple errors by cube2222 on Sunday December 11, 2022 @09:52AM (#33943667)
> That's a design problem, not an interface problem. Split you giant 30-methods interface into smaller ones if need be, that the whole point of interfaces: not be a 1-1 mapping to methods, but a semantic (sub)group of them.

It really isn't. This way it becomes a guessing game "Which methods will be used with which other ones?".

Even if I have a KVStore interface with 4 methods: Get, Set, List and Delete, it's a huge value to future code readers if my new structure only accepts an interface with List and Get, or List and Delete.

The other commenter already responded to your static typing assertion, so leaving that for there (it absolutely does check it).

Re:New in Go 1.20: wrapping multiple errors by za3faran on Sunday December 11, 2022 @03:06PM (#33946912)
> it's a huge value to future code readers if my new structure only accepts an interface with List and Get, or List and Delete.

But that's not specific to golang. You can use the same approach in Java, Kotlin, C#, etc

Re:New in Go 1.20: wrapping multiple errors by cube2222 on Sunday December 11, 2022 @03:59PM (#33947425)
Unless I'm missing something, you then have to write wrappers that translate between the big and the small interfaces, or explicitly mark all interfaces as implemented at the original type definition point.

The first one is a lot of boilerplate, the second one is not always possible.

Re:New in Go 1.20: wrapping multiple errors by foldr on Sunday December 11, 2022 @09:40AM (#33943586)
>When you carry around pointers to struct implementing interfaces, it does not check for anything at compile time.

What exactly do you mean here? You can't assign a value that doesn't implement an interface Foo to a variable of type Foo. That will cause a compile time error.

Re:New in Go 1.20: wrapping multiple errors by pjmlp on Sunday December 11, 2022 @09:31AM (#33943520)
> Or just use any of the popular Go code editors/plugins which give you a "show me all implementations".

And me thinking the Go culture is against languages that tend to come with IDEs...

Re:New in Go 1.20: wrapping multiple errors by cube2222 on Sunday December 11, 2022 @09:53AM (#33943678)
Go culture, like any other, is diverse.

I prefer to use an editor/IDE and don't think it's pleasant to work with any language (including Go) without them.

Re:New in Go 1.20: wrapping multiple errors by za3faran on Sunday December 11, 2022 @03:07PM (#33946923)
Not to mention how slow it becomes in large projects
Re:New in Go 1.20: wrapping multiple errors by foldr on Sunday December 11, 2022 @09:34AM (#33943548)
You don't need an IDE to do that. More or les anything that can hook up with the Go language server will do the job.
Re:New in Go 1.20: wrapping multiple errors by pjmlp on Sunday December 11, 2022 @09:48AM (#33943642)
So somehow needing a language server to work around language design flaws is alright for Go then.
Re:New in Go 1.20: wrapping multiple errors by foldr on Sunday December 11, 2022 @11:41AM (#33944709)
Sarcasm aside, I do think it’s fair to assume that someone writing code in a modern programming language in 2022 has access to basic language-aware editor tooling. That’s the beauty of the language server. You can look up the implementations of an interface from vim, or some other minimalist development environment, if that’s your bag.
Re:New in Go 1.20: wrapping multiple errors by masklinn on Sunday December 11, 2022 @12:04PM (#33944960)
"Go is so simple you don't need an IDE to write it, unlike java"

"Well obviously you need a proper IDE to protect you from Go's fuckups"

Cool.

Re:New in Go 1.20: wrapping multiple errors by foldr on Sunday December 11, 2022 @12:40PM (#33945341)
You don’t need an IDE, as I explained in my two preceding posts in this thread. Please at least try to respond to someone who is actually making the arguments that you take yourself to be refuting.
Re:New in Go 1.20: wrapping multiple errors by saturn_vk on Sunday December 11, 2022 @04:39PM (#33947846)
> Implicit interfaces are OK when you want to cow-boy your way through through prototyping. When I go back to your code 3 years later, it's a huge obstacle. OK, so you have this function that takes a FooBar. Oh, FooBar is an interface. Great, now I'll have to pull a rickety 3rd-package or ‶just grep bro″ through the whole code base to find what types implement this interface.

Language servers are a thing nowadays, and the standard go one will find all implementations before you finish blinking. Why is this considered harder than whatever you are using to find implementations in your language of choice?

> And God forbid I needed to extend this interface and missed to add the new method to one of the 32 types implementing it, so that it blows on my face in prod at 3AM.

So like every other language with interfaces then? But why are you even compiling in prod at 3AM in the first place?