comp.lang.ada
 help / color / mirror / Atom feed
From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: Type safety on wikipedia
Date: Fri, 27 Jan 2006 12:34:29 +0100
Date: 2006-01-27T12:34:29+01:00	[thread overview]
Message-ID: <43DA0545.8030904@mailinator.com> (raw)
In-Reply-To: <87fynaajuh.fsf@mid.deneb.enyo.de>

Florian Weimer wrote:
>>Even with unchecked conversion Ada has the 'Valid attribute, allowing
>>the programmer to determine if the result of an unchecked conversion is
>>a valid value.
> 
> 
> Only in very limited cases.
> 
> 
>>I do not see how Unchecked_Deallocation interferes with type safety.
> 
> 
> The following is just a rough sketch, but maybe it helps to clarify
> the terms.
> 
> A type system gives you a subset of all expressions which are
> well-typed (in Ada, 1 + 1 is well-typed, but 1.0 + 1 is not).
> 
> A type-safe language has a type system with these two properties: any
> well-typed expression which is not a value can be reduced to a simpler
> expression, according to a set of run-time evaluation rules (which
> define the semantics of the language) -- and these simplification
> steps preserve the well-typedness of expressions.
> 
> (Of course, considerable notational overhead is needed to apply this
> definitions in a rigorous manner to real-world programming languages.)
> 
> Now, suppose that X is a pool-specific access value for some type T,
> and Free is a corresponding instance of Ada.Unchecked_Deallocation.
> Suppose that
> 
> 
>    Free (X);
> 
> has just been exected.  Suppose the next thing to be evaluated is
> 
>    declare
>       Y : T := X.all;
>    begin
>       ...
> 
> Now X.all is not a value, so it has to reduce (at run-time) to some
> other expression.  But the language definition explicitly tells you
> that no such rule exists.  Therefore, the first rule I mentioned is
> violated, and Ada with Ada.Unchecked_Deallocation is not type-safe.

Thanks for your effort in making us understand. However, there's still 
something fundamental that I'm not grasping.

According to the current Wikipedia article, Java is believed to be type 
safe. However, one can have null pointers in Java. For example:

public class Test {
	public static void main (String args[]) {
		Integer x = new Integer (5);
		Integer y = null;
		
		System.out.println ("X + Y: " + (x + y));
	}
}

will compile without warnings with latest JDK1.5 and run as:

$ java Test
X: 5
Exception in thread "main" java.lang.NullPointerException
         at Test.main(Test.java:7)

This means that Java has explicit rules for when this happens that 
differ from those in Ada? Since Ada also detects null pointer usage, and 
per your example it makes Ada type unsafe.

Conversely, I understand that evaluations that yield out-of-range values 
don't make a language type-unsafe because these cases have well-defined 
rules of behavior.

Maybe I should go now to read the original paper linked from the wikipedia.



  parent reply	other threads:[~2006-01-27 11:34 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-26  7:28 Type safety on wikipedia Martin Krischik
2006-01-26 11:58 ` Alex R. Mosteo
2006-01-26 17:10   ` Martin Krischik
2006-01-26 20:24   ` Simon Wright
2006-01-26 20:43     ` Simon Wright
2006-01-27  6:58       ` Martin Krischik
2006-01-26 23:43   ` Bobby D. Bryant
2006-01-27 11:14     ` Alex R. Mosteo
2006-01-27 11:57       ` Martin Krischik
2006-01-27 15:30         ` Larry Kilgallen
2006-01-27 19:04           ` Martin Krischik
2006-01-27 22:06             ` Larry Kilgallen
2006-01-28  7:04               ` Martin Krischik
2006-01-29 21:48               ` Florian Weimer
2006-01-27 12:43       ` Georg Bauhaus
2006-01-26 13:49 ` Rod Chapman
2006-01-26 17:05   ` Martin Krischik
2006-01-26 18:14   ` Martin Krischik
2006-01-26 13:53 ` jimmaureenrogers
2006-01-26 15:18   ` Alex R. Mosteo
2006-01-26 16:49     ` Martin Krischik
2006-01-26 18:19       ` Alex R. Mosteo
2006-01-26 20:38         ` Simon Wright
2006-01-27 11:13           ` Alex R. Mosteo
2006-01-27 19:38             ` Simon Wright
2006-01-27 23:24               ` Randy Brukardt
2006-01-28  6:53               ` Martin Krischik
2006-01-27 18:58           ` Martin Krischik
2006-01-27 19:50             ` Simon Wright
2006-01-28  6:52               ` Martin Krischik
2006-01-26 19:22     ` Dmitry A. Kazakov
2006-01-26 19:07   ` Florian Weimer
2006-01-27  0:38     ` jimmaureenrogers
2006-01-27 18:54       ` Martin Krischik
2006-01-28  1:48         ` Jan Andres
2006-01-28  6:44           ` Martin Krischik
2006-01-31  2:13           ` Randy Brukardt
2006-02-06  5:02       ` Dave Thompson
2006-02-06  8:29         ` Larry Kilgallen
2006-01-27 11:34     ` Alex R. Mosteo [this message]
2006-01-27 12:18       ` Martin Krischik
2006-01-27 15:27       ` Florian Weimer
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox