Re: Sequences - parameter checking responsibility

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

> Because a sequence is so generic, any sequence will pass type
> checking without necessarily being in the
> the correct form for that function.
        So make a type...

> Should the responsibility beyond type checking belong
> to the function or to programmer who calls it?
        That should be optional...
        If you use a type the programmer has a choice..
                ..in developping time have type_check on.
                ..when your program is finished turn it off.
        If type_check is on, it will generate an error if the value passed
is wrong. The advantage is you know you it's because of wrong
arguments and not a bug in the routine...
        For speed, turn type check off when you KNOW you program will not
give any errors.
        Setting type_check makes sure you get the right error message.
        A program isn't finished until there are no errors in it.. so....
here's your solution.
        BTW You should only check the value passed when it will produce an
error if it's wrong. That's the rule... all values that do NOT
generate an error should be allowed, you never know where you can use
your function for later on.

> On the other hand, with sequences, there can be an awful
> lot of checking that must be done, which can slow down the
> function.
        Yeah..but in design time...speed is not needed and when its finished
put a without type_check on top of your program.

> If the responsiblity is on the programmer who calls the
> function, where should the function writer store the
> information, so the programmer can code the sequence
> correctly?
        Well, it will always generate an error the programmer should deal
with, if its a type_check error you know that you gave bad values to
your function.

> In my real-life example the sequence passed as the parameter
> must contain at least one, but may contain multiple sequences.
> Also the sequences within sequences must be composed of atoms,
> not other sequences.

        You mean 2D-sequences ? (Like images and stuff)
        I guess so...

        Here is what it should look like:
        In your program type:

        "with type_check"   to turn it  on
        (all calls after this will have their values checked.)


        "without type_check"  to turn it off
        (all calls after this allow all objects)

----------- Code begins here: ---------------------------------------

        type 2D_Sequence (sequence s)
                for j = 1 to length(s)
                        if sequence (s[j]) then return 0 end if
                end if
                return 1                  -- Value ok
        end type

        global function xyz ( 2D_Sequence s )
        -- code
        end function
------------------------------ Code ends here --------------------

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

Search



Quick Links

User menu

Not signed in.

Misc Menu