2

I try to understand why Smalltalk is sometimes called "dynamically typed" and not "untyped" which i also read a lot and which seems to make perfect sense.

There are no type annotations for variables, parameters and method returns in Smalltalk - so what would you compare the type of an object (if you say the type of the object is it's class) to?

Also dynamically typed is not the same as dynamically type-checked? So if Smalltalk was dynamically typed it would mean, that internally Smalltalk does give types to variables, parameters, method returns at runtime? does it?

Helene Bilbo
  • 1,142
  • 7
  • 20

4 Answers4

4

"Dynamically typed" is widely used in certain programming language communities to mean "dynamically checked". Likewise, in more theory-oriented circles it is widely regarded as being technically misleading, because what is being checked is not types in any formal sense of the word. However, that usage is far too common these days for any chance of correcting it.

See also my answer to the inverse question for a bit more background.

Community
  • 1
  • 1
Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72
  • But what is it, that is "dynamically checked"? I mean what can be checked? Assignments and method calls? Are assignments "checked" in any way in Smalltalk?? And message sends are dynamically bound to methods - but is there any "checking" done? Does "MessageNotUnderstood" count as "checking"? – Helene Bilbo Jul 17 '12 at 14:27
  • Well, for certain primitive operations you have to check that something is an instance of a certain class, I presume. This is e.g. the case with primitive "binary methods", such as addition for example. – Andreas Rossberg Jul 17 '12 at 18:14
  • So do i understand it right this way: - A language can have a static type system, if it doesnt it is called "untyped". - A language can be dynamically (type) checked, in this case type means something different than in "Static Type System" - The two concepts are not even mutually exclusive. – Helene Bilbo Jul 18 '12 at 07:42
  • 1
    Yes. In fact, most typed languages still have some amount of dynamic checking, for properties that aren't tracked by their respective type system. For example, all mainstream languages need to check for 0 when doing integer division. Languages with more broken type systems, e.g. Java, also need to perform checks for more innocent operations, such as assignments to arrays, or even plain field access. (Ignoring languages with completely unsound type systems here, such as C++, which just crash.) – Andreas Rossberg Jul 18 '12 at 09:46
4

One convention is to compare programming languages along two dimensions:

  • A continuum from Dynamic Typing to Static Typing
  • A continuum from Strong Typing to Weak Typing

Dynamic Typing often means that the types are not checked at compile time, whereas they are for Static Typing.

Strong Typing often means that types at run-time are of a distinct type which never changes, whereas Weak Typing means that the underlying type can be changed according to context.

It is said that Smalltalk has Strong Dynamic Typing.

quamrana
  • 37,849
  • 12
  • 53
  • 71
4

For a thorough discussion of static/dynamic types and implicit/explicit types, you may want to check: http://blogs.perl.org/users/ovid/2010/08/what-to-know-before-debating-type-systems.html

Damien Cassou
  • 2,555
  • 1
  • 16
  • 21
2

In Smalltalk each object has its type - class which defines operations that can be carried over its instances (and how). So when you send some object a message its class checks if that message can be processed and how.

On the other hand in contrast to statically typed languages, variable can over the lifetime of program contain different objects of different types, so there is no variable (or argument) based type checking.

As an excellent article suggested by Damien points out - concept of type is quite different in statically and dynamically typed languages. This difference can lead to a lot of confusion if direct comparison is attempted.

Davorin Ruševljan
  • 4,353
  • 21
  • 27