What is type safty in dot net?

J

Jon Skeet [C# MVP]

Bhuwan Bhaskar said:
What is type safety in Dot net?

Well, that's a very broad question. What's the context? What exactly
are you trying to find out?
 
S

Scott M.

Essentially, it means that the compiler won't let you treat an apple like a
trampoline.

In other words, the compiler looks at the "type" you are working with in
your statements and makes sure that you only do things with or to that type
that are allowed for that type.

C# has this automatic type-safety built in by defalut. With VB .NET, you
must change the Option Strict setting in Tools...Options to On (the default
is off).

-Scott
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Scott said:
Essentially, it means that the compiler won't let you treat an apple like a
trampoline.

In other words, the compiler looks at the "type" you are working with in
your statements and makes sure that you only do things with or to that type
that are allowed for that type.

C# has this automatic type-safety built in by defalut. With VB .NET, you
must change the Option Strict setting in Tools...Options to On (the default
is off).

VB.NET is actually type safe regardless of the Option Strict setting.

With the setting off it allows a lot of implicit conversions that is not
allowed in strict mode, but the conversions are still type safe. If the
conversion would produce an unusable result, you get a runtime error
instead.
 
S

Scott M.

Well, I think when most folk talk about type-safety, they are referring to
design-time, not run time. After all, with your definition, you could make
the argument that VB .NET is also bug-safe, since you'll get a runtime
exception or runtime anomoly when the program encounters bugs. If there
were such a thing as a bug-safe language, you'd expect it would indicate a
bug as your were creating the bug.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Scott said:
Well, I think when most folk talk about type-safety, they are referring to
design-time, not run time.

Then they are confused, as that is strong typing, not type safety.
After all, with your definition,

The definition is not mine.
you could make
the argument that VB .NET is also bug-safe, since you'll get a runtime
exception or runtime anomoly when the program encounters bugs.

Not at all. A bug can very well result in a perfectly normal result,
even if it isn't the correct result.
 
B

Bhuwan Bhaskar

Hi Göran,

what are your views for 'type safety' and 'strongly typed' in dot net. I
will be obliged if you make my concept clear on these terms.

Thanks,

Bhuwan
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Bhuwan said:
what are your views for 'type safety' and 'strongly typed' in dot net. I
will be obliged if you make my concept clear on these terms.

A type safe language won't allow operations or conversions that can give
an illegal result.

For example, converting a Long to an Integer i VB.NET will check that
the value is actually possible to store in an Integer.

A strongly typed language enforces type conversions to be explicit.

For example, with Option Explicit On VB.NET will not implicitly convert
a string to a number, but with Option Explicit Off, it will.


Type safety:
http://en.wikipedia.org/wiki/Type_system#Safely_and_unsafely_typed_systems

Type strength:
http://en.wikipedia.org/wiki/Type_system#Strong_and_weak_typing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top