Type-check behavior
Maybe this is just me, but I think it's silly for Euphoria to do this...
-- Example 1
type string(sequence s) -- abend line
...
end type
? string(5) -- abends w/ type-check fail @ "abend line" (argh!)
-- ideally, it would just print 0 here
--
..which forces us as programmers to write our types like this:
-- Example 2
type string(object s)
if not sequence(s) then -- grumble grumble
return 0 -- it is annoying
end if -- to have to do this
...
end type
? string(5) -- doesn't abend, prints 0
--
What prevents Euphoria from "passing on" the sequence type-check failure in
Example 1 to the point where the string() type was called from, so it
*doesn't* abend?
The way things currently are, I define *all* my types like Example 2 above,
which means that the "object" type is the only one that ever gets used for
my type parms, and I have to start each type with a separate "if" statement,
checking for the type I would *like* to have up in the top line of my type
declaration. This makes my types less readable, and probably makes the types
run one precious picosecond slower as well.
Additionally, with type-checking turned off, all my user-defined types
become generic objects!
-- Example 1a
without type_check
type string(sequence s)
...
end type
string message
message = 5 -- abends, 5 is not a sequence
-- Example 2a
without type_check
type string(object s)
if not sequence(s) then
return 0
end if
...
end type
string message
message = 5 -- doesn't abend!
--
Anyone else think this is a problem?
Be seeing you,
Gabriel Boehme
---------------------
The obligatory quote:
To attract and keep an audience, art must entertain, but the significance of
any art lies in its ability to express truths -- to reveal and help us
understand our world.
Bill Watterson
---------------------
|
Not Categorized, Please Help
|
|