Keith Devens .com |
Friday, August 29, 2008 | ![]() |
| C++ is history repeated as tragedy. Java is history repeated as farce. – Scott McKay | ||
|
| ← Perl is difficult to program correctly in | The truth about the Baghdad museum → |

anonymous wrote:
Keith (http://www.keithdevens.com/) wrote:
For the first example you bring up, I dunno, I'll have to see if that's the same. However, I guarantee you the second example is not the same. In fact, my trim code is taken straight from perlfaq4 (although someone may have found a more Perlish way to do it). Besides the trim though, how could you possibly know what I'm substringing?
raptor wrote:
u are correct i was guessing... :")
anyway probably a simple change to the regex would solve your problem...
My point was that a simple one-liner by one-liner comparison is neither fair nor correct when someone have to compare languages...
I'm sure I can find many such cases that Python will look much badly, even that I'm not Python programmer..
It is in most of the cases personal feeling and "acustumisation" which language he will choose...
In your case .strip() was a unfair comparison 'cause it is not something that show something fundamentaly advantegous over perl.
just my 5c, dont take it personal :")
PS. in the past i was reading somewhere for program written in Java (around 30-40 lines of code) that the author calculated was faster and shorter than similar program written in Perl(afaik he wrote it).. what came out during a discussion of perl monks was a several perl solutions to the same problem written in 2-3 lines of perl-code which was faster.. so u see even a litlle longer program can't be trusted for such comparison..
so all depend on the context..etc..etc..
Keith (http://www.keithdevens.com/) wrote:
what came out during a discussion of perl monks was a several perl solutions to the same problem written in 2-3 lines of perl-code which was faster
Yeah, it's amazing what they can do sometimes.
In your case .strip() was a unfair comparison 'cause it is not something that show something fundamentaly advantegous over perl.
Well, it wasn't just the strip. The code also highlighted A. named function parameters, and B. that strings have list operators like ranges, in addition to the strip() trim() comparison. In fact, Python is pretty good that way in that many different containers (strings, lists, dictionaries, etc.) use list syntax. I've complained about this with Perl in the past: that because Perl uses different syntax for everything, it often makes it very hard to abstract things.
You're right though, these examples don't necessarily show that Python is "better" than Perl. Python is usually much more comfortable to me though. And I did wind up with a much shorter program, though by the time I finished it wasn't as much shorter as when I wrote this post.
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):
Generated in about 0.142s.
(Used 8 db queries)

why u should use this :
$self->{line_count} = scalar(@{$self->{lines}});
when u can do this :
$$self{line_count} = @{$$self{lines}};
why this :
#key
$_[1] = $self->trim(substr($_[0], 0, $n));
#value
$_[2] = $self->trim(substr($_[0], $n+1, $len-($n+1)));
and not this :
($_[1],$_[2]) = $_[0] =~ /^\s*(.+?)\s+(.+?)\s*$/
seems to me u have made it bigger on purpose to mislead
the ppl reading this :")... Or the other way is that u
think better in Python rather in Perl terms which is not in any way worse, just different way..