Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is basically a hack to get pragmatic performance at a cost of comprehensibility. It would have been better if Go allowed union types then a func could be declared to use interface A|B efficiently. Passing a narrow interface when a wider implemented one could get used is lying about the actual "interface" in the signature. Added to that is that Go's interfaces are structural (which I think are great), but could lead to accidental misuse by passing in interface A for an object that also has method X for unrelated purposes that co-incidentally satisfies interface B which the called func on A magically uses.

> Like all articles about Go’s interfaces, we are obligated to start with Go’s io package.

Also the io package, or stdlib in general is not a good place to look for good patterns to use in Go. Numerous antipatterns are used in the name of performance. The principles for stdlib authors and recommendation for Go developers are different. As an example io functions can return a value AND an error--and whether to continue or not depends on the specific error (as some are benign). It's better that I don't name an example as you should always be on the lookout for (until having learned) them.



> It's better that I don't name an example as you should always be on the lookout for (until having learned) them.

"this gun will shoot you in the foot in some cases. It's better that I don't name an example as you should always be on the lookout for (until having shot yourself in the foot) them"


They are all documented in the io package. There's no point in telling you just one of them. But you have to RTM which was my point.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: