Re: Units as a checkable indicator of program errors



On Apr 22, 4:07 pm, "Aaron Gray" <ang.use...@xxxxxxxxx> wrote:
"Ray Dillinger" <b...@xxxxxxxxx> wrote in message

news:49dfbb89$0$95484$742ec2ed@xxxxxxxxxxxxxxxxx





In another topic which I won't respond to now because it's been
diverted into a religious war about static and dynamic typing,
someone made a point that a biologist faced with typical type-
error messages was likely to give up in frustration rather than
understand what was wrong with the program.

An' I thought about that.

You know what scientists of all types understand, and which really
would help them get code correct?  I include both dynamic and
static checking systems here - please, I beg you, don't get hung
up on exactly when a check is to be made. What every scientist
understands is units.

We're all used to handling raw numbers with type declarations limited
to rational, floating or integer, etc.  We attach units like "meters"
or "seconds" or "reontgens per hour," etc, on an adhoc, usually
unchecked, basis, during our output routines.

But actual factual logical errors in scientific programs that work
with numbers often (maybe even usually) express themselves as
results in unexpected unit types, or in unit mismatches.  If a
scientist runs a calculation to find out how much time something
will take and gets an answer in meters or lumens or Hertz, s/he
knows something is wrong with the program logic and most
scientists tracing through could probably pinpoint the line of
code where it went awry.  If another scientist is looking for
correlation, and gets probability instead, it indicates that
the same general sort of logic error has been made (are there
scientific units of correlation and probability?  Are they part
of the metric system?  They certainly should be by now....).

The problem ceases to be a "type" error involving obscure details
of computer hardware representation (outside their specialty, but
within that of we CS geeks) and becomes a "unit" error of a sort
that they and their students/lab assistants/colleagues understand
because they run into such in calculations-by-hand all the time.

This is only marginally expressible in primitive static type systems,
but there's a calculus of units that works in direct parallel with
our calculus of numbers.  Some languages make it possible to
implement this sort of thing, with a lot of pain and a lot of writing
very repetitive methods, but I'm increasingly of the opinion that
knowledge of the calculus of units ought to come as a builtin and
standard part of a language's math libraries.

When I add or subtract two speeds, I get a speed.
When I multiply a speed by a time, I get a distance.
When I multiply an acceleration by a time, I get a speed.
When I multiply an acceleration by a mass, I get a force.
When I multiply a force by a time, I get work.

When I try to subtract a speed from a mass -- that ought to provoke
an error, because it doesn't mean anything.

And so on and so on.

If we start doing math on numbers expressed with units, and our
languages or libraries fully support units, we get results with
units.  If our language system is aware of the units of the result,
and we've told it to expect a result with a different unit type,
then we have an opportunity to signal an error.

Bravo, I thought of this one when I was 16, some 26 years ago, and apart
from Mathmatica no language supports units or unit checking, or does
dimentional analysis at all.

Not true. The Curl programming language has had built-in support for
"quantity types" and many standard units since its creation well over
a decade ago. This is especially useful when doing GUI/graphics
programming since it allows you to work in your favorite distance
units (e.g., in, cm, pica, ...). (BTW, early versions of Curl
supported temperature units but we found that in practice it was too
weird supporting scales with differing concepts of zero, so we dropped
it)

- Christopher


.



Relevant Pages

  • Re: Facts are facts
    ... should evidence hold true. ... It appears that scientists have ... written language. ... you have the gall to demand others support their claims (claims you ...
    (talk.origins)
  • Re: In the News: Expelled Exposes Plight of Darwin Doubters
    ... first language, and I think that is where the problem lies. ... Scientists use ... Natural selection can only explain strictly biological features of ... advantage of a neighbouring environment or a new food source. ...
    (talk.origins)
  • Re: Programmers unpaid overtime.
    ... tokenizing a string correctly. ... ability to specify a set of delimiter tokens, ... >> postmodern attack on language itself, ... An the scientists, in turn, think a lot of that artistic talk about ...
    (comp.programming)
  • Re: Natural selection is a false term - says Darwin in Origin Species
    ... scientists can reads their intent quite easily. ... created language and thus their language is what bouncing atoms makes ... Science has determined that some elemets are unstable, ... evidence in the universe turns against creationism, I would be the first to ...
    (talk.origins)
  • Re: Stonethrowing most compelling behaviour to create language
    ... Throwing of stones or rocks does not take or make language at all. ... Can we get real scientists, not Val, to tell us why the bone anatomy of a chimp ...
    (sci.anthropology.paleo)

Loading