lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Tue, Jun 3, 2014 at 10:29 AM, Coroutines <> wrote:
> ...  Side note:
> Libraries usually provide a mechanism, not a policy.

When appropriate. For instance, I have tablex.find which does a linear
lookup on an 'array-like object' - assumes that #t and t[i] are
meaningful.  So it is fully generic and would work on userdata and
customized tables. Likewise, 'map-like' means that pairs() is defined
on that type.

For this case, the implementation is very bound up with plain Lua
strings and their properties (that's what the library does).  It's
tempting to make such code generic and handle any 'string-like' data
type, but in general it isn't possible to construct a user type which
can be used as a plug-in replacement for strings (the so-called
"virtualization" problem discussed on the wiki)  stringio is a
closed/final class. If it was meant to be extended, then it would
provide appropriate mechanism.

I still feel that monkey-patching is too crude a strategy to reliably
use in large code bases because it cannot be scoped.

(I did miss some opportunities for micro-optimization: e.g. using
str:find(...) where sfind(str,...) would be faster.)