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 Dave Beck on may 14, 2016

Good post—it offers a quick summary of various typing paradigms. I’ve referenced it in my post comparing JavaScript to a cockroach.

commented by Josh on june 24, 2015

Short, concise, and straight to the point. Thanks!

commented by Tharanga Abeyseela on december 21, 2015

Short and Sweet . Thanks for the post.

commented by prednisoneDow on february 22, 2016

Hiya user. 2+0+1+6

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 Sayying Ayoub kokabi on july 08, 2014

Elaboration was very nice. short and useful.

commented by Kerry on november 28, 2013

What does static keyword mean ?