Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm also not sure I understand the motive for optimization at this point (2,3)-- it seems premature... but I will defer to your experience.

Thank-you. ;-)

The point is not to actually insist on optimisation at present (though part of our motivation in cleaning up the Perl syntax is to make more optimizations possible). The point is to avoid making changes now that make later optimisations impossible. Which is what unifying arrays and hashes would do.

I am certain I haven't had any problems keeping my Ruby hashes and arrays separate (4)

I'm sure. But we don't just design for programmers as clueful and competent as you. We have to consider the common mistakes made by the vast majority of Perl programmers -- whose level of experience and ability is quite low. And then consider how the changes we propose will affect them.

In my (considerable) experience with such programmers, one of their most frequent difficulties is distinguishing between container types. I've published research1 that indicates that removing syntactic cues to the differences between data types (as the Turing language did, for example) makes that problem far worse.

As to 5, I think I'll wait for Ex5, since I've not yet internalized A5, but I don't see how the brackets/brace is a problem if you are assigning a series of key/values to a hash

It isn't. In that particular case.

But that's not what I was talking about. I was talking about the case where a regex returns a "match object" (either directly, or via $0):

$match = m/complex pattern/; # match object in $match m/complex pattern>; # match object in $0

Now array accesses on (say) $match give you the numbered captures:

print "$match[1] was val for $match[0]\n"; my ($key,$val) = (0,1); print "$match[$val] was val for $match[$key]\n";

Whereas hash accesses on it give you the named captures:

print "$match{val} was val for $match{key}\n"; my ($key,$val) = ("key", "val"); print "$match{$val} was val for $match{$key}\n";

But if there's no syntactic distinction between arrays and hashes (represented here by a hypothetical, unified $match<...> accessor), how do you distinguish between hash-like and array-like look-ups on non-literal keys:

print "$match<0> was val for $match<1>\n"; # array look-u +p print "$match<'val'> was val for $match<'key'>\n"; # hash look-up print "$match<$val> was val for $match<$key>\n"; # ???

Deciding that last case on the basis of run-time type of the values in $val and $key is both much slower, and vastly more error prone (in light of Perl's free-and-easy interconversion of numbers and strings).

So people will be generally forced to make the distinction explicit anyway:

print "$match<$val> was val for $match<$key>\n"; # ??? print "$match<+$val> was val for $match<+$key>\n"; # array look-u +p print "$match<_$val> was val for $match<_$key>\n"; # hash look-up

Which is far worse than what we have now.


  1. They didn't select me to help Larry design Perl 6 just because I'm even weirder than he is, you know! Well, not solely on that basis, at least. ;-)

In reply to Re: (ichi) Re x 4: Apocalypse 5 and regexes by TheDamian
in thread Apocalypse 5 and regexes by c-era

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 sharing their wisdom with the Monastery: (4)
As of 2024-04-16 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found