News for hackers. Stuff that matters.
Re:Is Go Duck-Typed? by lkitching on Wednesday March 04, 2020 @03:43PM (#22487858)
I'm not sure what you mean by 'not exact' since the article you posted explictly contrasts duck typing with structural type systems of which Go is given as an example.
Re:Is Go Duck-Typed? by Footkerchief on Wednesday March 04, 2020 @05:26PM (#22488827)
The contrast in the Wikipedia article is:

> Structural typing is a static typing system that determines type compatibility and equivalence by a type's structure, whereas duck typing is dynamic and determines type compatibility by only that part of a type's structure that is accessed during run time.

That sounds like static vs. dynamic implementations of the same thing.

Re:Is Go Duck-Typed? by lkitching on Thursday March 05, 2020 @05:04AM (#22492326)
The fact that one is checked statically and the other is only enforced at runtime is a significant different between them, since the static approach will reject some programs that are dynamically safe. The term duck typing when employed by dynamic languages like Ruby is misleading since it's a consequence of not having a type system at all.
Re:Is Go Duck-Typed? by derefr on Wednesday March 04, 2020 @06:05PM (#22489130)
When you're talking about type systems, "dynamic" really doesn't make much sense to talk about. It's not like the runtime constructs a typing model out of its observations of the properties of objects' runtime interactions. The notion of there being a "type" to a duck-typed object is purely a theoretical one; in practice, the object just does whatever it wants moment-to-moment, and the runtime has no idea.

Consider a generic "proxy" object that can be arbitrarily disconnected and reconnected to objects of different types. These can exist in any duck-typed runtime system. What is such an object's "type", even in the sense of its "runtime type"? There isn't one. There might be a sense in which it has an instantaneous type—a type it has as of a given program world-state—but that information is inaccessible to the runtime, since any probing it might do to ascertain this might also cause the object's instantaneous typing to change in the middle of the probing procedure.

(See also: the Universal Server in Erlang [ https://joearms.github.io/published/2013-11-21-My-favorite-e... ]. What is this server's "type"?)

A type system is something that can make guarantees about the behavior of a program in advance. In that sense, duck-typing isn't really a type system. It's just asking objects questions and then blindly trusting the responses you get. There's nothing but convention guaranteeing that an object that e.g. in Ruby implements `respond_to?` a certain way, will _actually_ respond to those methods when they're called. The object can lie. Which means you don't have a guarantee, and so you don't have a type system.

Re:Is Go Duck-Typed? by gowld on Wednesday March 04, 2020 @08:16PM (#22490012)
Arguing about definitions is old and boring. https://en.m.wikipedia.org/wiki/Type_system