Re: about complex data type

new topic     » goto parent     » topic index » view thread      » older message » newer message

jacques deschĂȘnes wrote:

> reading datetime.e I just got an idea that is not specific to it.
> 
> looking at this type definition
> }}}
<eucode>
> global type datetime(object o)
>   return sequence(o) and length(o) = 6
>       and integer(o[DT_YEAR]) and integer(o[DT_MONTH]) and integer(o[DT_DAY])
>       and integer(o[DT_HOUR]) and integer(o[DT_MINUTE]) and atom(o[DT_SECOND])
> end type
> </eucode>
{{{

> 
> one see that it take a large boolean expression to check the nature of complex
> data type like this one. My idea is why not use a tag to identify complex data
> type. the first element of the sequence being the tag. In this exemple every
> datetime object would be like: {"DATETIME",...}
> and the type would be.
> 
> }}}
<eucode>
> global datetime(object o)
>   return sequence(o) and equal(o[1],"DATETIME")
> end type
> </eucode>
{{{


But you're only checking to see if it "says" that it's the correct type.
What if some buggy code dropped an element somewhere, or changed something
into a sequence?  You'd never know, and would have removed the usefulness
of type checking, which is really a development tool, not for runtime
support.  If you're concerned about speed, just turn off type checking

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu