Interfaces / data types in E
Thomas Leonard <tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]> Thu, 06 Oct 2011 11:35:39 +0100
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <[email protected]> |
We've got quite a few methods that take or return maps. e.g.
to purchase(customerDetails :Map[String,any]) {
... customerDetails["name"] ...
...
if (problem) {
notify(customerDetails["email"])
}
...
}
The problem is that it's not obvious from the method signature what keys
need to be present. Often someone fails to include a mapping, and the
system only fails later in some case where it needed that value.
What I think I'd like to do is something like:
def CustomerDetails := makeNamedTuple([
"name" => String,
"email" => String,
])
...
to purchase(customerDetails :CustomerDetails]) {
... customerDetails["name"] ...
}
So that:
- if the caller fails to provide "name" and "email" then it fails the guard
- if I try to access a field I didn't define (e.g. "fax") then I get an
error, whether or not the client provided it, so I'm forced to keep the
interface up-to-date
Ideally it should handle fields being added later (e.g. if two parties
are running different versions of the software it should ignore fields
it doesn't understand).
Any ideas on the best way to do this? Maps? TermTrees?
Some of the other systems using this are written in Java, so ideally it
should be easy to use from there too.
--
Dr Thomas Leonard
IT Innovation Centre
Gamma House, Enterprise Road,
Southampton SO16 7NS, UK
tel: +44 23 8059 8866
mailto:tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]
http://www.it-innovation.soton.ac.uk/