3

I am really confused about the concept of Strongly typed programming language (AKA type safety enforcement). Based on multiple definitions from Wikipedia source I can conclude from how I understood it that Type safety is really about what can and cannot be done with a language as predicted by the language itself (correct me if I am wrong)..

This made me remember glancing through an article that talked about binding. It got me all confused as to if there is any relationship between static/dynamic type safey assertion and static/dynamic binding of fields..

For example an Integer variable int two = 1; is statictly binded to its value, trying to assign a string value "1" to integer an variable will result in a compile time error like int one ="1";. I consider this a type safety approach implemented by static binding. Am I wrong thinking this way? Please enlighten my understanding of this concept.

4
  • 2
    Could you give some examples of what you mean by "static type safety assertion", "dynamic type safety assertion" and "dynamic binding of a field"? A lot of the terms you're using are either non-standard or--like "strongly typed"--standard only in the sense that everyone has their own favorite definition and there is no usable definition everyone agrees on. – Ixrec Mar 14 '16 at 11:44
  • An example of "static type safety assertion" would be the language disallowing assignment of type char one = '1'; to int one; Dynamic binding of field would be comparison to allow or disallow assignment the type of data and the type of value assigned to it to be paired. – Nexima360 Mar 14 '16 at 11:50
  • 2
    @Nexima360: I think what you call "static type safety assertion" and "static binding of fields" are one and the same thing, and the same as what is usually called "static typing." – JacquesB Mar 14 '16 at 12:22
  • You didn't say what programming language, and, what binding means is different in different programming languages. For the C/C++/C#/Java family of languages int a = 1 is a variable declaration with an initializer, which is considered an assignment, rather than a binding. For these languages the compiler will statically (i.e. at compile time) check the assignment for legality (i.e. type checking, other things). The compiler will generate code to execute the assignment at runtime. (Logic languages, on the other hand, have a powerful notion of bidirectional binding.) – Erik Eidt Mar 14 '16 at 12:51
2

No. Type system and binding are distinct concepts.

The type system as the name says has to do on who and how the types themselves are checked. The binding has to do with the link between the data or code/operation and the names (of procedure, variable). Related to binding is also the term of dispatch, which has to do with how/when it's decided which operation is performed. It happens that binding is confused with dispatch.

Let's take as example Java:

Type system is:

  • static: you must specify types when you declare them so the compiler checks
  • strong: compiler checks the types of the operations and don't allow if not matching

Binding can be of both types:

  • static: in static functions using static fields
  • dynamic: when using Reflection or when having dynamic dispatch (see below)

Dispatch can be of both types:

  • early: when using calling static methods
  • dynamic: when calling virtual methods, allowing polymorphism

Taking C as example:

Type system:

  • static: you must define the types when you use them
  • weak: you can add an int to char for example

Binding:

  • static: the compiler does all the stuff

Dispatch:

  • static: as above, it's decided at compile time what functions are called
2
  • A little complex, but will ponder on it – Nexima360 Mar 14 '16 at 13:50
  • 3
    Careful with the terminology - what Nexima360 calls binding in the original question is not binding of methods as in the sense of dynamic or static linking or dispatch, but is the the assignment of a value to a variable. – JacquesB Mar 14 '16 at 14:38
0

I think it is more about declaring the type vs. run-time type resolving. And of course being able to change bound variables' types after initialization. For example c#'s Implicitly Typed Local Variables doesn't change its static typed checking feature. But if you use dynamic it is totally different. Compiler can't warn you when using dynamic keyword.

To summarize, it is the explicit declaration of types and static analyze of the compiler.

You can examine Typescript if you want how static type checking implemented in a non type checking language: JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.