News for hackers. Stuff that matters.
Re:Are dynamic languages going to replace static languages? ... by dbt00 on Wednesday August 04, 2021 @02:02AM (#28057709)
Go's interfaces are a great example.
Re:Are dynamic languages going to replace static languages? ... by sidlls on Wednesday August 04, 2021 @10:44AM (#28061575)
Not really. It’s a terrible approach that permits some really, truly awful patterns that the designers should have known better than to permit. But it’s not really “go is dynamic!”
Re:Are dynamic languages going to replace static languages? ... by IshKebab on Wednesday August 04, 2021 @03:52AM (#28058413)
Go interfaces aren't dynamically typed. They are statically duck typed, like C++ templates.
Re:Are dynamic languages going to replace static languages? ... by majjgepolja on Wednesday August 04, 2021 @05:30AM (#28058991)
I guess the word is structural typing.
Re:Are dynamic languages going to replace static languages? ... by gefhfff on Wednesday August 04, 2021 @05:28AM (#28058982)
Down voters may express the reason for their action?
Re:Are dynamic languages going to replace static languages? ... by wizhi on Wednesday August 04, 2021 @02:10AM (#28057753)
What makes Go's interfaces dynamic in nature?
Re:Are dynamic languages going to replace static languages? ... by zmmmmm on Wednesday August 04, 2021 @04:35AM (#28058663)
they are "duck typed" .... so an object automatically implements an interface if it has methods with the right signatures to satisfy the interface.

It's handy if you need to add interfaces onto code you don't control (say, library code) as you can avoid a whole layer of adapter types / functions that you need in true statically typed languages.

But I'm curious if its a great idea in the long run to have interfaces being "accidentally" implemented by objects. Doesn't seem like it would stand up well to refactoring or various other scenarios.

Re:Are dynamic languages going to replace static languages? ... by kaba0 on Wednesday August 04, 2021 @05:58AM (#28059171)
Than it’s the age-old war between nominal and structural typing. The latter can be really comfortable and productive, but as you note, it may be less safe (eg. just because I have a next method doesn’t mean I want to make it an iterable or something like that. It can easily break class invariants)
Re:Are dynamic languages going to replace static languages? ... by Zababa on Wednesday August 04, 2021 @10:53AM (#28061687)
Isn't this more "structurally typed" rather than "duck typed"? From what I've seen, duck typing implies dynamism, while structual typing implies static types. Go is clearly statically typed. So no, Go interfaces are not dynamically typed, they are structurally typed, which is static.