The reason it's so hard to read and error-prone isn't the number of sigils in my opinion; it's the amount that's variable.
These parts are fixed:
for my ___ ( ___ .. ___ ) # Perl
for ( ___ ; ___ ; ___ ) # C
We can quickly identify these as counting loops, and we can quickly identify and locate the parts that define the loop. (Well, the number of sigils in the C version does make this harder, so the number of sigils is a factor, but I believe this to be a secondary factor.)
So what's left? In the Perl version, we have $i, 0 and 9. Clearly unbeatable for clarity in this trivial case. But it supports more complex cases well too.
In the C version, we have my $i = 0, $i < 10 and $i++. That's 9 tokens (when counting $i as one)!!! And all of them could vary. Is < used or <=? Maybe neither... Is my used? Is the same var used throughout? etc etc etc etc There are so many variations that the whole must be analyzed each time it's encountered.
Most of the time, the loops takes on the following shape:
for ( my ___ = ___ ; $same < ___ ; ++$same )
But variations occur too often to assume the loop takes on this shape. And it's not always easy to spot if a variation is used at glance. But we make this assumption anyway, and that's when mistakes happen. This is why it's also error-prone.
This is the same reason we use subs. We sacrifice flexibility, but we gain readability and reliability.
|