Hacker News new | ask | show | jobs
by masklinn 700 days ago
In my experience this really is not an issue. There’s an intentionality to using objects and you’re not a maddened fuzzer trying to plug random objects into arbitrary functions with no rhyme or reason.

It’s essentially a less likely version of using the wrong callback, something which has undoubtedly happened in the fullness of time but is of no real concern.

No in my opinion the issue is the opposite: implicit structural interfaces make it harder to discover what interfaces a type implements, and what you can do with it.

A secondary effect being that mismatches have worse reporting, whether you’re trying to implement an interface or the interface has changed from under you the compiler only reports use site so from there you have to did out what the type is and why it does not conform anymore, things get worse if side casts are involved. There’s actually a pattern for checking conformance:

    var _ Iface = (*Type)(nil)
Mmm yummy.

Oh yeah and if the interface removed a method and you didn’t realise you might be dragging that useless methods for a long while. Then again it’s not like your Java-style interface is any different.

1 comments

> Oh yeah and if the interface removed a method and you didn’t realise you might be dragging that useless methods for a long while. Then again it’s not like your Java-style interface is any different.

In C# I usually use explicit interface implementations. (They're inconvenient to type, but Rider has a macro for it.) When the interface changes or disappears, my code won't compile.

Didn’t know that existed. It’s a bit of a half assed version of half of type classes but it’s an improvement that this is at least available.

Can you also implement interfaces on types you didn’t define?