Hacker News new | ask | show | jobs
by BadBadJellyBean 41 days ago
I can write go but I don't prefer it. It's ... okay.

Things I dislike:

- if err != nil. Just give me some syntactic sugar instead of letting me write the same thing a bajillion time.

- no way to bind a struct to an interface. I'd like my IDE to tell me when I accidentally stopped implementing an interface

- some stdlib parts are too bare bones. Unpacking an archive requires me to handle all files, directories, links, etc. myself. There is no move command that can move a file or directory across fs boundaries. The little things.

2 comments

    var _ MyInterface = &MyStruct{}

Now your compiler will tell you you stopped implementing the interface. Pretty? No. But it works. And gopls will even offer to implement stubs for missing methods.
This also works:

    var _ MyInterface = (*MyStruct)(nil)
In my mind as I read this, I am reminded that it is the receiver type *MyStruct that implements MyInterface. YMMV.
This is a useful hack but just imagine someone coming from another language reading this. They'd have no idea what it's for. It looks a bit like the things C people do to themselves. And all just because someone didn't want a keyword or another form of annotation to signal that a struct should implement an interface.

These are the small things that annoy me about go.

That is helpful but I think that is still a fail for Go. This could and should be a simple annotation.
> I'd like my IDE to tell me when I accidentally stopped implementing an interface

I don't know about others, but Goland's analyser is pretty powerful and can navigate from interface to implementation(s) and vice versa.

In my experience only when you implement it correctly. If I add a new method to the interface I can't navigate to the implementations anymore because they don't completely implement the interface.
That's surely the correct behaviour?
It is. But it's also an inconvenience. In a language like Java I can just say that a class implements an interface. If the interface changes the compiler and the IDE tell me about the missing methods. Go not so much.