Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Type safe language

 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
What do we mean by type safe language ?
Hari
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Type-safe refers to a language's built-in checking for type compatibility. For example Java will not allow assignments of a variable with wider width to a variable with a shallower width.
For example, the following Java code fails to compile:

But the following C code does compile:

Type safety goes much further in Java when it comes to reference checking but you get the idea.
[ October 16, 2002: Message edited by: Leslie Chaim ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact, there are two forms of type safety:
There are weakly versus strongly typed languages. Java and Smalltalk are strongly typed languages - they will give you an error if you try to use an object as an inapropriate type (for example by throwing a ClassCastException). C++ is a weakly typed language - you can cast any object to any type, the program will just try to interpret the bytes at the memory location accordingly (with sometimes devastating results...).
Then there are dynamically versus statically typed languages. In statically typed languages like Java and C++, the validity of calling a method is determined at compile time - polymorphism is bound to the inheritance hierarchy. In dynamically typed languages like Smalltalk, method calls are verified at runtime, based solely on method signatures - polymorphism and inheritance are totally orthogonal in these languages.
Does that help?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic