[ruby-talk:02557] Re: frozen behavior

From: Andrew Hunt <andy@...>
Date: 2000-04-21 15:22:09 UTC
List: ruby-talk #2557
    mengx@nielsenmedia.com writes:

    >I feel making string frozen by default
    >not only saves a lot of typing, but also make programs a lot safer.
    >Perhaps it is time to write Ruby4000 to make a perfect language:-)

I don't necessarily see the argument for safety.  Java Strings
are immutable, and that basically boils down to huge pain (or
severe runtime penalty) having to conert them to StringBuffers.

If you need immutable string literals, why not simply create
a method that freezes the string and use that?

def f(a)
    result = a.dup
    result.freeze
    result
end

to use it, just:

newstring = f "I am frozen"

Surely typing one extra character :-) isn't so bad?
You still have to remember to freeze the strings you want frozen,
but I don't think that's fatal.

/\ndy

In This Thread

Prev Next