I respectfully disagree. First, philisophically I have a problem with using the word "ALWAYS" in any practice. It's tough to "ALWAYS" do something a certain way. In IT the usual answer is "IT DEPENDS", and it usually depends on a multitude of factors.
I would argue that assuming an initial state of valid or invalid is tomato vs. tomatoe. It's functionally equivalent to flag something as valid until it fails or invalid until it passes. The limitiations of 4GL don't allow an elegant coding approach here (at least I personally don't know it well enough). In a higher level language like C# I would create a collection of invalid characters and use something like the contains method against a string literal.
As far as testing individual characters, the subset of characters that disrupt a barcode is far smaller than those that don't. It's not practical to test for every other valid unicode character. I agree that coding should be as generic as possible, but that's not always pragmatic. Additionally, I don't know the underlying specifics of the 4GL compiler, but in most languages an IF statement containing multiple conditions will exit at the first failure, so the remaing conditions are never evaluated. If I were to test for every valid character, then every condition would be evaluated. From a sheer performance perspective with respect to CPU clock cycles the winner is clear.
While I agree genericism and future proofing are important concepts in design, performance is equally so. In the grand scheme of application development, my code is ridiculously small, and easily maintainable. Always willing to have a constructive debate on semantics!
Cheers,
Jared
I would argue that assuming an initial state of valid or invalid is tomato vs. tomatoe. It's functionally equivalent to flag something as valid until it fails or invalid until it passes. The limitiations of 4GL don't allow an elegant coding approach here (at least I personally don't know it well enough). In a higher level language like C# I would create a collection of invalid characters and use something like the contains method against a string literal.
As far as testing individual characters, the subset of characters that disrupt a barcode is far smaller than those that don't. It's not practical to test for every other valid unicode character. I agree that coding should be as generic as possible, but that's not always pragmatic. Additionally, I don't know the underlying specifics of the 4GL compiler, but in most languages an IF statement containing multiple conditions will exit at the first failure, so the remaing conditions are never evaluated. If I were to test for every valid character, then every condition would be evaluated. From a sheer performance perspective with respect to CPU clock cycles the winner is clear.
While I agree genericism and future proofing are important concepts in design, performance is equally so. In the grand scheme of application development, my code is ridiculously small, and easily maintainable. Always willing to have a constructive debate on semantics!
Cheers,
Jared
--- In vantage@yahoogroups.com, "wmc84" <wmc20@...> wrote:
>
> Nit-picking here. But Good Programming Practice says you should always assume a character is NOT valid, and test for valid ones. Valid characters are a well defined subset. The Invalid set is subject to expand. eg: in the future you may have a non-English speaking office using a multibyte character set like Unicode or something. Many security holes have also come about through code testing this way, as well.
> -Wayne
>
> --- In vantage@yahoogroups.com, "k99ja04" <jallmond@> wrote:
> > I'm working on a BPM to check and see if a part number is barcode friendly, as in doesn't contain special characters.
> > [[[ snip ]]
> > IF INDEX(STRING(ttOrderDtl.PartNum),' ') NE 0 OR
> > INDEX(STRING(ttOrderDtl.PartNum),'!') NE 0 OR
> > INDEX(STRING(ttOrderDtl.PartNum),'@') NE 0 OR
> > INDEX(STRING(ttOrderDtl.PartNum),'#') NE 0 OR
> > INDEX(STRING(ttOrderDtl.PartNum),'$') NE 0 OR
> > INDEX(STRING(ttOrderDtl.PartNum),'%') NE 0 OR
> > INDEX(STRING(ttOrderDtl.PartNum),'&') NE 0 OR
> > INDEX(STRING(ttOrderDtl.PartNum),'*') NE 0 OR
>