Live data from Hacker News

The Power of Lua and Mixins

notmagi.me

1–10 of 25 posts

Re: The Power of Lua and Mixins

#4
I've bee studying Lua very thoroughly recently because I'm working on a toy language based on its runtime, so I gained a certain appreciation for some of the concepts Lua uses.

Given this background and my general coding experience up to now, I'm very skeptical about OO frameworks for Lua, because they mostly provide mechanisms that are neither true to the language's design nor are they really necessary. Specifically, mix-in patterns are extremely easy to implement just using core features already present.

Most languages work best if you don't try to forcefully adapt them to emulate another language. In my opinion, some of the worst features in both PHP and JavaScript come from a more or less hidden desire to mimic Java instead of being confident in the paradigms those languages already provide.

Lua already allows you to share code between "objects", and it allows you to do that with excellent granularity, simplicity, and a lot of control. There is no question that Lua is well-suited for modification and can be adapted for many things, but in this case I'm having trouble seeing the benefit (other than perhaps a programmer's familiarity with "standard" OO design which can be a considerable boon in the short term).

Re: The Power of Lua and Mixins

#6
post #4

I've bee studying Lua very thoroughly recently because I'm working on a toy language based on its runtime, so I gained a certain appreciation for some of the concepts Lua uses. Given this background and my general coding experience up to now, I'm very skeptical about OO frameworks for Lua, because they mostly provide mechanisms that are neither true to the language's design nor are they really necessary. Specifically…

Mixins are a useful mental model for some kinds of code reuse though.

(I don't like his class style either, the constructor should return self, and I just like prototypal inheritance anyway).

Re: The Power of Lua and Mixins

#7
post #4

I've bee studying Lua very thoroughly recently because I'm working on a toy language based on its runtime, so I gained a certain appreciation for some of the concepts Lua uses. Given this background and my general coding experience up to now, I'm very skeptical about OO frameworks for Lua, because they mostly provide mechanisms that are neither true to the language's design nor are they really necessary. Specifically…

Mixins are a useful mental model for some kinds of code reuse though. (I don't like his class style either, the constructor should return self, and I just like prototypal inheritance anyway).

> Mixins are a useful mental model for some kinds of code reuse though.

They are, but I can think of at least one core feature-based solution to do the same thing with less overhead. Each mix-in or trait could easily be in its own table, to be joined with the object as it's being constructed in whatever fashion desirable.

Re: The Power of Lua and Mixins

#8
It would be better if this article had been using real Lua code, and not starting with a "class" function. Lua does !NOT! have classes. Lua is a prototyping language, and anybody can handwave an own class system, or go without classes at all. The idea of mixins makes only sense in languages that have classes. Lua does not. References have a metatable, and this metatable contains functions. The functions are independent of the reference, and there are no classes. So basically all functions in a metatable are mixins by default.

Re: The Power of Lua and Mixins

#9

Animated pictures of a Jump'n'Run game make blog posts really hard to read. Might be related to the way human attention works, but well.

i thought they made the abstract nature of a construct like mixins into something far more concrete.

It does but it's unrelated, I think @sieisteinmodel meant it was far too distracting.

Re: The Power of Lua and Mixins

#10
Wait. Just having a glance at the website, and I see these animations - do they have anything to do with the code? It doesn't quite clearly state that and I'm kind of put off reading the code. :-/ Sorry if I've missed something.
Post reply on HN