Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Note that the first word in the title is apparent, meaning that the rest of the title is thing as they appear to me, not necessarily the way they are.

Ok, let's do this storybook style. I'm sitting in my office and my boss says "how do you find out the length of an array in Perl?" So I tell him

1+$#array #or scalar @array

A week later I'm reading comp.lang.perl.misc and Uri Guttman says to someone asking a similar question about strings: To take the length of a string, you use length. Larry did a good job of naming the Perl functions.

So then I, the nobody, have the nerve to email Uri Guttman, one of the Perl 5 Porters and lead author on one of the best Perl papers ever (on sorting) and tell him he isn't right about Larry naming the functions... Larry didn't do so great a job... why? Take a look:

<
Desired operation Perl datatype Perl function
lengthstringlength
lengtharrayscalar
lengthlist?
lengthhashscalar keys

In other words, the desired operation is the same in each case, but the way it is done in Perl is not... while one may say: "RTFM", one thing that reduces the learning curve for a language is for it to be intuitive. That's why I'm in awe when I hear people (even Damian Conway) say: "my brain thinks like Perl"... I have to stop,drop my jaw and say: "why in the world would you want different names for the exact same conceptual operation and what is it about your brain that seeks diversity in the function names for the exact same thing?

Example 2

Operation: Taking a "slice" of something in Perl

A string substr $STRING, $OFFSET, $LENGTH
An array @array[$OFFSET..$LENGTH+OFFSET]

Again while a logical person would say "how do I take subseries of something, regardless of whether it is a string or an array", we have the questionable brilliance involved in creating two radically different syntactic mechanisms for doing so.

And again, one must think seriously about offering a CAT scan to anyone who proclaims that such unwarranted non-homogeneity is "how their brain thinks".

Conclusion

Perl makes simple things simple, and hard things possible, but also makes consistent operations possible through highly inconsistent means.

And of course we cant forget the recent interview on Perl.COM with Ilya Zakharavich handled by BigJoe about how FILEhandle information is inconsistently handled by Perl.


In reply to Apparent Inconsistencies in Perl Function Naming by princepawn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
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 surveying the Monastery: (5)
As of 2024-04-20 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found