4 ms·
> I thought that using an empty interface to represent "any type" was kind of ingenious It makes me a bit sad to read that. We all are on a journey to be becom
by valenterry 5y ago
> I thought that using an empty interface to represent "any type" was kind of ingenious
It makes me a bit sad to read that. We all are on a journey to be become better developers every day. But things like that are like a distraction. They make you think you found a really cool and smart concept, but you actually didn't and it's essentially just a hack.
Not sure what the solution can be. But PL designers should be more clear about features that are just "hacks" and considered "bad" but necessary in practice due to certain constraints. Go's {} and nil-errorhandling are examples. Nulls (in any language) are another common example.
- Lhiw 5y agoNulls aren't a hack they're the not yet set state. The problem is that languages don't create both nullable and non nullable types. Forcing everything to use options which infect everything with guarding at every layer of the stack is just as bad as nullable types. That is, nullable types aren't the problem, never was, the problem is developers not dereferencing them at the edges of code boundaries and using non nullable types internally. E.g. in rust, the first point you encounter an option type should be the point you handle the optionality of it and deref into a standard type with the value. From then on, your code is so much freeer.
- laumars 5y agoThat’s a very condescending way of say “I don’t personally like this feature”.
- the-alt-one 5y agoIt's not a hack, it's the natural way of expressing it in the chosen type system. The use cases for interface{} are often hacks, because of a lack of parametric polymorphism, but that's different.