Hello --

On Mon, 13 May 2002, Patrick May wrote:

> David Alan Black <dblack / candle.superlink.net> wrote in message news:<Pine.LNX.4.30.0205121112470.26952-100000 / candle.superlink.net>...
> > An array seems to me like a more natural container for multiple values
> > than a string.  I guess I'm not sure what you would ever do with such
> > a string, except split it on $/ and get an array :-)
>
> Array is the more natural container for multiple values than a string.
>  A string is the more natural container for a single value.

My point, though, was that although "val1\0val2\0val3" is a single
value, it seems to me to exist as a way to package multiple values
into a string, probably for the purpose of eventually getting at them
array-wise anyway.  (We may be talking slightly at cross purposes
because my comment was CGI.[] returning a \0-joined string, rather
than its returning the equivalent of the present c["x"][0] idiom.)

> However, given a form, the programmer can safely assumptions,
> including:
>
> + the meaning of different param keys
> + whether a param should be treated as having single or multiple
> values

Yes, but not whether the param actually *has* single or multiple
values :-)

> Dealing with unexpected input is usually done in the form of sanity
> checking asserts.  Once the input differs from the 'contract' of the
> form, the correct behavior is usually to fail.  After the asserts, the
> programmer controls how s/he wants to treat the data.

This is one thing I'm still puzzling through -- whether changing from
the array-based style would introduce the need for a lot more
checking.

> This change would make using a singular param easier.  In my
> experience, this is the common case by a long shot.
>
> # -- now --
> # confusing ways to get a single value
> name, = cgi["name"]
> name = cgi["name"].to_s
> name = cgi["name"][0]
> name = cgi["name"].join("/0")

OK... but they're different single values (i.e., those four things do
not all produce the same result).  Therefore:

> # -- future --
> # quick way to get single value
> name = cgi["name"]

would not be a replacement for all of the above.  I guess for to_s
you'd do:  cgi["name"].values.to_s (probably a very rare case
anyway).


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav