comp.lang.ada
 help / color / mirror / Atom feed
From: wardi@rsd.bel.alcatel.be (Ian Ward)
Subject: Re: strongly typed langauge
Date: 1996/09/19
Date: 1996-09-19T00:00:00+00:00	[thread overview]
Message-ID: <51rp18$p5@btmpjg.god.bel.alcatel.be> (raw)
In-Reply-To: 51rai1$2jh@rc1.vub.ac.be


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




  parent reply	other threads:[~1996-09-19  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-19  0:00 strongly typed langauge AGBOH CHARLES
1996-09-19  0:00 ` Larry Kilgallen
1996-09-19  0:00 ` Ian Ward [this message]
1996-09-22  0:00   ` Hugh Bonney
1996-09-22  0:00   ` Hugh Bonney
1996-09-23  0:00     ` Alan Brain
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
replies disabled

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