Hacker News new | ask | show | jobs
by samatman 1534 days ago
That's one way of stating the problem, sure.

It's more accurate to say that Ruby has mutable strings as part of its semantics, and that can't be changed, and would interact disastrously with immutability.

Languages with immutable strings simply architect a web server around that semantic, the problem you're describing doesn't happen. A mutable string is replaced with (in Lua) a mutable array containing immutable string fragments, which are made into a string using the builtin table.concat.

1 comments

> A mutable string is replaced with (in Lua) a mutable array containing immutable string fragments, which are made into a string using the builtin table.concat.

That's what TruffleRuby does internally! We give you 'mutable' Ruby strings, but really they're made up of fragments of immutable strings.

So it.. isn't catastrophic for performance?

Edit: I'm guessing you're saying they're immutable but not necessarily interned. Ok.

Yeah - if all strings are interned that's ok for comparison, but atrocious for string allocation. If not all strings are interned that's better for allocation, but atrocious for string comparison.

We already have the best solution... symbols. An alternative set of semantics that work well with our hardware.