3 ms·
> for a web-focused scripting language it makes sense to default to mutable strings Why do you say that? I would say the opposite.
by empthought 1y 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.
- superjan 1y agoBecause 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.
- stouset 1y agoIf 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.