[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Type safety (was: Language War (Re: "C" Manual))



Richard Cobbe <cobbe@airmail.net> wrote on 01/01/2002 (19:04) :
> 
> No, type-safety is important.  Type-safety makes several guarantees, but
> the most important for our purposes is the following:
> 
>     If an expression E has (static) type T, then the result of
>     evaluating E is *always* one of two things:
> 
>         * the evaluation throws an exception which escapes beyond the
>           boundaries of E (or otherwise signals an error condition)
> 
>         * E's value is a valid object of type T and not some random
>           collection of bits.
> 
> In particular, this means that if p is of type pointer to T, then
> dereferencing p will *always* give you a valid T.
> 
> Languages generally do this by restricting the set of pointer values
> (and such restricted pointers are usually called `references' [1]).  For
> instance, in LISP and Scheme, there is exactly one way [2] to create a
> reference to a list: call the function CONS, and the return value is
> your reference.  The language guarantees that, if CONS returns (as
> opposed to throwing an exception), its result is a reference to a valid
> list.

Another advantage of strict typing is that the compiler will catch a lot
of your bugs that you will have to debug for hours to find with a
language such as C or C++. Ada 95 is a OOP language that has strict
typing.  Ada was designed with three overriding concerns: program
reliability and maintenance, programming as a human activity, and
efficiency.

After switching from C/C++ to Ada 95 I found again the joy in
programming. The main reason is that as soon as a program compiles and
can be quite certain that it will work as I intended. When I compile C
or C++ I don't know as the compiler won't catch nasty bugs that makes
the program segfault. Also it is very hard to make buffer overflows
vunerable programs due to range checking etc...

If you want to learn more about Ada 95 check out:
http://www.adapower.com/. You will also find free text books online to
learn the language along with ISO reference manual, Style Guide and
Rationale.

PS: I don't want to start a flame war on which language is better, but I
have found that a lot of C/C++ programmers have never heard about Ada 95
and a lot of people have been interested in the language when learning
more about it.

Preben
-- 
«Don't use C;  In my opinion,  C is a library programming language
 not an app programming language.»  - Owen Taylor (GTK+ developer)

Use Ada 95, a free language. More info at http://www.adapower.com/



Reply to: