Hacker News new | past | comments | ask | show | jobs | submit login

There's a way to make channels easy to use and abstract. Just make a typecast function. Details in a comment on the original post.

The idea is that you create a library which communicates using channel interface. Great. Now you need to add `i.(myType)` wherever. So, create a function that accepts an interface, switches on type (switch i.(type)) and returns a value with your concrete type.

It's a 6-liner solution to most of this rant about channels.




In a statically typed language, it shouldn't be necessary to break type safety to implement basic abstractions. The only thing interface{} provides over void* is safe typecasting.


In other statically typed languages you don't break type safety to implement abstractions.

In go, where interfaces are implemented by default and `interface{}` covers everything, you also don't need to. It's just a little bit (~6 lines) of code to add to guarantee it while they figure out a nice way to add generics.


Well that's not to be sneezed at, even though it remains crude.




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

Search: