lua-users home
lua-l archive

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


It was thus said that the Great Andrew Starks once stated:
> On Thu, Dec 24, 2020 at 10:55 AM Spar <developspartv@gmail.com> wrote:
> 
> > I used *__type *with overridden *type *function for my scripts
> 
> I've used similar magic and as has been pointed out, this has been done by
> many libraries.
> 
> To me, the border between "a good idea" and "a good idea for your code, but
> not for the language" is:
> 
> What's required for interoperability? In this case, is the situation
> improved for the user if the language offers this mechanism for subtyping
> tables?

  I don't quite understand the rational for this.  But then again, I'm a fan
of offensive programming [1] and would prefer for the program to "crash
fast, crash hard" to root out bugs.

  For a project, I had need to emulate Lua's file object.  So I have this
table that has a read, write, close, seek, setvbuf, flush and seek
functions.  Any code that explicitly checks for a type of 'userdata' or an
io.type of "file" will fail, yet if such checks are removed, it should run
fine.

  -spc

[1]	https://interrupt.memfault.com/blog/defensive-and-offensive-programming

	This article describes my position.