Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: pissed off about functional programming

by cog (Parson)
on Apr 24, 2005 at 12:52 UTC ( #450935=note: print w/replies, xml ) Need Help??

in reply to pissed off about functional programming

a young programmer who recently discovered functional programming, and thinks it can solve every problem in the world

Back where I studied, the first language of the course is now Haskell. As a result, most students get to think that that is the only way of coding, and keep on doing it that way.

I remember the teacher who taught me Perl complaining to other student: "You're coding in Perl as if it were Haskell!!!"

Which is kind of like what C-programmers do when they start programming Perl, but with a different language.

Hum... I wonder if it also happens with other languages? :-)

  • Comment on Re: pissed off about functional programming

Replies are listed 'Best First'.
Re^2: pissed off about functional programming
by merlyn (Sage) on Apr 24, 2005 at 13:18 UTC
    It obviously happens with human languages!

    And because we call that "speaking with an accent", I use that same term with some Perl coders. "You're speaking Perl with a C accent." "I'm coding Perl with a LISP." (The word "accent" there is optional.)

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      In your opinion, is there a "Perl accent" that one might write other languages using?

      Caution: Contents may have been coded under pressure.
        Only if those languages have the facilities Perl provides. I once tried writing some C with a Perl accent and it was ... ugly. The first thing I tried to do was abstract away my memory management. (Reading the Perl source helped here, but doubly-indirected variables scare me on so many levels.) The second thing was to redesign, given I didn't have hashes. (I was using ANSI C.) At that point, I kinda gave up, rewrote the damn thing in Perl in about 20min, verified that it still ran in under 2 milliseconds, and walked away.

        I'd have to say yes. D has hashes, which is great, but the first thing I wanted when I started coding in D was a generalised structure for holding configuration and command line parameters. Something akin to Perl's A hash is the perfect structure for this, but hashes in D have typed values. They can be anything, but each hash can only contain values of the specified type. That is dashed inconvenient when one is used to having polymorphic hashes.

        So about the first thing I did was to define polymorphic hash class that used void* to bypass the type checking:

        typedef void*[ char[] ] Config;

        Of course, the D guru's would view this as "typical of someone coming from 'scripting' languages", and could be viewed as writing D with a Perlish accent.

        One day I'll get around to re-writing it using templates and mixins to do away with all the explicit casting, but for now, almost every non-trivial D program I write uses that first attempt to handle command line arguments and configuration. I did add persistance to the class so that I avoid having to specify every parameter every time--it just remembers the values from last time I specified it.

        That also allows a degree of self-configuration. Each run of a program can remember things like the number of instances of a particular class that it used this time and average that with the number record in it's configuration. Then the next time the program runs, it can pre-allocate space for this number of instances when the class initialises which avoids a bit of thrashing and GC runs for highly dynamic classes.

        Using Perl for an extended period of time has certainly affected the way I code in a whole range of ways. For a while now I have been looking around at the features and facilities of several other languages and comparing both the features and implementations. Even when other languages have equal or greater feature sets, Perl always comes out on top for ease of use and the way it manages to blend those features together into the langauge. Perl 5 has lots of weird nooks and crannies and inconsistencies, but it still manages to blend it's features better than most other languages I've looked at.

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco.
        Rule 1 has a caveat! -- Who broke the cabal?
      I used to speak perl with a very C accent. But lately (many years down the road), my perl is becoming much purer, and full of more native perl idioms, while my C still looks like C. I think this is a sign that I'm beginning to be a nearly-native speaker, as opposed to some guy who took a berlitz course just before a trip overseas.
Re^2: pissed off about functional programming
by spurperl (Priest) on Apr 24, 2005 at 13:51 UTC
    Writing in language A with an accent of language B is a curious phenomenon (to detect and to analyze). I pondered it a while ago - "Native Perlish", an interesting thread evolved.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://450935]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2019-10-23 13:22 GMT
Find Nodes?
    Voting Booth?