Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Slice Madness

by Anonymous Monk
on Nov 09, 2005 at 18:39 UTC ( [id://507166]=note: print w/replies, xml ) Need Help??


in reply to Slice Madness

*sigh*

Why do we have to have nasty things like this in our language? :-(

From perlop: Binary ".." is the range operator, which is really two different operators depending on the context. (emphasis mine)

I always felt this was a point of needless confusion in perl. If the operator is really two operators, why not create two operators? Just make a range operator (array context only), and a flip flop operator (scalar context only), and report an error if the wrong one is used in the wrong context? That would eliminate this kind of error altogether, and make life easier to all concerned.

Wouldn't that have been wiser? Is it too late to fix it? Will Perl6 have the same mistake?

Me, I don't like the flip-flop operator; I didn't understand it when I first ran across it, and now that I do, I still prefer to write my conditionals more verbosely. But I'd put up with it to appease the sed people (if the are any left), and create a range operator (or function), rather than deal with this kind of ugliness for newcomers (or for me when I'm sick, overtired, or called into work in the middle of the night).

Even a function called "range" that returned a list from the first argument to the last argument would probably do.

Given that I can write this:

@range = $x .. $y; @slice = @x[ @range ];
it shouldn't be that much more confusing to write this:
@range = range($x,$y); @slice = @x[ @range ];
and leave the .. for the flip flop.

Just a thought... --
Ytrew

Replies are listed 'Best First'.
Re^2: Slice Madness
by TimToady (Parson) on Nov 09, 2005 at 19:33 UTC
    Yes, it's fixed in Perl 6. In fact, it's already fixed in Pugs:

        pugs> say ~(1..10)
        1 2 3 4 5 6 7 8 9 10

    But your solution is bad Huffman coding. Range objects are much more useful than flipflops, and therefore should get the .. operator.
      Yes, it's fixed in Perl 6. In fact, it's already fixed in Pugs:

      Yay! Three cheers for fixing stuff! :-)

      But your solution is bad Huffman coding. Range objects are much more useful than flipflops, and therefore should get the .. operator.

      Either way works for me; I was trying to be charitable to the opposing position. :-) I'll always prefer the solution that lets me keep my favourite syntax (i.e. the range operator), but I didn't know if there were a ton of hidden ex-sed and awk lurkers out there ready to gripe at me if I suggested the range operator be used instead. :-)
      --
      Ytrew

Re^2: Slice Madness
by Roy Johnson (Monsignor) on Nov 09, 2005 at 23:02 UTC
    Perl got where it is via evolution*. Evolution begets cruft. It strikes me as particularly ivory-tower-minded of people to wring their hands over these little throwbacks, particularly considering that Perl was never intended to be elegant. I trust you know where to find Ruby.

    It's not like this thing is something that's constantly tripping people up and making Perl painful to use. It's more of a wart that adds some amusing character. Yes, it's a flaw. What is there to do about it? Break backward-compatibility? That would be a worse flaw. And that's why evolution begets cruft.

    *You were thinking maybe intelligent design?


    Caution: Contents may have been coded under pressure.
      You were thinking maybe intelligent design?

      Yup! Larry certainly designed most of Perl intelligently enough. In some ways, it makes the areas where he didn't more jarring, because they're unexpected, and thus confusing. And by the way, thanks, Larry! :-)

      It's a small nit, but the nits add up. The more of them we can clean up, the better.

      Yes, it's a flaw. What is there to do about it? Break backward-compatibility? That would be a worse flaw.

      Yup. It doesn't have to be a flaw: we can deprecate the feature, like we've done in the past.

      Just add a warning like: "$x .. $y better written as flip_flop($x,$y)" for flip flops. Put in an explanation that flip flops must be written explictly so that they're not confused with the range operator, and in a few years, we could remove the feature entirely.

      Remember, effort at development time is easy. Until the program is put in production, it can be changed without impacting end users. Effort at mainenance time is hard; any change to the program will have to be analysed for it's impact on the end users. Fixing bugs is easy; finding bugs is hard. Giving the users one less bug is worth it, IMHO.

      --
      Ytrew

        The thing is, it's not a bug. It's just a quirk. Something that could have been more beautiful if they'd thought of that. Like using ' instead of :: for package specs, and -> instead of . for dereferencing. Neither of which has gone away.

        BTW, I like the flip-flop operator, and I don't think a spelled-out function version is an improvement.


        Caution: Contents may have been coded under pressure.

      Ruby is much perfect as we Japaness are made for perfection. We are made to lead the world to its perfection even it means pain to our own nation and people.

        頑張って,よ!でも,日本語を習う場会はもう痛く過ぎます,ね。:-)
        And on behalf of the rest of the world, I thank you. The perfection of the Japaness[sic] is a source of great delight.

        Caution: Contents may have been coded under pressure.
Re^2: Slice Madness
by dragonchild (Archbishop) on Nov 09, 2005 at 18:50 UTC
    I just had this exact same thought in Ruby terms today. The idea of the flip-flop operator is ... well ... dumb. It's syntactic sugar that's overloading a rather useful operator (the range) and should be banned. IMNSHO, of course.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-25 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found