Live data from Hacker News

Why I Use Perl: Reliability

modernperlbooks.com

51–60 of 196 posts

Re: Why I Use Perl: Reliability

#51
post #38
post #27

Earlier quoted context omitted.

Lets see, what about factorial in constant memory? Exponentiation (a to the power of b, where they are positive integers) in logarithmic time (not using built-in exponentiation functions/syntax)? Anonymously add a constant to a number and return it (in a way that can be passed to a function like 'map' or some such)? def Factorial(x): output = 1 for i in xrange(x): output *= (i + 1) return output def Factorial2(x): re…

Thanks for that. First one (not 100% sure it's constant memory, I think perl optimises the for to avoid instantiating the (1..$n) list: #!/usr/bin/perl use Modern::Perl; use bigint; say fact(5000); sub fact { my ($n) = @_; my $output = 1; for my $i (1..$n) { $output *= $i; } return $output; } (Took the value up to 5000 to get something which ran long enough to get a measurement, on my laptop it runs (including startu…

First one (not 100% sure it's constant memory, I think perl optimises the for to avoid instantiating the (1..$n) list:

It does since 5.005 - so for a good long time now :-)

The reduce version (again, I'm unsure of const mem req). Comes in at ~1.4s:

This would allocate the array I'm afraid. You'd could use something liek List::Gen's reduce() to get around that.

Re: Why I Use Perl: Reliability

#52
post #45

I was about to note that the OP clearly hasn't used Clojure if he uses it as a negative example in terms of reliability, but then I remembered — I promised myself not to get too deeply into these kinds of silly discussions. So, dear OP, good luck writing your large-scale multithreaded high-performance distributed applications using Perl. And BTW, I do use Perl quite a bit and I really like it, for certain tasks. But…

That's not a comparison he makes.

Re: Why I Use Perl: Reliability

#53
post #37
post #27

Earlier quoted context omitted.

Lets see, what about factorial in constant memory? Exponentiation (a to the power of b, where they are positive integers) in logarithmic time (not using built-in exponentiation functions/syntax)? Anonymously add a constant to a number and return it (in a way that can be passed to a function like 'map' or some such)? def Factorial(x): output = 1 for i in xrange(x): output *= (i + 1) return output def Factorial2(x): re…

use bignum; use v5.10; =cut def Factorial(x): output = 1 for i in xrange(x): output *= (i + 1) return output =cut # Direct translation sub factorial { my $x = shift; my $output = 1; for my $i (1 .. $x) { $output *= $i; } return $output; } say factorial(200); =cut def Factorial2(x): return reduce(operator.mul, xrange(1, x + 1), 1) =cut use List::Util "reduce"; sub factorial2 { my $x = shift; reduce { $a * $b } (1 .. $…

Just in case anyone was wondering, in Perl 6:

    sub factorial($n) {
        my $output = 1;
        for 1..$n -> $i {
            $output *= $i;
        }
        $output;
    }
or

    sub factorial2($n) {
        [*] 1..$n;
    }
Pretty anonymous function to add a constant:

    -> $x { $x + 7 }
Really short version:

    * + 7
Named:

    sub plus7($x) {
        $x + 7;
    }

Re: Why I Use Perl: Reliability

#54
post #50
post #38

Earlier quoted context omitted.

Thanks for that. First one (not 100% sure it's constant memory, I think perl optimises the for to avoid instantiating the (1..$n) list: #!/usr/bin/perl use Modern::Perl; use bigint; say fact(5000); sub fact { my ($n) = @_; my $output = 1; for my $i (1..$n) { $output *= $i; } return $output; } (Took the value up to 5000 to get something which ran long enough to get a measurement, on my laptop it runs (including startu…

I don't program in perl now a days. But when I did, I generally used perl's shortcuts a lot. For example: return reduce(sub { $a * $b; }, 1, (1..$n)); would be: reduce { $a * $b } 1..$n; This my $output = 1; for my $i (1..$n) { $output *= $i; } would be: $output *= $_ for (1..$n) So, I have a question for you(assuming you write perl for a living). Is this your preferred style, or you do this to appease readability po…

My production style is happy to use:

    $output *= $_ for (1..$n)
and you're right to call me on it. If I am writing a multi-line for loop, I do like to name the loop var though.

I think this is an interesting point (in a discussion about readability), do non-perl coders think the one-liner (with 'for' suffix) is more or less readable?

(I also prefer explicit return for maintenance reasons, except possibly in one-line subs)

Re: Why I Use Perl: Reliability

#55
post #47
post #27

Earlier quoted context omitted.

Lets see, what about factorial in constant memory? Exponentiation (a to the power of b, where they are positive integers) in logarithmic time (not using built-in exponentiation functions/syntax)? Anonymously add a constant to a number and return it (in a way that can be passed to a function like 'map' or some such)? def Factorial(x): output = 1 for i in xrange(x): output *= (i + 1) return output def Factorial2(x): re…

> def Factorial(x): output = 1 for i in xrange(x): output = (i + 1) return output Umm, did you mean: def factorial(x): output = 1 for i in xrange(2, x): output *= i return output Here are the perl versions. Such trivial examples are going to look the same in languages which share the same paradigms. use List::Util qw(reduce); # This is how I would write it. sub fact1 { my $num = shift; my $output = 1; $output *= $_ f…

Based on the examples, I presume xrange(x) is every integer up to but not including x. ie 1..^$x in Perl 6, don't recall if that's the Perl 5 syntax or not.

Re: Why I Use Perl: Reliability

#56
post #45

I was about to note that the OP clearly hasn't used Clojure if he uses it as a negative example in terms of reliability, but then I remembered — I promised myself not to get too deeply into these kinds of silly discussions. So, dear OP, good luck writing your large-scale multithreaded high-performance distributed applications using Perl. And BTW, I do use Perl quite a bit and I really like it, for certain tasks. But…

I was about to note that the OP clearly hasn't used Clojure if he uses it as a negative example in terms of reliability, but then I remembered — I promised myself not to get too deeply into these kinds of silly discussions.

Erm... He didn't? He said:

"While so much of the shiny-chasing buzz in the micro-ISV startup built-it-and-they-will-fund world seems to chase Clojure and Node.js and app-in-a-page tricks, Perl 5 continues to be my workhorse."

No comment on the reliability (or otherwise) of Clojure.

And much as I love Clojure - there's an element of truth there. Lots of folk using it because it's the new-and-shiny rather than it being necessarily the best solution. I know I've binned some Clojure stuff that would have been fun for me - because adding the JVM to the mix in production wouldn't have helped us actually get stuff done.

(and while it's an unfair comparison - since it's a vastly younger language - the transition to 1.3 wasn't fun for many folk :-)

Re: Why I Use Perl: Reliability

#57
post #44
post #38

Earlier quoted context omitted.

Thanks for that. First one (not 100% sure it's constant memory, I think perl optimises the for to avoid instantiating the (1..$n) list: #!/usr/bin/perl use Modern::Perl; use bigint; say fact(5000); sub fact { my ($n) = @_; my $output = 1; for my $i (1..$n) { $output *= $i; } return $output; } (Took the value up to 5000 to get something which ran long enough to get a measurement, on my laptop it runs (including startu…

that also highlights one of my perl peeves - having to scrape function args out of @_ rather than declaring them as part of the function definition.

Most of your life's problems can be solved at CPAN. :-) Just write:

  use Method::Signatures::Simple;
http://search.cpan.org/~rhesa/Method-Signatures-Simple-1.02/...

But you might instead want to look at this (or similar with Moose support) to get simple type declarations:

http://search.cpan.org/~barefoot/Method-Signatures-20120523/...

Re: Why I Use Perl: Reliability

#58
post #5

I remain unconvinced. Should the amount of effort that it costs to update the interpreter really be the main consideration?

Not at all. You shouldn't be updating the interpreter unless you have to, and then it should be done through your distro's package management and standard upstream path. The OP seems to think it's a good idea to upgrade his production code to the newest stable interpreter just because it was released. This is a recipe for disaster. Sometimes there are just hidden bugs you don't see until a weird use case blows up you…

Your rule ("don't change anything") is also an argument for never adding features!

There's a tradeoff here that you're glossing over. Given that each newer version is presumably some amount better than the previous one, eventually the benefits of upgrading will outweigh the costs, at least if you're going to continue making changes to your software.

I don't think chromatic was saying "everyone should immediately upgrade to the latest version of Perl". I think he was saying "upgrading to the latest version of Perl isn't as scary/costly as some people think; I did it, and here's my experience."

Also, keep in mind that sometimes there are hidden bugs in the old version, too. My employer just ran into a problem with the de-allocation of deeply nested structures being implemented inefficiently in Perl 5.8 (which has been in production for close to a decade); the bug was fixed in 5.14.

Re: Why I Use Perl: Reliability

#59
post #40

Earlier quoted context omitted.

Is COBOL still used by banks? Short answer: Yes :-) Still the backbone of many banks, building societies, credit card companies, etc. See http://www.careerjet.co.uk/cobol-jobs.html for some of job adverts. This old 2009 article http://www.guardian.co.uk/technology/2009/apr/09/cobol-inter... is still pretty much true AFAIK.

Thanks for the links - looks like the COBOL jobs are not promoted as much (I couldn't find any on the four bank sites I looked at) but still there, and reasonably well paid too.

Most of those COBOL jobs were offshored or are now performed by Indian/Asian vendor non-immigrant visa holders imported.

Within hour drive from my house, I can tally at least a half-dozen corporate IT shops that outsourced heavily in this way, axing thousands (in aggregate) of jobs that normally were served by internal/domestic consulting houses.

Yes, on the backend there is still a lot of COBOL, even if it is running on micro-hardware as opposed to the old big iron. Claims adjudication, utility metering, charge card processing, billing for just about any corporation that existed pre-1980, etc.…

Re: Why I Use Perl: Reliability

#60
post #49

The readability arguments need to include such modules as Method::Signatures::Simple, which replaces the old manual method (no pun intended) with: method foo ($a, $b) { $self->blargh($a + $b); }

Is "my ($self, $a, $b) = @_" really that hard to read? It's slightly more characters but I've never found it particularly annoying.
Post reply on HN