Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Tightening the type system

Reply
Thread Tools

Tightening the type system

 
 
Hemal Pandya
Guest
Posts: n/a
 
      07-15-2005
> On 14 Jul 2005 08:05:57 -0700, "Hemal Pandya" <(E-Mail Removed)>
> wrote or quoted :
>
> >Perhaps a typedef with name-equivalence is what Roedy is
> >looking for.

>
> I am looking for something stronger. I want it to catch you adding
> apples to oranges even though both internally and handled with an int.
>
> Further, I think the compiler should catch you assigning something
> measured in lines to something measured in pixels. It could catch
> degree F vs degree C errors.


I would still want the liberty to assign pixels to lines once in a
while.

>
> I first ran into the problem writing a Pascal program years ago to
> implement a super fast, crash proof Btree. There were several arrays
> and many indexes. Variables were associated with an array. Yet the
> compiler could not check that I used a variable of the wrong "type" to
> index an array.
>


In Pascal you should be able to give different type names to ranges of
integers and use those as the index type for the array. I can't recall
the syntax right now.

> I attacked the problem in my own language by giving each array its own
> primary index and naming it the same as the array.


Its own primary index or index type?

As another post suggest maybe Ada is the answer. But I am sure you want
this along with all the flexibility of Java.

 
Reply With Quote
 
 
 
 
Stefan Schulz
Guest
Posts: n/a
 
      07-15-2005
On Thu, 14 Jul 2005 21:03:58 +0000, Roedy Green wrote:

> If you could subclass primitives or subclass finals, but only for the
> purpose of adding additional type constraints, not adding fields or
> functionality, that might let you do something like this:


I disagree. You can already use composition for this kind of typing, and
adding rather arbitrary new constraints to the language does not add
anything useful IMHO. It merely serves to make the entire structure of the
language less logical and consistent.

--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-15-2005
On 14 Jul 2005 23:45:22 +0200, Gordon Beaton <(E-Mail Removed)> wrote or
quoted :

>
>You want Ada.


Ada though requires you to write pages of code to define every new
unit of measure.
--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-15-2005
On 14 Jul 2005 21:17:17 -0700, "Hemal Pandya" <(E-Mail Removed)>
wrote or quoted :

>I would still want the liberty to assign pixels to lines once in a
>while.


Just like the (cast) breaks the other type system.


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-15-2005
On 14 Jul 2005 21:17:17 -0700, "Hemal Pandya" <(E-Mail Removed)>
wrote or quoted :

>> I attacked the problem in my own language by giving each array its own
>> primary index and naming it the same as the array.

>
>Its own primary index or index type?


In abundance you would write something like this:

<<<FOR anycollection height width * . FOR>>>

where height and width are fields of the elements of the collection.
In post fix that computes the area and displays it on the console.

collections are arrays, arrayLists, files etc.

The java equivalent is:

for ( Record r : collection )
{
int area = r.height * r.width;
System.out.printn( area );
}

before Java became more abundance-like you had to say:

for ( int i = 0; i<array.length; i++)
{

int area = r[i].height * r[i].width;
System.out.println( area );
}

Abundance is a DOS based Forth dialect. See
http://mindprod.com/jgloss/abundance.html if you are curious.

If I want to crank out a data entry app, it is far faster in Abundance
than Java and the end product is much faster for high speed data entry
and does far more automatic validation. However, DOS has great
limits, 640K, no gui, all character based.



--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      07-15-2005
On Fri, 15 Jul 2005 08:39:52 GMT, Roedy Green wrote:
> Ada though requires you to write pages of code to define every new
> unit of measure.


Not if you want plain integers, only if you want to restrict units in
the way you were asking earlier in the thread. How much code you
really need to write depends on what you want to be able to do with
your units. Think of them as classes.

Or were you really asking for a compiler that knows and does what you
mean, without you having to specify anything?

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      07-15-2005
On 15 Jul 2005 11:00:31 +0200, Gordon Beaton wrote:
[snip]
> Or were you really asking for a compiler that knows and does what you
> mean, without you having to specify anything?


I was after a DWIMNWIS[1] compiler, but that would be better.
...Does anybody got some codes for one?

[1] Do what I mean, not what I say.

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
In Hypno-Vision
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-15-2005
On 15 Jul 2005 11:00:31 +0200, Gordon Beaton <(E-Mail Removed)> wrote or
quoted :

>Or were you really asking for a compiler that knows and does what you
>mean, without you having to specify anything?



Something in between. In normal English you can create a new unit of
measure just by saying it is a unit of measure the quatloo, or you can
define it in terms of some existing measure, e.g.

foot is 12 inches.

The equivalent declaration in a computer language should be equally
terse.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Hemal Pandya
Guest
Posts: n/a
 
      07-15-2005
Andrew Thompson wrote:

> I was after a DWIMNWIS[1] compiler, but that would be better.
> ..Does anybody got some codes for one?


I believe the KIBO programming language does what you say, I mean mean.
See http://groups.google.co.in/group/rec...14af30863513ff.

 
Reply With Quote
 
Hemal Pandya
Guest
Posts: n/a
 
      07-15-2005
Roedy Green wrote:
> On 14 Jul 2005 21:17:17 -0700, "Hemal Pandya" <(E-Mail Removed)>
> wrote or quoted :
>
> >I would still want the liberty to assign pixels to lines once in a
> >while.

>
> Just like the (cast) breaks the other type system.
>


The ability to break rules is important. But its better if it is
explicit. So I find dynamic_case<type> much better then (type).
Unfortunately Java did away with that. Maybe not so unfortunate, with
untyped collections the code would have been so full of them.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to cast object of type 'System.Byte[]' to type 'System.String'. Imran Aziz ASP .Net 4 01-19-2011 03:39 AM
Unable to cast object of type 'System.Web.Compilation.BuildResultCompiledAssembly' to type 'System.Web.Util.ITypedWebObjectFactory'. jlecain@free.fr ASP .Net 0 08-03-2006 06:00 PM
Help: Unable to cast object of type 'System.Int32' to type 'System.String'. keithb ASP .Net 3 05-07-2006 08:06 AM
Tightening up Shootout code Greg Buchholz C++ 2 01-16-2006 06:51 PM
PIX: tightening things down J Bard Cisco 1 02-16-2004 09:52 PM



Advertisments