Mark said:
Maybe I've just been programming for too many years and looked at too
much code written by people who like to take shortcuts, but I think
your cases 1/2 should never be used! In fact I avoid any syntax that
has a default such as "while (<>)" which is why I always use "while
($var=<>)". After all, you never know when someone is going to
insert a line of code that blows away your default with a different
one. In other words it's all about supportability!
It's also common for someone to pick up a piece of code in a language
they're not familiar with and try to figure out what it does with
minimal effort and having something that is not obvious is a real
pain. Are people that lazy that typing a few extra characters to
make what they're doing more explicit too much of a burden?
I am somewhat torn. You certainly have a very valid point and taking
shortcuts that lead to unreadable code is definitely not a good idea.
On the other hand a lot of the elegance of Perl comes from its default "work
space". It is so ingrained in the Perl world that I would almost call it a
prerequisit for programming in Perl. If you don't know how to take advantage
of $_ and @_ then maybe you shouldn't program in Perl or maintain Perl code.
How is
this any different from commenting code? Or don't people do that any
more either?
Now that is actually comparing apples and oranges. I think you would agree
that a comment like
$index++ #increments $index by 1
is nonsense. Correct, but still nonsense. Comments should describe _what_ is
being done, not _how_ it is done. So the comment above should be something
like "examine next personal file" or whatever action this increment
indicates.
Now, if you were using
shift @_;
instead of relying on the default as in
shift;
then you would just re-state information that is already there anyway, just
like with the stupid comment above. If this shift moves on to the next
personal file, then by all means comment it as such. But replacing shift;
with shift @_; doesn't add any new information for the code maintainance
person as long as he has at least a basic understanding of the language.
jue