[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Pooling of strings is good
- From: Coroutines <coroutines@...>
- Date: Fri, 22 Aug 2014 04:58:56 -0700
On Fri, Aug 22, 2014 at 4:41 AM, Axel Kittenberger <axkibe@gmail.com> wrote:
> Strings are a native thing, since there are string literals in source code.
> I don't think anyone wants to string literals to go. That what makes them
> different to generic UserData. There is more to it due to automatic
> coercions and the '..' operator, but thats another story.
>
> Mutables are bad. More mutables are worse. If I'd see a language develop, it
> be more in the directions of immutables in the direction of deeply frozen
> tables. Albeit it may seem counterintuitive at first, so many problems and
> issues go away if one would use immutables. For example the whole
> computation times of the # operator, vs. ipairs would go away in a poof.
In my opinion, I feel like people talk about mutable types like they
talk about use of 'goto'. A lot of people advise you to never look in
that direction, and a few instruct you on the appropriate places they
can exist. Honestly I'd be happy to continue letting strings be
default: immutable & pooled
I'd be happier being able to coerce userdata to string without having
to touch C, or treat userdata as a mutable string where no hash is
computed (a transparent memcmp() in string-userdata comparisons --
most of the string library functions don't need to know the hash of
the string anyway, they deal directly with memory). Again, I say that
mutable strings have their place -- it can be contentious and wasteful
to realloc() and as I said before, there are many places where a
mutable buffer type would be welcome in the network stuff I do. I
just hate that I have to promote these to full-blown strings to use
the string library functions on them or pass them to other libraries
that don't like userdata. For me, there is a need.
immutable types have only become popular because of how cheap memory
is in computers these days and it's easy to orient a program for
sharing data between processes, threads, and through IPC if it is
immutable. Did we forget that Lua is embedded and caters to embedded
devices? I see a lot of people reinvent buffer types that could be
userdata and/or lua_Buffer's. I think of userdata like a black box,
and I wish it were easier to pass around and look inside. Part of
that is the appeal -- what you can't see is good encapsulation.