← Back to context

Comment by empthought

3 days ago

> for a web-focused scripting language it makes sense to default to mutable strings

Why do you say that? I would say the opposite.

Because there’ll likely be a lot of string concatenation in a language whose job is to output HTML. Adding a single char to a 1k string will require allocating a modified copy, in mutable strings it’s just appending in a preallocated buffer.

  • If you are using string concatenation to build HTML in your application layer, you are fundamentally doing it wrong.

    Ruby isn’t making all strings immutable here. Just string literals. You are free to allocate mutable strings that can be appended to, to your heart’s content. It is extremely rare that modifying a literal is intended behavior, since their contents are permanently persisted throughout the lifetime of your program. With your example, this would be like having one shared global buffer for your final document.