Ben Morrow said:
Quoth Rainer Weikusat <
[email protected]>:
[...]
-----
$tabs = $ARGV[0] =~ /^\t*/ && $+[0];
-----
-----
($tabs) = $ARGV[0] =~ /^(\t*)/;
$tabs = length($tabs);
-----
But they utilize different methods of calculating this value and while
the first requires perl (5.10.1) to perform nine basic operations, the
second needs fourteen, not the least because it reimplements a feature
the perl regex engine already provides
[...]
As I have said many times before, if you are concerned about that level
of efficiency Perl is almost certainly the wrong language to be using in
the first place.
The statement "If you are concerned about the way perl executes
Perl-code, you shouldn't be using Perl" doesn't seem to make much
sense to me: I'm concerned about this precisely because I use Perl and
I'm (for hopefully obvious reasons) interested in being able to use it
for anything where technical concerns, execution speed of the code
being among them, don't require taking a much more time-consuming
'other route'. The perl VM is a tool I'm employing to solve technical
problems and the more I know about this tool the more effectively can
I use it.
The first rule of optimisation is 'Don't'.
'Optimization' is a mathematical term and it means 'finding an optimal
solution to a certain problem'. It doesn't really have a clearly
defined meaning when being applied to programming. Chances are that I
agree with your opinion for the definition of 'optimization' you
happen to have in mind. But that would be a different question.
All forms of writing, in natural or artificial languages, should be
considered a work of art at some level. (Incidentally, this is the
principle upon which the idea of copyright in computer programs is
based.)
The principle upon which the idea of 'copyright' (or 'patentability
of') computer programs is based is "There's serious money to be made
here and competion in the marketplact is bad for maximizing ROI." Pro
forma, it rests on the assumption that code would be overwhelmingly
the result of 'individual creative expression'. Expressions like the
first one quoted above rightfully cast some doubt on this
concept. They're more akin to mathematical formulas which can't be
copyrighted (or patented, at least in theory), because they are
discovered and not invented.
While material technical considerations are more important than
questions of aesthetics, in this case, unless the code in question is
part of an inner loop you have previously determined is causing a
significant performance problem, there is no *material* technical
difference between the two.
Unless the Titanic sank, there's no reason to assume it ever would.