lua-users home
lua-l archive

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


KR schrieb:
Mike Pall <mikelu-1104 <at> mike.de> writes:

  
<rant>
However I strongly suggest to resist the initial impulse to build
up a complex class system for Lua. Inheritance is overrated, anyway.

It seems to be a common reflex of programmers coming from other
languages to build up their dream of a class system for Lua as
their first task. Learning how to actually write good code in Lua
is skipped of course, because the language looks so easy, right?

Many months later, they still have no application to speak of, but
an overly complex, slow and entirely useless framework that's
quickly abandoned right after blogging how horrible their whole
Lua experience was. 
</rant>

--Mike
    
I am coming from a C++ backgound and I am very intersted in learning how to
write good code in Lua.

...

  

I welcome any suggestion on this point!
  
1 Looking at any FP language.

For the fun of it and for getting an idea what direction Lua opens up. I.e. the power of first order functions, less state*, generic code by default (i.e. non typed, always a template already). Coming from C++ you'll see some of the safety but also lots of clutter from the hard types flying off. That to my experience, needs a little stretching to allow oneself to put the liberty to task. But Lua absolutely deserves to try to free your mind from what you know, with an effort, which is harder because it looks so similar.

Mike disses OO in passing on his way to bigger game, but I can only attest to a surprisingly irrational resistance in the OO camp, basically the accepted mainstream currently, to anticpate even the possibility of anything after OO. Which of course is about to happen and it's FP.**

But for the rest, I think it's only objectionable to write huge, clumsy, unusably complex stuff as a first task in a new language if you actually end up blaming the language for your failures. And then you're good riddance to the community in the first place. But without the blaming, isn't that human nature?

Since you have to get the vocabulary down first, why not using your fresh impulses and have fun trying to recreate what you know. Sometimes there is no better way to realize what offends the nature of a language than running into the sheer impossibility to write elegant code for the approach you chose in it. As a guide, if it looks ugly, you 're probably using the wrong mind set. Rewrite it over until you got it right for the new language and you learned a lot.

Since you run up against something you by definition don't know yet - a new way of thinking - in my experience that really helps a lot to learn seeing it.

2 Look into the source.

Lua is so small, it's a bliss to scoure through, if you're coming from C/++ it's a breeze and fun, since the elegance of the language proper is of course reflected in the concise implementation. Maybe you can find a better table implementation.


Henning

* this is so central, you'll overlook it 1000x times.
** the truth tm, of course
*** there was something else I wanted to disclaim. Mh. Forgot.