Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: Shouldn't references be readonly? (updated)

by ikegami (Pope)
on Aug 07, 2020 at 01:19 UTC ( #11120443=note: print w/replies, xml ) Need Help??


in reply to Re^3: Shouldn't references be readonly? (updated)
in thread Shouldn't LITERAL references be readonly? (updated)

Ok, I'd like to contradict myself.

I'd actually be ok with making "unassigned" scalars read-only. That includes [...], $x.$y, <>, etc.

It might have performance implications, but they should be extremely tiny.

It would break some code (such as my @lines = map { chomp; } <>;), but I think the benefits might be larger.

Replies are listed 'Best First'.
Re^5: Shouldn't references be readonly? (updated)
by LanX (Cardinal) on Aug 07, 2020 at 10:34 UTC
    > It would break some code

    I think if it comes to simple scalar types like strings this would result in a migration nightmare.

    Hence I wouldn't include the cases like $x.$y, <>, etc at least by default.

    Refs on the other hand should be immutable, because the result is always junk.

    But I doubt we have the resources to implement that anyway.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      @a = map { $_ = 3; } [];

      is no more or less junk than

      @a = map { $_ = 3; } $x.$y;

      Are you therefore talking about [] + 1? Making the reference read-only is not going to catch that.

        There are far more situations where it might make sense to append or add something to a simple type.

        Not so with refs, no way a .= or a += will lead to anything meaningful.

        Well except when blessed and overloaded. But that's far fetched.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2020-12-03 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (49 votes). Check out past polls.

    Notices?