5 ms·
Perl vs Python vs Ruby (2002..2009)
- idlewords 17y agoI find arrow notation when dealing with references makes things a lot clearer in Perl. In the example, $r->[$SKUTITLE] rather than $$r[$SKUTITLE] 'use constant' for the numbered fields would also help, getting rid of a few dollar signs.
- elblanco 17y agoPerl's dereferencing semantics are atrocious. I love the language, but figuring out which combination of sigils dereference something can take forever. I'm so very glad they included arrow notation, that's literally saved me hundreds of hours. I've always had the impression that the basic dereferencing ($$r[$SKUTITILE]) semantics were more a function of clever Larry thought he could be than something that was well planned. If I'm not mistaken, the dereference notation changes again in Perl 6, but I haven't bothered to really check it out until the releases reach a production level.
- xiaoma 17y agoWhat's the point? It's nice that he decided to try a couple of new languages that he'd never written any code in before, but what significance does his experience of writing a trivial tool in each really have for other people? The blog post strikes me as a bit like a youtube video of somebody trying out a couple of musical instruments they haven't played before... irrelevant to people who don't know the submitter. flagged
- jrockway 17y agoYes, it is a worthless comparison. This specific application would look almost exactly the same in assembly language, so there is really not much to learn here. It is interesting to see that "I am switching from Perl to Ruby or Python" was something people blogged about in 2002, however.
- systems 17y agoAs simonw said, what's interesting is that people kept commenting for 7 years on this blog post. With some interesting notes * Most of them seem to be Perl folks * None of the language seem to offer anything new to solve that problem 7 years later * None of the languages converged, i.e. 7 years laters the advantages and disadvantages of each language seems to be the same
- berntb 17y ago>>The punctuation and my’s make this harder to read than it should be. Huh, declaration of variables should remove a typical error at least I do: foo = X if ... foi = Y .. if foo == X .. I really don't understand why the strict functionality isn't default in Perl and all other languages. Also, only total newbies initialize arrays like this: my @records = (); Most every time Perl is mentioned, we get an insane amount of trolling. It is quite boring. Now I'm out of jeans, into a good shirt and off for a party, so you have to work on someone else... :-)
- petercooper 17y agoJust picking on one section. The Python: contactRecords = filter(lambda r: r[1] == "1", contactRecords) Versus the Ruby: contactRecords.reject! {|a| a[1] != "1"} Yet the author points out that not everyone will appreciate the blocks.. even though the Python variant is using much the same thing, just as an explicit lambda. In what universe is the Python variant make readable? The variable name is repeated (not very OO like) and there's more syntactic salt and verbosity.
- jeremymcanally 17y agoI'm not sure we'd consider this good Python these days; Python had some ugly warts and quirks that got fixed in later versions.
- altano 17y agoWhat does the equivalent code in the latest version of Python look like?
- EliAndrewC 17y agocontactRecords = [r for r in contactRecords if r[1] == "1"]
- adw 17y agoAnd in reasonably idiomatic recent Python, the whole thing'd be: #!/usr/bin/env python import fileinput import csv EMAIL, CONTACTME, SKUTITLE = 17, 27, 34 tsl = csv.reader(fileinput.input(), dialect='excel-tab') for line in sorted([r[SKUTITLE], r[CONTACTME], r[EMAIL]] for r in tsl if r[CONTACTME] == "1"): print "\t".join(line) It's going to be good in any language though, isn't it?
- simonw 17y agoPeople seem to be missing what's interesting about this post... it has a single, continuous comment thread that spans 7 years.
- hbien 17y agoI guess if I want some traffic on my blog, I'll title it Emacs vs Vi =].
- tptacek 17y agoHere's an awesome comment: Perhaps your time would be better spent becoming a better perl programmer than to learn a new language? :) Seriously, it's unfair to compare bad perl code that doesn't use common idioms. If you write bad ugly code you've got nobody to blame but yourself. If it was something I was writing for myself I would use something like this. It's something I probably wouldn't use in production but it's a fairly decent example. The advantage over your example is that the sort comes after the grep, thus avoiding sorting records you are going to reject anyway, the same with quotes. my @recs = sort { $a->[0] cmp $b->[0] } grep { $_->[1] eq '1' } map { my @r = split /\t/; [map { s/"//g; $_ } @r[34, 27, 17]] } <>; print join("\t", @$_), "\n" for @recs;