Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

My Perl code can be understood by...

by TimButterfield (Monk)
on Feb 21, 2008 at 02:33 UTC ( [id://669173]=poll: print w/replies, xml ) Need Help??

Vote on this poll

very small children
[bar] 53/7%
a Perl novice
[bar] 57/8%
someone comfortable with Perl
[bar] 237/33%
an experienced Perl programmer
[bar] 98/14%
an expert Perl programmer
[bar] 14/2%
a Perl guru
[bar] 6/1%
not even by me 6 months later
[bar] 76/11%
not even by me the next day
[bar] 31/4%
not even by me while I write it
[bar] 138/19%
710 total votes
Replies are listed 'Best First'.
Re: My Perl code can be understood by...
by evaluator (Monk) on Feb 21, 2008 at 09:18 UTC
    not even by the Perl interpreter (while I write it)
      You write the Perl interpeter?
        I wish I had it bookmarked, but one of my favourite threads here went something like this (from memory):

        Monk1: And here's my awesome answer
        Monk2: That doesn't work.
        Monk1: It should work.
        Monk2: No it doesn't. Here's the proof (inserts code)
        Monk1: Patched Perl. Now it works.

        Hard to argue with someone who has a commit bit.

        ___________________
        Jeremy
        Insight is found at the bottom of the cup.

Re: My Perl code can be understood by...
by grinder (Bishop) on Feb 21, 2008 at 09:31 UTC

    ... the people who file bug reports on the RT queues of my modules. Many times the person goes to the trouble of:

    • identifying the offending line,
    • writing a patch to fix it,
    • and adding a test case to exercise the bug.

    So some people understand my code...

    • another intruder with the mooring in the heart of the Perl

      Ideally the order would be:
      1. identifying the offending line
      2. adding a test case to exercise the bug
      3. and writing a patch to fix it

      --
      Rohan
Re: My Perl code can be understood by...
by TimButterfield (Monk) on Feb 21, 2008 at 20:07 UTC
    This poll was triggered by the frequently heard comments of non-Perl developers that follow along the lines of Perl code being obfuscated by definition. For mostly evangelical reasons, I try to make my Perl code understandable by the novice. Where ever I happen to be working, sooner or later, I start writing Perl code to assist with other development work. For example, even though I was brought on where I am now to do C++ work, the first code written was some Perl scripts/modules to parse and analyze the data in some 55,000 log files to verify if proposed changes would actually help the customer. As is typically the case, no one else in my group knows Perl. By writing well commented Perl that minimizes code combinations, eliminates implied variable names, and uses named variables as much as possible, I hope that those who look at the code will not be scared off, but realize that Perl code can be written, which can be understood by those not well versed in the language. While writing code this way may not be the most efficient in terms of processing, I feel CPUs are fast enough that the evangelical benefits outweigh the loss in processing efficiency. As an added benefit, this practice helps reduce the applicability of the last three poll items.
Re: My Perl code can be understood by...
by wolfger (Deacon) on Feb 21, 2008 at 12:48 UTC
Re: My Perl code can be understood by...
by Joost (Canon) on Feb 21, 2008 at 20:40 UTC
    I posted "an experienced perl programmer", but I know there are cases where a lot of experienced perl programmers would probably do a double take. I try to code mainly for clarity, but that does not mean I stay away from "complex" techniques just because someone reading it might not know the ins and outs.

    I definitely don't hesitate to use closures generating closures that get combined into another closure (for instance) if that's the "best" way to solve the problem. I would hate to solve that kind of problem using only "easy to understand" primitives.

    What I mean to say is: some times, problems can only be easily solved (and understood) using relatively "obscure" techniques. If understanding the resulting code relies on the viewer knowing the technique, then that's probably still better than using "simple" techniques in a convoluted way which no-one will be able to understand.

      I guess a factor in determining intended complexity may be the intended audience. For me, that audience is the non-Perl programmers who will inherit the code when my contract is over. Even though most of what I write is only for my use (that's how I sell it), I leave the code behind when I leave the contract, but with the hopes that someone else will look at it and try to use it. I want to make that use as easy as possible for them. If I were writing a module for CPAN with the intended audience being other Perl developers, the intended complexity level could safely jump way up.
        I guess a factor in determining intended complexity may be the intended audience.
        True.

        I write most of my perl code these days for a client that wants me get the *hard* things done, and has the expertise to make sense of the code - at least, once I explain some things :) Most of my CPAN code is probably more straight-forward, just because the problems solved there are easier.

        On the other hand, if I had to do the kind of stuff I'm getting paid for right now, and also had to cater to not very experienced perl programmers, I would estimate the most efficient use of our time would be for someone (or even me) to give them a really intensive course in advanced perl programming for a month or two.

        IOW: it's not just the target audience, the problem domain is also important. Some things just can't be solved correctly or "maintainably" with only minimal skills. In those cases, it's better to try to raise the skill level (in whatever way suits the business).

      I think it is ok to use complex perl if you leave a simple comment over it that explains it. Or you could do something I saw in production code for a Fortune 500 company.
      # DO NOT EDIT THE NEXT LINE... IT WORKS AND THAT IS ALL YOU NEED TO KNOW

      -- rogueFalcon
      Why do you people insist on doing things sdrawkcab?

        Exactly. If I have a really efficient/ugly/erudite line or two of code, I comment above it that

        ## This is where the magic happens ##

        So that (a) I can find it later, and (b) J. Random Neophyte (see gloryhack's post, below) might not screw with that line after turning off the strict pragma.

      Agreed. Adding my take to the "intended audience discussion", I expect that my co-workers have a solid grasp of Perl, so I don't shy away from using somewhat more complex Perl idioms.

      Published papers in mathematics don't explain the summation symbol every time it comes up. If you have a degree in mathematics, you're just expected to understand it already. Likewise, there's no reason to limit yourself to a pidgin dialect of Perl (or any other language) if you're hiring good people.


      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re: My Perl code can be understood by...
by BrowserUk (Patriarch) on Feb 21, 2008 at 02:46 UTC
Re: My Perl code can be understood... (author)
by tye (Sage) on Feb 21, 2008 at 02:39 UTC

    Much thanks to TimButterfield for the poll suggestion. I hope he doesn't mind that I made some changes but still assigned him as author of the poll.

    - tye        

      I don't mind at all. The more, the merrier. I'm just surprised my first poll submission was so quickly used. Thanks.
        First, it's a good poll. And second, polls have been few and far apart lately.
      Hey it was hard to write, it should hard to read ... right? ;-)
      Cowboy Neal!!!!!!!
Re: My Perl code can be understood by...
by apl (Monsignor) on Feb 21, 2008 at 12:47 UTC
    If I was one of the mad geniuses who can write Obfuscated Code, I'd be tempted to say "Understand? Why would I want someone to be able to understand it?"
Re: My Perl code can be understood by...
by Juerd (Abbot) on Feb 25, 2008 at 15:27 UTC

    It all depends on the kind of code, and the intended audience. For CPAN modules, I try to optimize for performance if it doesn't hurt readability too much. This code can be understood by experienced Perl programmers.

    For one-off quick hacks and oneliners, I don't care about readability and will use any technique that saves me from having to write much more code. This code can often be understood by people who are experienced in Perl. I will use ~~ instead of scalar.

    For example code in documentation, I try to optimize for readability. However, I will continue to assume that the reader is at least comfortable with Perl. That means that I still do use statement modifiers and the $_ variable.

    The Perl novice will have to find a way to plough through the first part of learning Perl: dealing with its sometimes exotic syntax. In some ways that is a barrier of entry, and keeps dumb and uninterested people away. It's not hard to learn how Perl works, there's lot of documentation to explain it. If you're learning Perl, you're only a real novice for a few days anyway.

    I suggest that people who are not comfortable with Perl, should not be using it.

    Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }

      ++ ** 10E6!

      I spent years dumbing down my code so J. Random Neophyte could read it, understand it, and make changes. I found out the hard way that JR is an untrustworthy witless dolt who should never be allowed to use a computer. He turns off the strict pragma because it does nothing except stop perfectly valid code from executing, and thinks that testing is a crutch used by incompetent programmers who don't know what to expect from their own code. I don't want JR to feel comfortable "fixing" my "executable line noise". I want JR to go back to flipping hamburgers where he belongs. And to receive at least two painful burns each week. On his face.

      The greatest threat to continued habitability of the planet is people who are convinced of their knowledge of things they've never actually learned.

        Now I have to go and find the 20 things most likely overheard from a Klingon programmer ... Sheesh! http://gradha.sdf-eu.org/textos/klingon_programmer.en.html
Re: My Perl code can be understood by...
by Discipulus (Canon) on Feb 21, 2008 at 08:36 UTC
    Nostradamus and Merlyn the mage !
Re: My Perl code can be understood by...
by dsheroh (Monsignor) on Feb 21, 2008 at 22:19 UTC
    Most of my code can be read by someone comfortable with Perl.

    But then there are the odd bits that I come back to a year or two later and can't decide whether to be ashamed that I wrote it or proud that I can still understand it...

Re: My Perl code can be understood by...
by Moriarty (Abbot) on Feb 22, 2008 at 11:08 UTC

    I really hope that my Perl code can be understood by a novice, as that's the only way I'll be able to understand it next time I look at it.

Re: My Perl code can be understood by...
by zentara (Archbishop) on Feb 21, 2008 at 15:31 UTC
My Perl code can be understood by...
by punch_card_don (Curate) on Feb 21, 2008 at 20:20 UTC
    My Perl code can be understood by...

    ...taking the time to read it.




    Forget that fear of gravity,
    Get a little savagery in your life.

      Unless...

          Infinity is insufficient.

      Just asking here. :)

Re: My Perl code can be understood by...
by swampyankee (Parson) on Feb 25, 2008 at 15:08 UTC

    All my Perl code can be understood by the Perl compiler. Since the average computer has considerably less processing power than almost any tetrapod, my dog should be able to read and understand it. He can't, and I would be challenged six months later if it weren't for my habit of including a reasonable number of not too cryptic comments.


    emc

    Information about American English usage here and here.

    Floating point issues? Read this before posting: What Every Computer Scientist Should Know about...

      Get a Border Collie, they can be trained to do anything.

      Me to dog: What do you think of my Perl?
      Dog to me: Rough

        I've heard of border collies herding wild rabbits, and trying to herd squirrels, so I've no doubt that they could be trained to manage programmers (which has been likened to herding cats).

        My dog is a bichon frise, who is cute and adorable (alas, that's a stock photo) but not the sharpest knife in the doggy drawer.


        emc

        Information about American English usage here and here.

        Floating point issues? Read this before posting: http://docs.sun.com/source/806-3568/ncg_goldberg.html

Re: My Perl code can be understood by...
by toolic (Bishop) on Feb 21, 2008 at 16:39 UTC
    ... an interviewee when I present a simple quiz :)
Re: My Perl code can be understood by...
by cdarke (Prior) on Feb 22, 2008 at 15:29 UTC
    My Perl code can be understood by...

    ...just reading the comments (or course).
Re: My Perl code can be understood by...
by papidave (Pilgrim) on Feb 22, 2008 at 18:22 UTC
    1. ... my team. If they can't read it, I can't delegate it to them next time.
    2. ... small children (mine), who are smarter than me (just ask them).
    3. ... qx/perldoc $0/
Re: My Perl code can be understood by...
by chatur (Acolyte) on Feb 21, 2008 at 13:47 UTC
    It must be simple enough that can be understood not only someone comfortable with Perl but with other programming language and novice
Re: My Perl code can be understood by...
by peterdragon (Beadle) on Feb 28, 2008 at 10:51 UTC
Re: My Perl code can be understood by...
by Aim9b (Monk) on Feb 22, 2008 at 21:34 UTC
    My Perl code is understandable by...and large. Doesn't mean is correct, just understandable.
Re: My Perl code can be understood by...
by wjw (Priest) on Feb 23, 2008 at 01:59 UTC
    I would guess my code is fairly understandable. What would confuse most people is what I apply it to. Not that what I apply it to is that hard. :-)
    • ...the majority is always wrong, and always the last to know about it...
    • The Spice must flow...
    • ..by my will, and by will alone.. I set my mind in motion
Re: My Perl code can be understood by...
by Nkuvu (Priest) on Feb 25, 2008 at 18:34 UTC

    someone comfortable with Perl

    Typically my Perl scripts are quite simple. I don't write scripts with packages, or object orientation, or things like map or grep, primarily because the scripts I write don't need any of that.

    Some of the scripts I have written are currently being maintained by non-Perl programmers, so in those cases the scripts are even more simple. In those cases, any programmer should be able to read and modify the scripts for the given task.

Re: My Perl code can be understood by...
by stonecolddevin (Parson) on Feb 26, 2008 at 21:37 UTC

    Anyone comfortable with perl can understand my code. I'd like to spend more time making it pretty though and optimizing it, in the sense that I could actually make it more simple, like, "ohhh...that makes sense, wow that's nice AND simple."

    Obviously that can't ALWAYS be achieved, but where possible, I'd like to do it more often.

    meh.
Re: My Perl code can be understood by...
by shoprat (Monk) on Feb 27, 2008 at 23:34 UTC
    Only one Perl novice - me.
Re: My Perl code can be understood by...
by drip (Beadle) on Feb 28, 2008 at 08:08 UTC
    even perl cant understand my code(since i am noob)...haha.it gives off a lot of errors..lol...
Re: My Perl code can be understood by...
by starX (Chaplain) on Mar 05, 2008 at 20:20 UTC
    Actually had a great object lesson in figuring out where my code could be better. My development machine went belly up on me a week ago, and because my office has been pretty ravaged by the flu, it took about a week to get a new one up and running.

    Coming back to it afterward, there were quite a few places where I found I had to work through some code in my head. Needless to say, I've been spending some time getting those nasty patches in better shape.

Re: My Perl code can be understood by...
by marcussen (Pilgrim) on Feb 22, 2008 at 02:41 UTC
    Perlcritic / Conway ++

    while ( whoring ){ for ( xp ){ grep /the source/,@perlmonks; }}
Re: My Perl code can be understood by...
by Anonymous Monk on Feb 21, 2008 at 05:21 UTC
    Cowboy Neal!!!!!!!

View List Of Past Polls


Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-19 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found