[fpc-pascal] with statement using mulltiple objects
Bernd Oppolzer
bernd.oppolzer at t-online.de
Sun Sep 14 16:30:02 CEST 2014
Am 14.09.2014 15:39, schrieb Ched:
> Hello All,
>
> My two cents. The with statement is crystal clear for me. If newbies
> prefer to use different manners to code the things, that are free to
> do it. Using some kind of intermediate variable ? That's make to code
> difficult to understand, need do open begin/end blocks in some
> situations. With make the code very clear, probably helps the compiler
> a lot. Well used, it's 100% safe - I *never* encountered any problems
> with it in 25+ years of intensive programmation.
>
> So, they with statement has at least one aficionados: me. Was the with
> statement present if the first versions designed by Wirth himself ?
>
WITH was present in the first PASCAL versions,
and it was used in the PASCAL compilers designed by Wirth et al.
written in PASCAL in the late 60s and early 70s.
The possible dangers of using WITH are only very limited, compared
to other languages, for example PL/1, where
- you don't need to declare variables, like in FORTRAN
- you can omit structure qualifiers, if the the structure components
alone are unique
- if the structure component is A.B.C, you can write A.C, B.C or simply
C, if it is unique in the program
- if there is both a simple variable C and a structure component A.C (C
in an outer block),
I guess, A.C will be used, if you write only C (but I am not sure on
this; hopefully there will be
a compiler warning)
- if you have a combination of vectors and structures, the order of
structure components
and vector indices is not fixed, that is: A.C(N,M) is the same as
A(N).C(M) is the same as
A(N,M).C ... regardless of the definition of the structures / vectors A
and C.
You may read some old articles from Dijkstra and C.A.R. Hoare on this
topic,
covering PL/1 ... it is very hard to write reliable programs using this
language,
but it is still in use until today in very large banks and insurance
companies.
I am using it in my everyday work.
So: I would use the PASCAL WITH statement with care, knowing its problems.
PASCAL is far less dangerous than PL/1.
The other language which I use much is C. There you have other problems that
PASCAL (and PL/1) don't have, that is: vector indices out of range,
leading to
storage overwrites, and storage leaks, due to heavy use of dynamic
memory allocation ...
which needs careful testing. Both PASCAL and PL/1 can be used with
options that
control the vector indices, which is IMHO a great help in the early
stages of program
development.
Kind regards
Bernd
> Cheers, Ched'
>
More information about the fpc-pascal
mailing list