lua-users home
lua-l archive

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


On Wed, Apr 16, 2014 at 4:10 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> On Wed, Apr 16, 2014 at 11:00 AM, Philipp Janda <siffiejoe@gmx.net> wrote:
>> What I wonder though: If people would have been aware of the problems of
>> using global shared objects from the beginning, would string method syntax
>> be as popular as it is now?
>
> Because most people think that random monkey-patching is dumb[1], and
> there's no defense against other people's decisions anyway in a
> dynamic language, unless one is sandboxing them severely ;)
>
> #3, "allow monkey-patching" - fine - usual method of defining modules
> does not interfere with this right.  But I won't go to too much
> trouble to bullet-proof against monkey-patching - all warranties
> invalid!  I'm a little perplexed that "allow monkey-patching" is
> elevated to a core consideration - it belongs in the "break the rules
> if needed" category.
>
> This all applies to regular application/scripting development, of
> course.  And I respect the need of people to code around an actual
> bug.
>
> [1] http://devblog.avdi.org/2008/02/23/why-monkeypatching-is-destroying-ruby/
>

I monkeypatch all of the time, but:

I create an environment using _ENV

I copy the library into a new table and make my additions and changes there.

I've yet to learn my lesson, as others have, so I don't advocate it. I
haven't seen any problems from it, however.


Aside from that, I wanted to add that the reason monkey patching is "a
thing", especially in the string library, is because Lua shares
elements of a typed language that, for example, Ruby doesn't. I simply
can't make a string-like table and expect it to work fine as a string,
everywhere it is passed. As far as I've seen, none of the math
library's methods work on tables, even when every one of arithmetic
and comparative metamethods are defined.

Basically, Lua can be agnostic about type, but in the standard
libraries and in the way that most people write their own libraries,
it is not. It also doesn't provide a way to spell out the intent of a
value. That is, "This here table is supposed to be a string."

There are good reasons why this is so and I love Lua the way it is. It
is the main reason why I patch most of the libraries that I use,
especially type.

-Andrew