tl;dr– Science is weakly typed rather than either duck-typed or strongly typed.
Points:
Duck-typing isn't about type-determination, but rather ignoring types entirely.
You probably meant to ask about "weak typing", where things can be considered ducks if we're able to frame them as such.
Yes, science is weakly typed.
1: Duck-typing isn't about type-determination, but rather ignoring types entirely.
Duck typing isn't about determining an object's type, but rather about not caring. As far as duck-typing is concerned, all objects are of the same, implicit type; any variance in behavior is up to the object itself.
For example, in C#:
class DuckObject
{
private Dictionary<string, Action<object>> MethodDictionary { get; set; }
public void Call(
string methodName
, object methodArgument
)
{
this.MethodDictionary[methodName](methodArgument);
}
}
Then instead of writing x.Quack();
, we'd write
x.Call(
"Quack" // Name of the called method
, new object[] { } // Arguments object, which contains no subordinate arguments in this case.
);
.
In other words, x
is duck enough for the purpose of .Quack()
'ing like a duck if it can .Quack()
.
2: You probably meant to ask about "weak typing", where things can be considered ducks if we're able to frame them as such.
In weakly typed languages, x
is a duck if we can frame it as one.
For example, in C#:
((Duck)x).Quack();
Weak-typing is stronger than duck-typing because it's not enough for something to .Quack()
like a duck to be a duck; instead, we must be able to coerce something into being a duck.
Weak-typing is weaker than strong-typing because it doesn't require something to be a duck so long as it can be regarded as a duck.
3: Yes, science is weakly typed.
Scientific models work when we can make them work. For example, cows can be spherical when such a description is adequate.
Which is to say that, yes, a duck is a duck when such a description is adequate. Even if it's actually an advanced robot pretending to be a duck, it's still a duck if it's close enough, but it isn't if it isn't.
In practice, scientists, engineers, etc., tend to work with models that they know to be imperfect.
This isn't a duck-typing logic because it's not enough for something to merely have some shared quality with its abstract representation.
This is a weak-typing logic in that requires something to be framable as its abstract representation.
This isn't a strong-typing logic in that there's no need for something to be its abstract representation.
x + 3
, the duck-typed programming language simply sendsx
a request to launch a method (possibly calledadd
) with the argument3
, and hopesx
knows what to do with it. It will work with every number. It might work for other objects, depending ifadd
is defined. If not, an error will be sent.duck + 3
probably won't work.