Why UDT's aren't used.
UDT - User Defined Types
I don't know how many times I had to see the acronym to finally figure out
what it meant.
----- Original Message -----
From: "Pete Lomax" <petelomax at blueyonder.co.uk>
To: <EUforum at topica.com>
Sent: Wednesday, June 02, 2004 2:46 AM
Subject: Re: Sequence of Suggestion (was Re: The Title Should At Least
Mention Strings (
>
>
> On Wed, 02 Jun 2004 08:03:46 +1000, Patrick Barnes
> <mistertrik at hotmail.com> wrote:
>
> >But this is what euphoria has to do ALL THE TIME currently. In fact, it's
> >even worse
> >than in this example, because at least with this example you only have to
> >check text_picture[3], not the entire text_picture.
> Waaay ahead of you there. I once had a program with a huge and
> complicated fieldlist table at the centre, which practically every
> other line in the whole program updated. Adding type checking to it
> dropped the load time from about 2 seconds to around 80!
> Here is a contrived example:
> atom t0
> t0=time()
> type table(sequence t)
> for i=1 to length(t) do
> if not integer(t[i]) or t[i]<-100 or t[1]>100 then return 0
> end if
> end for
> return 1
> end type
> --table t
> sequence t
> t=repeat(0,10000)
> for i=1 to 10000 do
> t[i]=5
> end for
> printf(1,"%3.2f\n",time()-t0)
> if getc(0) then end if
> Replacing sequence t with table t drops the time from between 0.00 and
> 0.01 seconds to over 100 seconds, which is some slowdown!
>
> Of course I understand precisely why, and we definitely need some
> better way. What amuses me is Rob sounds a little surprised and hurt
> that no-one uses user defined types much
)
>
<snip>
>
> Pete
>
The only reason he SHOULD be surprised is because he hadn't been
using the language. Anyone that has every tried to build a decent type
check on a sequence would know that the performance hit is horrible.
I as well understand why, as I assume most others do. But
understanding has simply lead us to not using it. Using good strong
type checking can turn a 1 second load program into a program that
appears to simply hang for several minutes. I know, cause I've
done it before. I've avoided type defining ever since. I don't think
I have seen any code of Robs where he defines a type on a
sequence in a table like manner.
}}}
<eucode>
type byte(object x)
if (integer(x)) and (255 >= x and x >= 0) then
return 1
end if
return 0
end type
type alphanum(object x)
object mask
mask = ('0' >= x and x >= '9')
mask += ('A' >= x and x >= 'Z')
mask += ('a' >= x and x >= 'z')
if atom(x) then
return mask
else
return (not find(0, mask))
end if
end type
type alpha(object x)
object mask
mask = ('A' >= x and x >= 'Z')
mask += ('a' >= x and x >= 'z')
if atom(x) then
return mask
else
return (not find(0, mask))
end if
end type
type numeric(object x)
object mask
mask = ('0' >= x and x >= '9')
if atom(x) then
return mask
else
return (not find(0, mask))
end if
end type
type flat(object x)
sequence s
if sequence(x) then
s = x * 0
if equal(s, repeat(0, length(s))) then
return 1
end if
end if
return 0
end type
type string1(object x)
if flat(x) then
for A = 1 to length(x) do
if (not byte(x[A])) then
return 0
end if
end for
return 1
end if
return 0
end type
type string(object x)
flat fl
if (flat(x) and (equal(x, floor(x)))then
fl = (255 >= x)
fl += (x >= 0)
if (0 = find(0, fl)) then
return 1
end if
end if
return 0
end type
type text(object x)
if (string(x)) then
if ('~' >= x and x >= ' ') then
return 1
end if
end if
return 0
end type
type zip9(object x)
integer result
if sequence(x) then
i = numeric(x[1..5] & x[7..10])
i = i and (x[6] = '-')
return i
end if
return 0
end type
type PhoneBookItem(object x)
integer i
if sequence(x) then
-- Names and Addresses should be text
if (length(x) = 18) then
for A = 1 to 18 do
if (not text(x[A])) then
return 0
end if
end for
--[NAMES]
-- 1 first
if (not alpha(x[1])) then
return 0
end if
-- 2 middle
-- 3 last
if (not alpha(x[3])) then
return 0
end if
-- 4 suffix
--[ADDRESSES]
-- 5 home address
-- 6 home city
if (not alpha(x[6])) then
return 0
end if
-- 7 home state
if (not alpha(x[7]) then
return 0
end if
i = length(x[7])
if (not (i = 0 or i = 2))then
return 0
end if
-- 8 home zip
i = length(x[8])
if (i = 5) then
if (not numeric(x[8])) then
return 0
end if
elsif (i = 10) then
if (not zip9(x[8]) then
return 0
end if
end if
-- 9 office address
--10 office city
if (not alpha(x[10])) then
return 0
end if
--11 office state
if (not alpha(x[11]) then
return 0
end if
i = length(x[11])
if (not (i = 0 or i = 2)) then
return 0
end if
--12 office zip
i = length(x[12])
if (i = 5) then
if (not numeric(x[12])) then
return 0
end if
elsif (i = 10) then
if (not zip9(x[12]) then
return 0
end if
end if
--[PHONES]
--13 phone main
--14 phone home
--15 phone office
--16 phone fax
--17 phone cell
--18 phone pager -- 123456789-123456789-123
for A = 13 to 18 do -- "# (###) ###-#### x#####"
if (length(x[A]) > 23) then
return 0
end if
end for
return 1
end if
end if
return 0
end type
type PhoneBook(object x)
if sequence(x) then
for A = 1 to length(x) do
if (not PhoneBookItem(x[A])) then
return 0
end if
end for
end if
return 0
end type
-----------------------
PhoneBook PB
PB = {}
Now who wants to write code to actually items to the phone book?
Better yet, Who would dare to use this with type checking enabled?
unkmar
|
Not Categorized, Please Help
|
|