krakjoe / ustring

UnicodeString for PHP7
Other
64 stars 7 forks source link

Immutability #7

Closed mnapoli closed 10 years ago

mnapoli commented 10 years ago

What do you think about making strings immutable? I.e. methods would always return the result without modifying the original object.

It would make much more sense IMO.

For example:

if ($str->toUpper() === 'HELLO') {
    // ...
}

Here $str would be modified, which is confusing.

mnapoli commented 10 years ago

(and the if wouldn't work because it returns void obviously)

pierrejoye commented 10 years ago

The main issue here is about performance. For many cases it could be too expensive to do it.

On the other hand, it would be nice to have these method be fluent. On Aug 18, 2014 3:04 PM, "Matthieu Napoli" notifications@github.com wrote:

(and the if wouldn't work because it returns void obviously)

— Reply to this email directly or view it on GitHub https://github.com/krakjoe/ustring/issues/7#issuecomment-52488758.

mnapoli commented 10 years ago

I see, it makes sense thanks for the answer.

krakjoe commented 10 years ago

We have it ...

pierrejoye commented 10 years ago

what do we have? Not sure to understand what you refer to here

On Mon, Aug 18, 2014 at 7:37 PM, Joe Watkins notifications@github.com wrote:

We have it ...

— Reply to this email directly or view it on GitHub https://github.com/krakjoe/ustring/issues/7#issuecomment-52526842.

Pierre

@pierrejoye | http://www.libgd.org

krakjoe commented 10 years ago

UString is immutable