Title: RE: [CFCDev] Check for Empty Strings in Required String Arguments

>Personally, I would return an empty array, with one empty element, the rationale being:
>...
>shouldnt the behaviour be the same? (not that cold fusion agrees with this
rationale...)

With these things, I always try to mirror as closely as possible CF's behaviour (whether the behaviour makes sense or not).  So I'd return arrayNew().  My rationale here is that CF has set a precendent, and it's more predictable if custom functions follow CF's lead.

(Obviously CF's precedent when it comes to lists is an annoyingly daft one, but… oh well).


1. IF an empty string was an invalid input (i.e. you just should NOT be having an empty string at that point) - you should check for it in the function and throw the error

I think that's dangerous ground there.  Generally, if a zero-length string is inappropriate "at that stage", it should be tested for by the calling code, and the function should not be called at all.  It is not the business of a split() function (in this example) to decide that a zero-length string is inappropriate.  I think it's much rarer for a zero-length string to be a completely unacceptable value for a string argument.

I note that in CF, this fails:
REReplace('test string','','foo')
However in JS, the equivalent passes:
s1 = "test string";
S2 = s1.replace("", "foo");

I agree with JS.

CF doesn't seem to automatically fail many of its string functions on zero-length strings.

But, yeah, your point stands that there's no hard-and-fast rule with these things.
--

Adam Cameron
Senior Developer
Straker Interactive

e: [EMAIL PROTECTED]
t: +64 9 3095252
f: +64 9 3092797
w: www.straker.co.nz

Reply via email to