static vs dynamic vs strong vs weak vs duck typing

posted by alexis reigel on march 19, 2012

Here’s my take at clearing up the confusion about the most common type systems used in programming.

I often hear how static and strong typing are used as synonyms. These two are however quite different systems. The same applies to dynamic and weak typing. For instance, a programming language can be both dynamically and strongly typed, but not dynamically and statically. Ruby is an example of a dynamically and strongly typed language.
Ok, I guess now it’s the time to elaborate.

static vs dynamic

  • static: types are checked at compile time
  // example in c#

  string s = "asdf";
  • dynamic: types are checked at runtime
  # example in ruby

  s = "asdf"

strong vs weak

  • strong: types must match, only explicit conversion
  # example in ruby

  "1" + 1 # TypeError
  • weak: implicit type conversion
  // example in javascript

  "1" + 1 // "11"

duck typing

Duck typing is a style of dynamic typing.With duck typing, the set of methods and properties determine the valid semantics of a class, instead of inheritance from a specific class or implementation of an interface.
“When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.”
This means that we actually don’t care if the class we’re using is actually of a certain type, as long as it provides the methods or properties we’re interested in.
The term duck typing comes from python, but ruby is also very known for this behaviour.

commented by Justin on september 13, 2013

Many thanks for anotehr great article. Where else could anybody get that sort of information in such an ideal way of writing? I have got a presentation the week after next, and I am on the look for such information.I like this internet sites. Actually i occasionally visit that web sites i think i must write long sentence.

commented by Kerry on november 28, 2013

What does static keyword mean ? http://net-informations.com/faq/general/static.htm

Kerry