4 ms·
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
by BadBadJellyBean 6mo 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.
- calcifer 6mo ago> 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.
- BadBadJellyBean 6mo agoIn 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.
- calcifer 6mo agoThat's surely the correct behaviour?
- BadBadJellyBean 6mo agoIt 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.
- avanai 6mo agovar _ 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.
- BadBadJellyBean 6mo agoThat is helpful but I think that is still a fail for Go. This could and should be a simple annotation.
- pdmccormick 6mo agoThis 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.
- BadBadJellyBean 6mo agoThis 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.