[RndTbl] PHP undefined vars / array indices

John Lange john at johnlange.ca
Wed Jan 19 09:08:52 CST 2022


> Which doesn't help this bug at all.  Of course, no language can ever
> tell you you probably meant to add a second $i=0

As a programmer it helps you in 2 ways.

First, as a programmer in a declarative language you get used to declaring
everything, so when you start to type the second "int $i = 0;" <--
it immediately generates an error in your IDE (if you have one) or a
compile time error. Of course, you might forget to declare, so that brings
me to point #2.

Second, when you are trying to debug why your loop isn't working the first
thing you are going to do is look for where this variable is initialized
and you immediately realize you screwed up and reused an old variable.

Of course our example is extremely simple but imagine a more complex
example where $i is modified in a dozen places and perhaps inside some
if-then statements are as the result of some other function, e.g. $i =
SomeFunctionResult();

I submit that in the non-declarative case you can easily spend a ton of
time trying to trace the logic in the lower section of code without
realizing your mistake (been there, done that).

Regarding Perl6, totally agree it should have been "Perl++". But in IMHO
Perl dropped out of favour because of a point I made earlier, it is very
often unreadable and therefore hard to learn and maintain. This is made
worse by the fact that Perl programmers take pride in writing the most
unreadable code possible (there is even a contest for this) and then look
down their noses at less "expert" programmers who struggle to understand.
This is very ironic given the whole reason interpreted languages were
developed in the first place was to make them more "human readable".

Congratulations Perl developers! You played yourself!

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://muug.ca/pipermail/roundtable/attachments/20220119/3a01e559/attachment.htm>


More information about the Roundtable mailing list