Re: Precise types & retyping

Daniel Bonniot <[email protected]> Sat, 21 Feb 2004 11:49:28 +0100
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
>>No. That means that in package A you choose a certain policy, in B a 
>>different one.
>>    
>>
>
>I don't understand. What is a "policy"? 
>
A policy is the declaration of how Java types have to be interpreted as 
Nice types, in the absence of more specific retyping.

>Isn't it true that when compiling
>package A, different types will be used for methods in org.eclipse.swt than are
>used when compiling package B? Or, in other words, each method in
>org.eclipse.swt is given two types (one for package A, one for package B)?
>  
>
Yes, it's true.

>>I agree that normally there should be an "ideal" retyping for a given 
>>Java library. It's not always obvious, though, because many methods do 
>>not specify if they accept null arguments, under what circumstances, if 
>>any, they can return null, ...
>>    
>>
>
>I know, but I think that the compiler should enforce that the same set of
>retypings is used in each importing package for a given program. It doesn't make
>sense to say "I _know_ this method accepts null values for its parameters" in
>part of a program and then in another part of the same program, say "I _know_ it
>doesn't accept null values for its parameters" 
>
"I" might not be the same person. These two people can decide to 
consider imported Java methods with different types for valid reasons, 
because:
  1) There might not be a "true" type for it, since as I said Java 
methods are often underspecified.
  2) They might choose different levels of static checking. I know that 
this might sound strange. In pure Nice code, you don't get this choice, 
and that's completely deliberate. But using Java code makes the 
situation a bit different. Consider this: in Java, you can set the value 
of System.out. Which means that you can set it to null, brain dead as 
this idea might be. Should all printing code look like:
  let out = System.out;
  if (out != null) out.println("...");
That does not sound reasonable. In nice.lang I decided to retype also 
setStdout so that setting System.out to null is not possible from nice 
code. But you have no guarantee a Java method you call will not do it.
This situation can happen with various degrees of likeliness for the 
"exceptional case" to occur, in which case individual programmers might 
make different decisions about what type to give.

>My suggestion was that the user should create a file
>"org/eclise/swt/typing.nice" that contains the package declaration, and possibly
>other specific retypings for that package, so that all retypings for
>classes/methods in org.eclipse.swt are defined in this file (and _only_ this
>file). This way, every field and every method is prescribed exactly one type for
>all source code of the entire program. 
>
It seems you are assuming that there is only one author, a world-wide 
central repository of retypings or no independent development of 
packages, which does not seems reasonable.

Besides, there is no issue with different packages making different 
assumptions being combined. The retypings only affect the internals of 
the packages, not their public interface.

Daniel



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click