Re: Need help with REDEFINES (I think)....

From: Pete Dashwood (dashwood_at_enternet.co.nz)
Date: 11/25/04


Date: Fri, 26 Nov 2004 01:49:00 +1300


"Lueko Willms" <l.willms@jpberlin.de> wrote in message
news:9LXUmMNeflB@jpberlin-l.willms.jpberlin.de...
> . On 25.11.04
> wrote dashwood@enternet.co.nz (Pete Dashwood)
> on /COMP/LANG/COBOL
> in 30khlrF315qomU2@uni-berlin.de
> about Re: Need help with REDEFINES (I think)....
>
>
> PD> (Besides, that's the boring bit; the FUN bit is addressing the size
> PD> incompatibility... <G>)
>
> and in COBOL, there is this ON SIZE ERROR phrase, which is the
> appropriate thing to use in this case.
>
Hmmm... that is your opinion, Lueko.

I disagree.

Here's my opinion... <G>

> Maybe preceded by a IF NUMERIC check, so:
>
> IF source-variable NUMERIC
> THEN
> COMPUTE destination-variable = source-variable
> ON SIZE ERROR
> *> do the appropriate thing, e.g.
> DISPLAY
> "Hey - the source-variable " source-variable " doesn't fit!"
> NOT SIZE ERROR
> *> rejoice the happy end
> CONTINUE
> END-COMPUTE
> ELSE
> DISPLAY "The source-variable " source-variable " is not numeric!"
> END-IF
>
I see the numeric validation as separate from the size issue and IF NUMERIC
is a very poor way to check numeric input data. (certain alphas, that just
happen to be in the right position and have the right value, may be
considered signs and let through... A plus, minus, or decimal point may all
invalidate the field). If you make the numeric check device dependent (by
setting numeric attributes on a 3270 for example) your code is locked in to
a device that will do the check for you. If you then transport the code to a
different system you may find an alarming increase in the number of input
data errors.

I use a component that expects a standard device independent string and
checks each character of it to decide whether it represents a number or not,
recognising that the string may contain leading or trailing signs and a
single decimal point. It then sets properties that give me the number in
various internal and external formats. Plus a whole lot more besides.

Editing and validation of formats should occur in the presentation layer of
the system, not in the business logic.

>
>
>
> and let the compiler chose the optimumt for checking the size error
> instead of inventing the wheel anew.
>

The solution which Walter posted is simple and imaginative and it does not
preclude the compiler optimizing it. Neither does it reinvent the wheel. It
is also much more efficient (if you are bothered about that) than IF NUMERIC
( a compiler generated subroutine) or ON SIZE ERROR (another compiler
generated subroutine) because it uses a simple compare (or series of
character compares) and branch on condition. (Obviously the generated code
will vary on different platforms; I am basing the above on my experience of
IBM mainframe and the Intel platform.) I believe that the general outline
would be fairly consistent across platforms, but even if I'm wrong and there
is one (or more) platforms where IF NUMERIC and ON SIZE ERROR are INCREDIBLY
efficient, I still like Walter's solution better...<G>

The efficiency of it, while a positive factor, is not what sways me here...
it is the simple elegance of it.

The other solutions are clumsy and unwieldy in comparison.

(It is so cool, I wish I'd thought of it!)

Pete.



Relevant Pages

  • Re: "Sorting" assignment
    ... issue on some ancient compiler doesn't make a lot of sense. ... to his on a few commonly used platforms and compilers, ...  Be sure and call the swap ... reason to find algorithms which operate independent of it. ...
    (comp.programming)
  • Re: Death of Kylix and migrating towards Java
    ... But it can't beat Delphi's compiler speed! ... app developers on non-Windows platforms. ... It is NOT Delphi. ... > I do agree that Kylix was a very good promise and concept, that Borland ...
    (borland.public.delphi.non-technical)
  • Re: Is Assembler Language essential in compiler construction?
    ... emulator or compiler with a *restrictive* license ... for use on multiple platforms. ... for sandbox and general purpose applications. ... the development or runtime system doesn't support future versions of the ...
    (comp.compilers)
  • Re: Using C to program the 8051 family
    ... C may be fine for larger platforms but it's ... > you forget to turn the optimizer off. ... You must either trust the compiler or learn to use a ... > language to debug by. ...
    (comp.arch.embedded)
  • Re: vm02 preview #4
    ... To compare the interpreter against other interpreters or code ... This case is a nice one of checking compiler and interpreter efficiency. ... If the compiler was a little smart, there are lots of loop invariants to be pulled out of the color calculation, but I don't think the Java compiler is that smart. ... And vm02 has a type-ahead buffer and pre-emptively schedules. ...
    (comp.sys.apple2.programmer)