Perl isn't a good language for writing fast code in.
If I agreed with this I'd be disappointed - the perl porters put a lot of effort into improving the speed of perl, and trying to avoid speed loss.
It is true that perl wouldn't be a good choice for an interrupt handler (say), where you need to be able to impose very tight bounds on average and maximum latency.
However I have written lots of code that needed to be fast simply because it was doing an awful lot of work - the sort of recursive calculations that require billions of iterations - and I've found perl fine for such work. And for those cases, shaving a few microseconds can make a noticeable difference.
Similarly, when some code will create many millions of in-memory records, the few bytes-per-record saving that means you don't start swapping can also make a big difference.
I think the assembler background does give a helpful tint to the mindset, in that you get into the habit of applying the various micro-optimisations automatically, and the benefits do mount up.
The important thing though is to keep a balance, and not let the optimisations affect readability (hence maintainability) too much; and to remember that finding a slightly better algorithm will likely put all the micro-optimisations into the pale.
Hugo
| [reply] |
While Perl may be able to execute code fast, that isn't the focus of the language. The focus of Perl, as documented by many more Perlish than me, is to improve programmer efficiency. Now, it's nice to have efficient programmers while still having somewhat efficient programs, and I love it when that happens. I love being able to write programs extremely quickly that just happen to run quick enough so that I don't have to rewrite them.
But, the point theorbtwo is making is that, for the first writing of a program, you shouldn't worry about CPU speed, RAM, disk, or any other plebian item. The items that need to be concerned with in the first pass, in order, are:
- Does the program do what it needs to do?
- Does the program have any horrible crash-me type bugs?
- Did I finish the program in the time allotted to me by those paying me?
- Does the program have any medium-sized bugs that will occasionally trip users up?
- Is the program fast enough for the average usage?
- Does the program have any bugs at all?
- Can I improve the program's internal structure to make future changes easier?
- Can I improve the program's internal structure so that someone else can make changes without messing up my stuff?
Now, a requirement for item #1 may be "Execute in such-and-such time", in which case execution speed is a priority above programmer time. And, if that's the case, then Perl may not be the appropriate language for such an endeavor. If it is not, then Perl may be appropriate.
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] |