comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Are there noticable differences in Ada acceptance by country?
Date: Fri, 21 Mar 2008 08:52:38 +0100
Date: 2008-03-21T08:52:40+01:00	[thread overview]
Message-ID: <15bxm1vkv9k10.1s13j5278f2xn$.dlg@40tude.net> (raw)
In-Reply-To: m263vhca6p.fsf@mac.com

On Thu, 20 Mar 2008 22:17:18 +0000, Simon Wright wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> On Thu, 20 Mar 2008 20:22:22 +0000, Simon Wright wrote:
>>
>>> gpriv@axonx.com writes:
>>> 
>>>> I think strong typing should not be dismissed.  Unfortunately Java-
>>>> based (and C/C++/C#) courses don't explain to students that X and Y
>>>> coordinates being fundamentally integer (or float) types are not the
>>>> same thing.
>>> 
>>> I always disliked an X binding which had (sub)types for X, Y
>>> coordinates. Wrong level of abstraction, I thought: use something like
>>> 
>>>    type Position is record
>>>       X : Float;
>>>       Y : Float;
>>>    end record;
>>> 
>>> and you get a _lot_ less scope for confusion.
>>
>> If no rotations involved I would suggest:
>>
>>    type Horizontal_Coordinate is new Float;
>>    type Vertical_Coordinate is new Float;
>>    type Position is record
>>        X : Horizontal_Coordinate;
>>        Y : Vertical_Coordinate;
>>    end record;
>>
>> In some cases I would consider making absolute positions and relative
>> offsets different types, similar to Time and Duration.
> 
> Well, to be fair, I suppose I would have used Metres (or Pixels)
> rather than plain Float.
> 
>   subtype Metres is Float;

I would probably use fixed point for that.
 
> But I don't see the real advantage in using different types for H_C
> and V_C. How ofen are users actually going to get this wrong?

Quite often in GUI applications.

> There is
> some comment-like advantage to subtyping -- rather like AdaCore's
> library packages with eg
> 
>   subtype Path_Name is String;

Interesting, actually in my libraries, I indeed use Item_Path and Item_Name 
both different new types from String. That helped not to mix paths and
names in the subprograms like Get_Directory, Get_Name, compose path from
parent's path and name etc. I had some nasty bugs using Ada.Directories,
which treats path and names subtypes, therefore I decided to make them
separate types.

> but full typing is only going to clutter the place up with
> conversions. Or perhaps you lie to provide all the operations a person
> could need (acceleration x duration -> speed etc)?

Maybe. But these are different cases to me. I think it is true that 
dimensional algebra should be better built on subtypes. But dimensioned 
values are often applied to some reference points. Like distances measured 
from different places. These cannot be mixed even if they have same 
dimensions. So "meter" is more like "float." You could possibly wish to 
have

   type Distance_From_My_Office is new Meter;

(Actually it should produce a whole new dimensional algebra of types.)

> Why would things be different if there were rotations involved?

Because with rotations coordinates become linear combinations with 
dimensionless coefficients. (The rotation matrix is a matrix exponent so 
that cannot be made dimensioned.)

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2008-03-21  7:52 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-18 19:08 Are there noticable differences in Ada acceptance by country? Mike Silva
2008-03-18 20:41 ` Pascal Obry
2008-03-18 22:58   ` Phaedrus
2008-03-18 22:25     ` Mike Silva
2008-03-18 22:50 ` Ludovic Brenta
2008-03-19 11:42   ` Thomas
2008-03-19 12:09     ` Ludovic Brenta
2008-03-19 12:51       ` framefritti
2008-03-20  4:37         ` gpriv
2008-03-19 12:16     ` Ludovic Brenta
2008-03-19 19:04       ` Tero Koskinen
2008-03-20  8:57         ` Jean-Pierre Rosen
2008-03-25 18:02           ` Tero Koskinen
2008-03-25 19:57             ` Gautier
2008-03-19 19:55     ` svaa
2008-03-19 21:14       ` Phaedrus
2008-03-20  4:52         ` gpriv
2008-03-20 20:22           ` Simon Wright
2008-03-20 20:48             ` Dmitry A. Kazakov
2008-03-20 22:17               ` Simon Wright
2008-03-20 22:59                 ` gpriv
2008-03-21  1:54                   ` tmoran
2008-03-21  4:16                   ` Jeffrey R. Carter
2008-03-21 16:41                     ` Simon Wright
2008-03-21 19:15                     ` gpriv
2008-03-22 14:00                       ` Maciej Sobczak
2008-03-21 16:39                   ` Simon Wright
2008-03-21 19:21                     ` gpriv
2008-03-21 21:11                       ` Adam Beneschan
2008-03-22  7:02                         ` Simon Wright
2008-03-24 18:01                           ` gpriv
2008-03-21  7:52                 ` Dmitry A. Kazakov [this message]
2008-03-22 17:16                   ` Subtypes to represent coordinate charts Eric Hughes
2008-03-21 16:44                 ` Are there noticable differences in Ada acceptance by country? Simon Wright
2008-03-20 21:17             ` gpriv
2008-03-20  1:34       ` Ivan Levashew
2008-03-19  7:42 ` Thomas
2008-03-19 10:35   ` Peter C. Chapin
2008-03-19 21:21     ` Phaedrus
     [not found]       ` <13u3vq728nidu3b@corp.supernews.com>
2008-03-31  4:27         ` David Thompson
2008-03-31  5:40           ` DScott
replies disabled

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