Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is type-safety?

I had a brainbench exam recently, got high mark, but there were a couple of questions which were hard for me. Maybe it's because english is not my native language... One of the questions is:

Which one of the following describes type-safety?

  1. A programming construct used to ensure the security of reference and value types in the CLR
  2. The protection from memory leakage as a result of disallowing unmanaged access
  3. The CLR-specific feature providing assurances that types may not access memory outside their own AppDomain
  4. A mechanism created to protect assemblies and their types by the use of strong-named keys
  5. The concept dealing with assurances that allocated objects are always accessed in compatible ways

I think it's 1 or 5, but they sound weird to me anyway :(

What do you think?

like image 767
nightcoder Avatar asked May 29 '09 21:05

nightcoder


People also ask

Why is type safety?

In essence, type safe variables are key pillars of a safe and robust program. This is so because the algorithms that use these variables are rest assured that these variables will only take values from a well-defined domain. Thus, this ensures the integrity and quality of the data and the program.

What is type-safe?

TypeSafe means that variables are statically checked for appropriate assignment at compile time. For example, consder a string or an integer.

What is type safety and why is it important?

Type safety is sometimes alternatively considered to be a property of facilities of a computer language; that is, some facilities are type-safe and their usage will not result in type errors, while other facilities in the same language may be type-unsafe and a program using them may encounter type errors.

What is type safety in Python?

Typesafety is a tool for writing type-checked code in Python. In languages like C++, Java, etc., this is a language-level feature, but Python has no such feature. With the advent of annotations it is however possible to write code with type notations. Typesafety is a means to enforce that those notations are valid.


2 Answers

Type Safety is the feature of a language designed to make good on [Robin Milner][1]'s famous slogan about ML programming: well-typed programs cannot go wrong.

The slogan needs some unpacking before it can be properly understood, but it basically means that programs cannot fail because of a runtime type error, i.e. when the parameters applied to constructor or a function have values of incompatible type.

Consider a language that allows integers, integer functions as first class values, function abstraction and partial function application, and which defines the usual integer arithmetic operators as binary functions. The property of type safety is what the compiler enforces to ensure that both of the arguments to the addition operator are expressions that reduce to integers and not to functions. If a program is well-typed, then the compiler can emit an executable object for it. Otherwise, it flags the programming error and aborts.

like image 162
james woodyatt Avatar answered Oct 21 '22 20:10

james woodyatt


Actually I think it's Choice 5 because type safety has nothing to do with Security.

like image 35
oscarkuo Avatar answered Oct 21 '22 22:10

oscarkuo