473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Non-Type Safe Example

I have read the documentation from msdn to try to understanding the concept
of "Type safe". Would someone give me an example of code segment
illustrating what is *Non* type safe?

Many Thanks,
Jeff.
Nov 21 '05 #1
2 1878
"Jeff Chan" <je**@macro.com.hk> wrote in message
news:Oe**************@TK2MSFTNGP15.phx.gbl...
I have read the documentation from msdn to try to understanding the concept
of "Type safe". Would someone give me an example of code segment
illustrating what is *Non* type safe?


It's hard since you can't write unsafe code in VB, and VB has always been
Type Safe. You can write terrible code with dozens of hidden
InvalidCastExceptions and NullReferenceExceptions, but you can't violate the
type system. To be Type Safe is to obey the type system, to access memory
only through the methods of declared types.

In the beginning, programs viewed their memory as an undifferentiated extent
of bytes. Then C added types and structs to give names to the bits. But in
C you can always directly access any area of memory, and the compiler will
allow almost any assignment. This direct memory access causes both
dangerous bugs and vectors for malicous code. For instance a "buffer
overrun" is a simple programming error in a non type-safe language which can
be exploited by a malicous client.

VB is verifiably Type Safe. This means that a VB program simply cannot have
a buffer overrun or a memory leak. A VB program cannot generate an access
violation, or touch any area of memory it isn't supposed to. And you can
verify all this at runtime, so you don't have to trust the programmer to use
the right compiler switches or to not make mistakes.

David
Nov 21 '05 #2
Hi Jeff,

Here is an example:

Dim notTypeSafeCollection As New Collection()
notTypeSafeCollection.Add("John")

notTypeSafeCollection.Add(1)

notTypeSafeCollection.Add(New Object())

Notice that I can add any object to the collection. If I decided to use it to store account objects I could accidently store a non-account object in the collection. The collection is not type safe.

and here is a link to an article on how to create a type safe collection:

http://www.devcity.net/Articles/66/1...ollection.aspx
--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com



"Jeff Chan" <je**@macro.com.hk> wrote in message news:Oe**************@TK2MSFTNGP15.phx.gbl...
I have read the documentation from msdn to try to understanding the concept
of "Type safe". Would someone give me an example of code segment
illustrating what is *Non* type safe?

Many Thanks,
Jeff.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
22
by: Steve - DND | last post by:
We're currently doing some tests to determine the performance of static vs non-static functions, and we're coming up with some odd(in our opinion) results. We used a very simple setup. One class...
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
13
by: asm23 | last post by:
Hi,I need some help to clarify the warning "initial value of reference to non-const must be an lvalue". I'm searching in this groups to find someone has the same situation like me. I found in...
9
by: Francois Grieu | last post by:
When running the following code under MinGW, I get realloc(p,0) returned NULL Is that a non-conformance? TIA, Francois Grieu #include <stdio.h> #include <stdlib.h>
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.