in reply to Re^4: RFC: Should join subsume reduce?
in thread RFC: Should join subsume reduce?

First of all, LISP hasn't been a total failure commercially. Viaweb aka Yahoo! Store comes to mind first.

No one I know had even heard of Viaweb before Paul Graham began touting it as a "success story for Lisp"! Erlang is the closest thing I've heard to a "success story" for FP; and it's an isolated case. Unix isn't written in LISP; Windows isn't written in LISP; in fact, all those horrible old LISP machine OS failed to compete with C. systems for decades. Functional programming isn't new. It's been the "latest, greatest thing" for the last fifty years or so. It's still not worth the hype, IMHO.

it was rewritten a few years ago in Perl/C++. Though I think that was more because they lacked in-house expertise once Paul Graham left.

Code that relies on individual heroics doesn't scale; that's part of my objection to functional programming. If you need to be able conceputalize the current state of sixteen different helper functions in order to keep the state of the function clearly in your head, you're probably going to fail, unless you're very smart. And when you leave, your replacement won't be, and the company will tank completely.

And just because you have trouble groking map and other functional code, that doesn't mean it wouldn't make perfect sense to someone who thought differently or had a better grasp on the subject.

You know, ad hominem is bad argument. :-( And while I may not be the best Perl programmer, I have been programming for a while (professionally since 1991), and what's more, I'm a good enough programmer to know my own limitations. I check my assumptions; and I did in this case, too.

One of my best friends is a LISP expert; though he and I disagree violently on the value of functional programming, he agreed in every single case when I asked him (and I asked often) that the functional code I was seeing was just plain bad, wrong, or occasionally, even "insane". Believe what you will of me or my abilities, but it's not just me. The FP devotees claim it's possible to write good FP code, but it's not what happens in the field, in my experience.

Aspects of functional programming are quite useful and a PITA to replicate imperatively.

I disagree. Being forced to reassemble an series of bottom-up self-referential maze of semi-correct function mappings into a single, coherent business rule is far less productive than just reading the imperative rule directly from the code.

Remember, when someone writes code, what they write doesn't matter much: in six months, it will be replaced anyway. The purpose of what they wrote it is critical; and the more layers of abstraction between the business and the code, the harder it is to discern intent.

Would you really rather read:

sub transform { my $coderef=shift; reduce($coderef,@_)/(@_+1); } sub display { printf("Avg: %f",transform(sub { $a > $b ? $a : $b },@_)); }
OR
sub display { my (@quarterly_results) = @_; # compute the arithmetic mean (average) of the results # for the past four quarters printf("Avg: %f", average(@quarterly_results); } sub average { my $average; $average = sum(@_)/ scalar(@_); return($average); }

The first example is "more clever", and more typical of the FP crowd. The second is "stupider", "more boring", and ore typical of my code. I find it easier to follow the business logic, so that when my code breaks, someone can fix it.

Throw in several more layers on the call stack, and the differences become even more pronounced; when the return value of a function is literally composed of a hundred little calls to other functions, each of which tampers with different states of different variables in different scopes, it's really, really hard to reconstruct what's being done, let alone WHY. True, that's not pure FP (lots of side effects), but it's what perl supports as FP, and it's what I get saddled with by FP-wannabees.

Encouraging more functional programming will at best lead to more ivory tower code, comprehensible only to the wise few, and at worst to the drek I see lately, where FP concepts are tangled with side effects of all sorts of scopes and flavours, and the net effect is a mess uglier than most.

I'm taking a pragmatic point of view: it's like if you serve alcohol at a bar, you hire bouncers. There's no reason, in principle, why people can't be rational, reasonable adults when they drink, and conduct themselves well, and leave when asked. In theory, you won't find piles of vomit all over the floor. In practice, you'ld better get the bouncers out and the puke buckets ready! Adding alcohol in the form of FP to Perl might be fun for you, but for me it just means more code puke to clean up.

--
Ytrew

Replies are listed 'Best First'.
Re^6: RFC: Should join subsume reduce?
by Aristotle (Chancellor) on Feb 22, 2006 at 01:55 UTC

    I really have to wonder why are you even using Perl in the first place; it gives people way too much rope, FP or not.

    No one I know had even heard of Viaweb before Paul Graham began touting it as a "success story for Lisp"!

    And that proves what, exactly? “Noone I know has” is a classic case of unrepresentative sample.

    The first example is "more clever", and more typical of the FP crowd.

    The other Anonymonks have already called you out on that one; this is a straw man.

    Quit the fallacies.

    Makeshifts last the longest.

      I really have to wonder why are you even using Perl in the first place; it gives people way too much rope, FP or not.

      Well, the guy doing the maintenance doesn't get to choose the language he maintains.

      And that proves what, exactly? “Noone I know has” is a classic case of unrepresentative sample.

      In response to a single example anecodote, I didn't feel it was out of place.

      The other Anonymonks have already called you out on that one; this is a straw man.

      I still don't think so; every single definition of a function in List::Util explains the function in terms of reduce(), implying that if you'ld only use reduce() for everything, you wouldn't need all these other functions.

      Quit the fallacies

      Quit the hypocrisy. You and I both know that FP isn't mainstream, and that it's been a known technique for well over fifty years, and that there are damn good reasons for it. This is a known argument; it's been proven, it's DONE. If you want to retread fifty-year old ground, you go do it: you know you're wrong, and I'm getting tired of the trolling, and the miscategorization of my posts.

        every single definition of a function in List::Util explains the function in terms of reduce(), implying that if you’ld only use reduce() for everything, you wouldn’t need all these other functions.

        That seems like a stretch. In the documentation I’m looking at, the reduce analogy always follows last, after an explanation of what the function in question does. The way I see it, it’s there as a guide in case you need to do something slightly different from what the builtin function does.

        You and I both know that FP isn’t mainstream, and that it’s been a known technique for well over fifty years, and that there are damn good reasons for it.

        There was a long-standing debate over whether structured programming was better than GOTOs in times past. When object-orientation was first championed by C++, its benefits had to be sold to each developer and manager individually.

        Draw your own conclusions about what I think of your argument.

        The damn good reasons are in the silicon, not the carbon.

        Makeshifts last the longest.

      I really have to wonder why are you even using Perl in the first place; it gives people way too much rope, FP or not.

      How is making things worse going to rectify that flaw?

      And that proves what, exactly? “Noone I know has” is a classic case of unrepresentative sample.

      A sample size of one was hardly representative to begin with. No one has presented an argument to explain when and why the majority of industry moved towards functional programming; that's of course, because it hasn't ever done it, despite ample opportunities. Prove it for yourself if you don't believe me; I think you'll find everything from operating systems to databases to web browsers written in an imperative or object oriented style. A single example, (which later reverses itself), is hardly compelling evidence of the superiority of functional programming in industry.

      The other Anonymonks have already called you out on that one; this is a straw man.

      No, it isn't. The List::Util system is quick to explain how all these typical functions can be implemented using reduce(), and that reduce() is the only function you really need.

      An approach that contrasts the approach advocated by the reduce-is-everything FP crowd was exactly what I contrasted with a normal, non-clever approach.

      Quit the fallacies.

      Fine. Why don't you quit your own, then? Quit the self-denial that says that FP is a major industry player, or appropriate for the workplace. Quit the cowboy mentality that goes with FP; the elitist crap that says that since something *can* be made complex, it *must* be made complex. Quit the "lets have fun being clever" approach to code; and go with trying to actually make code simple, obvious, and maintainable. Try professionalism for a change.

      Okay, rant over. I doubt I've convinced you of anything, so I quit. You "win".

        Quit the “lets have fun being clever” approach to code; and go with trying to actually make code simple, obvious, and maintainable. Try professionalism for a change.

        Are you implying that I put obfuscated code in production? Have you seen any code I’ve written? Excuse me while I laugh with gusto.

        Have you tried writing callback-heavy code, like, oh, GUIs f.ex., both with closures and without? Do you care to dispute the fact that having closures available makes such code about 100 times easier to write and clearer to read?

        Makeshifts last the longest.

Re^6: RFC: Should join subsume reduce?
by shotgunefx (Parson) on Feb 22, 2006 at 02:59 UTC
    No one ever heard of Yahoo! Store? Well apparently between 20-30K merchants did.

    And of course, your LISP friend would say the code you showed him was horrible, it's not in LISP. :P

    (I'm only half kidding, my very limited experience is that LISP programmers look down on everything not LISP. Maybe just me though. Though I could swear I remember someone in the LISP community calling Perl, "Lisp with Cancer" )

    It wasn't heroics either to keep it going, C/C++ programmers are just much easier to come by. Because something isn't popular, doesn't mean it's not useful.

    OTHOH it let a handful of people make a robust and stable product quickly. The Editor being LISP, the Manager being C and Perl. I had some involvment with Viaweb/Y! Store. On more than one occasion, if someone called in with a bug, pg would fix it while they were on hold.

    FP can be abused, it can also lend itself intuitively to solving certain problems. If your argument is that a language should idiot-proof code by constriction, Perl is probably not the best fit for ya.

    -Lee
    "To be civilized is to deny one's nature."
Re^6: RFC: Should join subsume reduce?
by Anonymous Monk on Feb 22, 2006 at 00:39 UTC
    One of my best friends is a LISP expert; though he and I disagree violently on the value of functional programming, he agreed in every single case when I asked him (and I asked often) that the functional code I was seeing was just plain bad, wrong, or occasionally, even "insane". Believe what you will of me or my abilities, but it's not just me. The FP devotees claim it's possible to write good FP code, but it's not what happens in the field, in my experience.
    About 90% of the Perl code I've ever seen makes me want to vomit. The fact Perl is relatively easy to learn might be one of Perl's biggest weaknesses, since it results in heaping piles stinking code written by people who can barely type, let alone know the first thing about programming. But that doesn't mean that Perl is worthless, does it?
Re^6: RFC: Should join subsume reduce?
by Anonymous Monk on Feb 22, 2006 at 00:55 UTC
    Ahem. One slight correction. Instead of the functional looking...
    sub average { my $average; $average = sum(@_)/ scalar(@_); return($average); }
    ...which is really just a verbose way of saying...
    sub average { sum(@_) / scalar(@_) }
    ...I'm sure you meant the much easier to understand alternative...
    sub average { my @arr = @_; my $average = 0; my $length = @arr; for(my $x=0; $x<$#arr; $x++) { $average = $average + $arr[$x]/$length; } return $average; }
Re^6: RFC: Should join subsume reduce?
by DrHyde (Prior) on Feb 22, 2006 at 11:00 UTC
    You know, ad hominem is bad argument...

    One of my best friends is a LISP expert

    Yeah, ad hominem is almost as bad as using unsubstantiable anecdotes.
      Yeah, ad hominem is almost as bad as using unsubstantiable anecdotes.

      1) No, ad hominem is just plain wrong; honest anecodotes offer evidence about at least one data point.

      2) Paul Graham's claims are no more substantiated than my own are. For all you know, I'm lying about my abilities, and my friend has never seen LISP. Then again, for all you know, Paul Graham was lying about the language he wrote his code in, and his software was really secretly written by trained hamsters jumping on keyboards to churn out INTERCAL code.