comp.lang.ada
 help / color / mirror / Atom feed
* strongly typed langauge
@ 1996-09-19  0:00 AGBOH CHARLES
  1996-09-19  0:00 ` Ian Ward
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: AGBOH CHARLES @ 1996-09-19  0:00 UTC (permalink / raw)



Hi


Could Some explain to me what the term "strongly typed language" is in the
context of ada.  Could you give some examples and tips as on how to
avoid errors related to this particular domain.



thanks




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: strongly typed langauge
  1996-09-19  0:00 strongly typed langauge AGBOH CHARLES
@ 1996-09-19  0:00 ` Ian Ward
  1996-09-22  0:00   ` Hugh Bonney
  1996-09-22  0:00   ` Hugh Bonney
  1996-09-19  0:00 ` Larry Kilgallen
  1996-09-20  0:00 ` Alan Brain
  2 siblings, 2 replies; 10+ messages in thread
From: Ian Ward @ 1996-09-19  0:00 UTC (permalink / raw)



In article 2jh@rc1.vub.ac.be, cagboh@vub.ac.be (AGBOH CHARLES) writes:
>Hi
>
>
>Could Some explain to me what the term "strongly typed language" is in the
>context of ada.  Could you give some examples and tips as on how to
>avoid errors related to this particular domain.
>
>
>
>thanks

Ada, as well as other modern languages provides the means of categorising
data into different types which have entirely or partly different meanings
to other types within the same program.

The easiest example I can think of is this :

Suppose I have two numbers

The first one is five, and it is the number of children, under ten
in England, who have behaved themselves at school since the 1976
decision by Strasbourg to ban corporal punishment in schools was
enforced.

The second number is 1200, this is the number of seconds it takes
to drink a pint of beer, say.

So we have two numbers, 1200 and 5, which we add together.

1200 + 5 = 1205.

1205 what, this clearly makes no sense...

It is therefore totally stupid, and no-one would ever want
to add five children, to a time. However, both of these numbers
are simple integers, and after six years on a project, when 
one's wife has just left you, and one has a particularly bad
hangover, one is likely to accidentally add these two numbers
together. In fact this will happen all over your project, 
some will get spotted, some shall not. Some will be caught
during testing, some shall not. Some will get to the customer.

In a language that does not define strong type checking, then
there is generally less chance that this mistake will be caught.
Unfortunately, the chinese? proverb "One's laces do not snap
until they are really needed." comes into play.

In essence, strong typing is just this, it is the software
engineering technique which stops the user from multiplying
a record by an array; dividing the time by a colour; or
passing a string variable into a procedure which expects 
an integer.

Because Ada defines this as part of the language definition,
it allows the programmer to create conceptual types within
the language which are fundamentally different in what they
represent. The language knows what sensible operations can
be performed on these types, and it knows what is stupid.
(What is stupid is defined by the rules of the language,
this doesn't mean the rules can be contravened, but the
programmer cannot avoid knowing he is doing it.)

Some people see these restrictions as a disadvantage, but,
as compilers provide such strong semantic checking, it can
be used to the programmer's advantage.

When faced with a data type such as an array of continents,
containing, a record containing, land area, number of vehicles,
an array of countries etc.

Each country in this array contains an array of animals, and
each animal contains a record, with number of legs, how many in 
existance etc.

Experienced Ada programmers, (well, ok, _I_) use the strong type
checking to their advantage here. They just type in any old
shit such as

...
   TOO_FEW_LEOPARDS := THIRTY; 
   -- TOO_FEW_LEOPARDS is of cunning type ANIMALS_COUNT, thirty is
   -- a constant := 30;

   if EARTH(AFRICA).ANIMALS.number_of_legs < TOO_FEW_LEOPARDS
   then

       -- invoke yield management
       PUT_UP_PRICE_OF (LEOPARD_SKIN_COATS);

   end if;
...
---

Throw this at the compiler, and hey presto before animal
rights campaigner have even written out the billboards to
campaign outside your shop, the compiler will turned around
and said. "EARTH" is a record, unlucky, perhaps you meant
EARTH.INCONTINENTS (AFRICA). so you go and change it.
and the compiler says

EARTH.INCONTINENTS (AFRICA) is a record, perhaps you meant
EARTH.INCONTINENTS (AFRICA).COUNTRIES....

So you change it, 
and it says

until eventually it says ...
.....NUMBER_OF_LEGS is not of the same type as TOO_FEW_LEOPARDS

So you change, and you still haven't had to think about the
code yet, and you recompile, and it compiles, and you run it,
and it runs, and you don't even have to start up the debugger.
Amazing huh?
Hey presto.
Congratulations, you've just finished early.

So you have the afternoon off, and get stabbed by some twelve year
old kid, on his way back from the European court of human rights,
having just won the right to stab anybody, without being told off
by his stepdad.


Ian Ward's opinions only : wardi@rsd.bel.alcatel.be




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: strongly typed langauge
  1996-09-19  0:00 strongly typed langauge AGBOH CHARLES
  1996-09-19  0:00 ` Ian Ward
@ 1996-09-19  0:00 ` Larry Kilgallen
  1996-09-20  0:00 ` Alan Brain
  2 siblings, 0 replies; 10+ messages in thread
From: Larry Kilgallen @ 1996-09-19  0:00 UTC (permalink / raw)



> Could Some explain to me what the term "strongly typed language" is in the
> context of ada.  Could you give some examples and tips as on how to
> avoid errors related to this particular domain.

A strongly typed language is one which requires explicit declaration
of datatypes for variables and prevents inadvertent intermixing:

    declare
        POINTER_TO_INTEGER is access INTEGER;
    begin
        POINTER_TO_INTEGER := 42;
    end;

Ada compilers will indicate an error since while 42 may be an integer,
it is not a pointer to an integer.  (Ada compilers may find other
errors in the above, I have not tested it.)

Strong typing is nothing new, Pascal compilers have been able to
discover the above error for years.  There are more subtle errors,
however, which Ada can catch but Pascal cannot.

There are other programming languages, with shorter names than
Ada, which do not catch errors of the type shown above.  They
rely on the hardware to catch the error with an operating system
fault later on, when the programmer is safely out of town.

Larry Kilgallen




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: strongly typed langauge
  1996-09-19  0:00 strongly typed langauge AGBOH CHARLES
  1996-09-19  0:00 ` Ian Ward
  1996-09-19  0:00 ` Larry Kilgallen
@ 1996-09-20  0:00 ` Alan Brain
  1996-09-23  0:00   ` Robin Vowels
  2 siblings, 1 reply; 10+ messages in thread
From: Alan Brain @ 1996-09-20  0:00 UTC (permalink / raw)



AGBOH CHARLES wrote:

> Hi
 
> Could Some explain to me what the term "strongly typed language" is in the
> context of ada.  Could you give some examples and tips as on how to
> avoid errors related to this particular domain.

Geen Problem, Pas de Probleme

OK, this is best answered by an example.
Suppose you had a quantity of 5 apples and 11 oranges.

In an untyped language, you could add 07 and 0B (Hex) to make 10 (Hex)
In a weakly typed language, you could declare them both as Integer
quantities, and add 5 to 11 to get 16 - but 16 of what?
In a strongly typed language, unless you'd made a new type, FRUIT_TYPE,
and defined that apples and oranges were both subtypes of this base
type,
the compiler would reject a statement adding apples to oranges, as they
are two different types.

Similarly, suppose you knew that the number of apples had to be within
the range 0 to 47. A strongly typed language would allow you to express
this, as 

subtype NUMBER_OF_APPLES_TYPE is INTEGER range 0..47;

and any operation which resulted in a quantity >47 or <0 would cause a
failure to be detected. 

Tot Ziens/A Bientot 

----------------------      <> <>    How doth the little Crocodile
| Alan & Carmel Brain|      xxxxx       Improve his shining tail?
| Canberra Australia |  xxxxxHxHxxxxxx _MMMMMMMMM_MMMMMMMMM
---------------------- o OO*O^^^^O*OO o oo     oo oo     oo  
                    By pulling Maerklin Wagons, in 1/220 Scale




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: strongly typed langauge
@ 1996-09-21  0:00 Spasmo
  0 siblings, 0 replies; 10+ messages in thread
From: Spasmo @ 1996-09-21  0:00 UTC (permalink / raw)



AGBOH CHARLES (cagboh@vub.ac.be) wrote:
: Hi


: Could Some explain to me what the term "strongly typed language" is in the
: context of ada.  Could you give some examples and tips as on how to
: avoid errors related to this particular domain.

Well strongly typed language in general means that strict type
checking is in place.  For instance try to mix and match various
numeric types in Ada and you'll quickly know what this means.
C will let you do stuff like mix floats and integers, but Ada
won't, at least not without explicit conversion.  Also you can
create new types which will be incompatible with old types,
even if they are "the same".  For instance compare the
following with C (notorious for being such a weakly typed language):

Ada:

type MY_INTEGER is new INTEGER;

C:

typedef int MY_INTEGER;

Now Ada will prevent you from mixing types of MY_INTEGER with
types of INTEGER, while C will happily let you mix MY_INTEGER
with int.  What this means for you as a developer is that
you get an extra layer of protection, and what IMO maps to
an ability to better reinforce your data types and map your
program to the problem domain you are wishing to solve.  Of
course if you are in the habit of mixing types, you will get
numerous errors, but these are easy to correct, and IMO will
save you grief in the long run.  Better a compile error now
than a runtime error a week later.

: thanks

--
Spasmo
"John Wayne was a Nazi, he liked to play SS
 He had a picture of Adolph the Boy tucked in his cowboy vest"
	"John Wayne was a Nazi" by MDC





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: strongly typed langauge
  1996-09-19  0:00 ` Ian Ward
  1996-09-22  0:00   ` Hugh Bonney
@ 1996-09-22  0:00   ` Hugh Bonney
  1996-09-23  0:00     ` Alan Brain
  1 sibling, 1 reply; 10+ messages in thread
From: Hugh Bonney @ 1996-09-22  0:00 UTC (permalink / raw)



Ian Ward (wardi@rsd.bel.alcatel.be) wrote:
: In article 2jh@rc1.vub.ac.be, cagboh@vub.ac.be (AGBOH CHARLES) writes:
: >Could Some explain to me what the term "strongly typed language" is in the
: >context of ada.  Could you give some examples and tips as on how to
: >avoid errors related to this particular domain.

: Ada, as well as other modern languages provides the means of categorising
: data into different types which have entirely or partly different meanings
: to other types within the same program.

: The easiest example I can think of is this :

: Suppose I have two numbers

: The first one is five, and it is the number of children, under ten
: in England, who have behaved themselves at school since the 1976
: decision by Strasbourg to ban corporal punishment in schools was
: enforced.

: The second number is 1200, this is the number of seconds it takes
: to drink a pint of beer, say.

: So we have two numbers, 1200 and 5, which we add together.

: 1200 + 5 = 1205.

: 1205 what, this clearly makes no sense...

    Well, of course it does since the sum is well known to be a
    physical constant. 

    Another example might be to note that it's 2km from A to B,
    300m from B to C, and 20mm from C to D. So if you walk from
    A to D have you gone a distance of 322? In elementary school
    we have to learn the essentials of data typing and one can 
    start with that. It does make sense to add apples and oranges
    sometimes, but it doesn't make sense to add km and mm even
    if you want to know the distance from Paris to the end of
    your nose.

    With all that, I do a lot of programming on the hardware. 
    Lately I've been writing up a boot rom almost entirely in
    C . Because the on-chip peripheral control registers are 
    all memory mapped, there are almost no asm statements 
    anywhere. There's one little chunk to save and restore
    all the processor registers and a few bits here and there
    including an equivalent of a simple crt0 to pass control 
    to an RTOS.  In some other languages it would have been 
    necessary to write very large chunks in assembler which
    would escape task-level type checking entirely. There must 
    be some code around that is known to be absolutely wonderful -
    but is running on a rather shakey substrate.

    Strong typing shouldn't be used as a substitute for thought
    or care, where it's useful is in pointing out real difficulties
    in either one person's thinking about a problem, or real
    (and inevitable) differences in understanding from one person
    to the next. One could have such a code inspection done by
    an inspection program, of course, incorporating every type of
    analysis that will execute by overnight, and going through all
    the code in a project as well as pieces of it.


: It is therefore totally stupid, and no-one would ever want
: to add five children, to a time. However, both of these numbers
: are simple integers, and after six years on a project, when 
: one's wife has just left you, and one has a particularly bad
: hangover, one is likely to accidentally add these two numbers
: together. In fact this will happen all over your project, 
: some will get spotted, some shall not. Some will be caught
: during testing, some shall not. Some will get to the customer.

: In a language that does not define strong type checking, then
: there is generally less chance that this mistake will be caught.
: Unfortunately, the chinese? proverb "One's laces do not snap
: until they are really needed." comes into play.

: In essence, strong typing is just this, it is the software
: engineering technique which stops the user from multiplying
: a record by an array; dividing the time by a colour; or
: passing a string variable into a procedure which expects 
: an integer.

: Because Ada defines this as part of the language definition,
: it allows the programmer to create conceptual types within
: the language which are fundamentally different in what they
: represent. The language knows what sensible operations can
: be performed on these types, and it knows what is stupid.
: (What is stupid is defined by the rules of the language,
: this doesn't mean the rules can be contravened, but the
: programmer cannot avoid knowing he is doing it.)

: Some people see these restrictions as a disadvantage, but,
: as compilers provide such strong semantic checking, it can
: be used to the programmer's advantage.

: When faced with a data type such as an array of continents,
: containing, a record containing, land area, number of vehicles,
: an array of countries etc.

: Each country in this array contains an array of animals, and
: each animal contains a record, with number of legs, how many in 
: existance etc.

: Experienced Ada programmers, (well, ok, _I_) use the strong type
: checking to their advantage here. They just type in any old
: shit such as

: ...
:    TOO_FEW_LEOPARDS := THIRTY; 
:    -- TOO_FEW_LEOPARDS is of cunning type ANIMALS_COUNT, thirty is
:    -- a constant := 30;

:    if EARTH(AFRICA).ANIMALS.number_of_legs < TOO_FEW_LEOPARDS
:    then

:        -- invoke yield management
:        PUT_UP_PRICE_OF (LEOPARD_SKIN_COATS);

:    end if;
: ...
: ---

: Throw this at the compiler, and hey presto before animal
: rights campaigner have even written out the billboards to
: campaign outside your shop, the compiler will turned around
: and said. "EARTH" is a record, unlucky, perhaps you meant
: EARTH.INCONTINENTS (AFRICA). so you go and change it.
: and the compiler says

: EARTH.INCONTINENTS (AFRICA) is a record, perhaps you meant
: EARTH.INCONTINENTS (AFRICA).COUNTRIES....

: So you change it, 
: and it says

: until eventually it says ...
: .....NUMBER_OF_LEGS is not of the same type as TOO_FEW_LEOPARDS

: So you change, and you still haven't had to think about the
: code yet, and you recompile, and it compiles, and you run it,
: and it runs, and you don't even have to start up the debugger.
: Amazing huh?
: Hey presto.  Congratulations, you've just finished early.

   Air Traffic Controllers in Europe must get interesting messages
   from their systems...

: So you have the afternoon off, and get stabbed by some twelve year
: old kid, on his way back from the European court of human rights,
: having just won the right to stab anybody, without being told off
: by his stepdad.

: Ian Ward's opinions only : wardi@rsd.bel.alcatel.be




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: strongly typed langauge
  1996-09-19  0:00 ` Ian Ward
@ 1996-09-22  0:00   ` Hugh Bonney
  1996-09-22  0:00   ` Hugh Bonney
  1 sibling, 0 replies; 10+ messages in thread
From: Hugh Bonney @ 1996-09-22  0:00 UTC (permalink / raw)



Reposting article removed by rogue canceller.

Ian Ward (wardi@rsd.bel.alcatel.be) wrote:
: In article 2jh@rc1.vub.ac.be, cagboh@vub.ac.be (AGBOH CHARLES) writes:
: >Could Some explain to me what the term "strongly typed language" is in the
: >context of ada.  Could you give some examples and tips as on how to
: >avoid errors related to this particular domain.

: Ada, as well as other modern languages provides the means of categorising
: data into different types which have entirely or partly different meanings
: to other types within the same program.

: The easiest example I can think of is this :

: Suppose I have two numbers

: The first one is five, and it is the number of children, under ten
: in England, who have behaved themselves at school since the 1976
: decision by Strasbourg to ban corporal punishment in schools was
: enforced.

: The second number is 1200, this is the number of seconds it takes
: to drink a pint of beer, say.

: So we have two numbers, 1200 and 5, which we add together.

: 1200 + 5 = 1205.

: 1205 what, this clearly makes no sense...

    Well, of course it does since the sum is well known to be a
    physical constant. 

    Another example might be to note that it's 2km from A to B,
    300m from B to C, and 20mm from C to D. So if you walk from
    A to D have you gone a distance of 322? In elementary school
    we have to learn the essentials of data typing and one can 
    start with that. It does make sense to add apples and oranges
    sometimes, but it doesn't make sense to add km and mm even
    if you want to know the distance from Paris to the end of
    your nose.

    With all that, I do a lot of programming on the hardware. 
    Lately I've been writing up a boot rom almost entirely in
    C . Because the on-chip peripheral control registers are 
    all memory mapped, there are almost no asm statements 
    anywhere. There's one little chunk to save and restore
    all the processor registers and a few bits here and there
    including an equivalent of a simple crt0 to pass control 
    to an RTOS.  In some other languages it would have been 
    necessary to write very large chunks in assembler which
    would escape task-level type checking entirely. There must 
    be some code around that is known to be absolutely wonderful -
    but is running on a rather shakey substrate.

    Strong typing shouldn't be used as a substitute for thought
    or care, where it's useful is in pointing out real difficulties
    in either one person's thinking about a problem, or real
    (and inevitable) differences in understanding from one person
    to the next. One could have such a code inspection done by
    an inspection program, of course, incorporating every type of
    analysis that will execute by overnight, and going through all
    the code in a project as well as pieces of it.


: It is therefore totally stupid, and no-one would ever want
: to add five children, to a time. However, both of these numbers
: are simple integers, and after six years on a project, when 
: one's wife has just left you, and one has a particularly bad
: hangover, one is likely to accidentally add these two numbers
: together. In fact this will happen all over your project, 
: some will get spotted, some shall not. Some will be caught
: during testing, some shall not. Some will get to the customer.

: In a language that does not define strong type checking, then
: there is generally less chance that this mistake will be caught.
: Unfortunately, the chinese? proverb "One's laces do not snap
: until they are really needed." comes into play.

: In essence, strong typing is just this, it is the software
: engineering technique which stops the user from multiplying
: a record by an array; dividing the time by a colour; or
: passing a string variable into a procedure which expects 
: an integer.

: Because Ada defines this as part of the language definition,
: it allows the programmer to create conceptual types within
: the language which are fundamentally different in what they
: represent. The language knows what sensible operations can
: be performed on these types, and it knows what is stupid.
: (What is stupid is defined by the rules of the language,
: this doesn't mean the rules can be contravened, but the
: programmer cannot avoid knowing he is doing it.)

: Some people see these restrictions as a disadvantage, but,
: as compilers provide such strong semantic checking, it can
: be used to the programmer's advantage.

: When faced with a data type such as an array of continents,
: containing, a record containing, land area, number of vehicles,
: an array of countries etc.

: Each country in this array contains an array of animals, and
: each animal contains a record, with number of legs, how many in 
: existance etc.

: Experienced Ada programmers, (well, ok, _I_) use the strong type
: checking to their advantage here. They just type in any old
: shit such as

: ...
:    TOO_FEW_LEOPARDS := THIRTY; 
:    -- TOO_FEW_LEOPARDS is of cunning type ANIMALS_COUNT, thirty is
:    -- a constant := 30;

:    if EARTH(AFRICA).ANIMALS.number_of_legs < TOO_FEW_LEOPARDS
:    then

:        -- invoke yield management
:        PUT_UP_PRICE_OF (LEOPARD_SKIN_COATS);

:    end if;
: ...
: ---

: Throw this at the compiler, and hey presto before animal
: rights campaigner have even written out the billboards to
: campaign outside your shop, the compiler will turned around
: and said. "EARTH" is a record, unlucky, perhaps you meant
: EARTH.INCONTINENTS (AFRICA). so you go and change it.
: and the compiler says

: EARTH.INCONTINENTS (AFRICA) is a record, perhaps you meant
: EARTH.INCONTINENTS (AFRICA).COUNTRIES....

: So you change it, 
: and it says

: until eventually it says ...
: .....NUMBER_OF_LEGS is not of the same type as TOO_FEW_LEOPARDS

: So you change, and you still haven't had to think about the
: code yet, and you recompile, and it compiles, and you run it,
: and it runs, and you don't even have to start up the debugger.
: Amazing huh?
: Hey presto.  Congratulations, you've just finished early.

   Air Traffic Controllers in Europe must get interesting messages
   from their systems...

: So you have the afternoon off, and get stabbed by some twelve year
: old kid, on his way back from the European court of human rights,
: having just won the right to stab anybody, without being told off
: by his stepdad.

: Ian Ward's opinions only : wardi@rsd.bel.alcatel.be




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: strongly typed langauge
  1996-09-22  0:00   ` Hugh Bonney
@ 1996-09-23  0:00     ` Alan Brain
  0 siblings, 0 replies; 10+ messages in thread
From: Alan Brain @ 1996-09-23  0:00 UTC (permalink / raw)



Hugh Bonney wrote:

>     Another example might be to note that it's 2km from A to B,
>     300m from B to C, and 20mm from C to D. So if you walk from
>     A to D have you gone a distance of 322? In elementary school
>     we have to learn the essentials of data typing and one can
>     start with that. It does make sense to add apples and oranges
>     sometimes, but it doesn't make sense to add km and mm even
>     if you want to know the distance from Paris to the end of
>     your nose.

Excellent point.


>     Strong typing shouldn't be used as a substitute for thought
>     or care

And the converse is also true:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Thought and Care shouldn't be used as a substitute for strong typing...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

>              , where it's useful is in pointing out real difficulties
>     in either one person's thinking about a problem, or real
>     (and inevitable) differences in understanding from one person
>     to the next. 

----------------------      <> <>    How doth the little Crocodile
| Alan & Carmel Brain|      xxxxx       Improve his shining tail?
| Canberra Australia |  xxxxxHxHxxxxxx _MMMMMMMMM_MMMMMMMMM
---------------------- o OO*O^^^^O*OO o oo     oo oo     oo  
                    By pulling Maerklin Wagons, in 1/220 Scale




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: strongly typed langauge
  1996-09-20  0:00 ` Alan Brain
@ 1996-09-23  0:00   ` Robin Vowels
  0 siblings, 0 replies; 10+ messages in thread
From: Robin Vowels @ 1996-09-23  0:00 UTC (permalink / raw)



	Alan Brain <aebrain@dynamite.com.au> writes:


	>Suppose you had a quantity of 5 apples and 11 oranges.

	>In an untyped language, you could add 07 and 0B (Hex) to make 10 (Hex)

---In an untyped language, I assure you that 07 + 0B gives 12 (hex).




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: strongly typed langauge
@ 1996-09-24  0:00 Spasmo
  0 siblings, 0 replies; 10+ messages in thread
From: Spasmo @ 1996-09-24  0:00 UTC (permalink / raw)



Hugh Bonney (hbonney@netcom.com) wrote:
: Reposting article removed by rogue canceller.

: Ian Ward (wardi@rsd.bel.alcatel.be) wrote:

[Snip]

: : Suppose I have two numbers

: : The first one is five, and it is the number of children, under ten
: : in England, who have behaved themselves at school since the 1976
: : decision by Strasbourg to ban corporal punishment in schools was
: : enforced.

: : The second number is 1200, this is the number of seconds it takes
: : to drink a pint of beer, say.

: : So we have two numbers, 1200 and 5, which we add together.

: : 1200 + 5 = 1205.

: : 1205 what, this clearly makes no sense...

:     Well, of course it does since the sum is well known to be a
:     physical constant. 

I think you are confused.  While it makes sense to add any given
number to another from a MATHEMATICAL view, it doesn't necessarily
make sense to add two numbers that represent different 
entities.  I mean adding school children to units of time
makes no sense whatsoever from the perspective of an application
and this is (what I believe) Ian was talking about.  Two
values, which while mathematically compatible, are incompatible
per the rules of your application, hence using strong typing
to guarantee that they remain so can keep you from goofing
up in new and exciting ways.


:     Another example might be to note that it's 2km from A to B,
:     300m from B to C, and 20mm from C to D. So if you walk from
:     A to D have you gone a distance of 322? In elementary school
:     we have to learn the essentials of data typing and one can 
:     start with that. It does make sense to add apples and oranges
:     sometimes, but it doesn't make sense to add km and mm even
:     if you want to know the distance from Paris to the end of
:     your nose.

It makes sense to add apples and oranges if the rules of your
application allow such an operation.  Someone brought up a
great example of a data type called FRUIT, of which apples
and oranges were instances (loose use of the term) of.
Adding apples to oranges in this context made sense since
the sum was that of fruit, and apples and oranges were both
fruit, ie: your application allowed such an operation.
However, if you didn't want to know the quantity of fruit
in general, but instead wanted to keep track of apples
and oranges SEPARATELY, then it makes no sense whatsoever
to add apples to oranges.  I mean what is the sum?  It has
no place in the application whatsoever.


[Snip]

:     Strong typing shouldn't be used as a substitute for thought
:     or care, where it's useful is in pointing out real difficulties
:     in either one person's thinking about a problem, or real
:     (and inevitable) differences in understanding from one person
:     to the next. One could have such a code inspection done by
:     an inspection program, of course, incorporating every type of
:     analysis that will execute by overnight, and going through all
:     the code in a project as well as pieces of it.

However it can and IMO should be used in conjunction with thought
and care, to enforce the categorizations which we make in our
programs, and also to catch errors.  Hey we all make errors,
and even with careful design bugs are liable to happen, so any
extra safety that comes my way is greatly appreciated (and used).

[Snip]

: : Ian Ward's opinions only : wardi@rsd.bel.alcatel.be

--
Spasmo
"John Wayne was a Nazi, he liked to play SS
 He had a picture of Adolph the Boy tucked in his cowboy vest"
	"John Wayne was a Nazi" by MDC





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1996-09-24  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-19  0:00 strongly typed langauge AGBOH CHARLES
1996-09-19  0:00 ` Ian Ward
1996-09-22  0:00   ` Hugh Bonney
1996-09-22  0:00   ` Hugh Bonney
1996-09-23  0:00     ` Alan Brain
1996-09-19  0:00 ` Larry Kilgallen
1996-09-20  0:00 ` Alan Brain
1996-09-23  0:00   ` Robin Vowels
  -- strict thread matches above, loose matches on Subject: below --
1996-09-21  0:00 Spasmo
1996-09-24  0:00 Spasmo

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