DC> [TP .EXE's not initing variables]
MC> I've always deplored this behavior (the IDE does which I don't
MC> use), since it leads most newbie (or lazy) programmers to believe
MC> that Pascal _does_ initialize variables...so the programmer doesn't
MC> have to do this "extra work".
DC> Nice to know this :-) I'd *almost* become lazy in initialising
DC> variables, since from what I could tell it was done for me, but I try
DC> to make code that is easier to port and I couldn't garantee that
DC> another platform would work the same.
DC> However, many of my variables are init'd the first time they're use
DC> (eg A := C), is there anythin wrong with not setting A to 0 since it
DC> gets the value of C before being used anywhere else?
The principle is simple: the value of any Pascal variable is
_undefined_ until it's explicitly assigned (some value). Thus, if you
always assure that the variable has a _defined_value_, you can use it
with assurance that it's okay. Assigning it a value can be done in
several ways: an assignment statement (A := 0.0); an i/o statement which
places some value into it (Readln (A)); a function call which returns a
value (A := Sqrt(4.0)); and even a TP/BP "initialized variable"
(non-standard Pascal, of course).
The point is to assure that _some_ value assignment has been done
prior to using a variable with any expected valid value.
... Can't Win, Can't Break Even, Can't Quit...
--- OMX/Blue Wave/DOS v2.20
---------------
* Origin: Mike's Place (1:114/307.0)
|