R
Roedy Green
Consider a program that uses a mixture of 10-character and 13-digit
ISBN numbers (International Standard Book Number). From Java's point
of view, they are all Strings.
It would be nice if there were some mechanism to label Strings with a
light-weight type, probably a purely compile-time concept, similar to
generics. You would then label some string vars as ISBN13 and some as
ISBN10, and similarly parameters to methods. Then the compiler could
detect an improper passing of in ISBN13 string to an ISBN10 parameter.
An extension of this idea is units of measure, so that you could not
pass a cm variable to an inch parameter (though possibly you could
with an automatic conversion applied).
Think how many times you have wondered if a variable is measured in
seconds, ms, or ns. Here would be a formal way to specify and check
your assumption was correct.
Going a step further, your type might have a associated assertion to
make sure the value were valid. Perhaps there would be a way to
insert that assertion at every assignment.
--
Roedy Green Canadian Mind Products
http://mindprod.com
When you are programming and you feel paralysis from overwhelm:
(o) Write down your worries in an electronic todo list, so you can temporarily stop thinking about them.
(o) Write smaller modules and classes so you don’t need to juggle many facts to complete the code.
(o) Do some necessary, but simple, clerical task.
(o) Solve some simple problem with at least some probability of being useful in the big solution. It will break the logjam.
~ Roedy
ISBN numbers (International Standard Book Number). From Java's point
of view, they are all Strings.
It would be nice if there were some mechanism to label Strings with a
light-weight type, probably a purely compile-time concept, similar to
generics. You would then label some string vars as ISBN13 and some as
ISBN10, and similarly parameters to methods. Then the compiler could
detect an improper passing of in ISBN13 string to an ISBN10 parameter.
An extension of this idea is units of measure, so that you could not
pass a cm variable to an inch parameter (though possibly you could
with an automatic conversion applied).
Think how many times you have wondered if a variable is measured in
seconds, ms, or ns. Here would be a formal way to specify and check
your assumption was correct.
Going a step further, your type might have a associated assertion to
make sure the value were valid. Perhaps there would be a way to
insert that assertion at every assignment.
--
Roedy Green Canadian Mind Products
http://mindprod.com
When you are programming and you feel paralysis from overwhelm:
(o) Write down your worries in an electronic todo list, so you can temporarily stop thinking about them.
(o) Write smaller modules and classes so you don’t need to juggle many facts to complete the code.
(o) Do some necessary, but simple, clerical task.
(o) Solve some simple problem with at least some probability of being useful in the big solution. It will break the logjam.
~ Roedy