[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Questions about writing a C library
- From: RLake@...
- Date: Wed, 24 Mar 2004 00:41:27 +0000
--------------------------
Phil: please don't take this personally :) I am writing
this only
because I have seen so many people following this
path lately, and
getting frustrated.
--------------------------
Phil Bewig escribe:
> As an exercise in learning to program in
lua, and because I
> think it will be a useful library to have, I am writing a
> library to manipulate linked lists.
In other words, you seek to learn how to program in
Lua by writing
a program in C, a language in which you are presumably
already
fluent, in order to create a datatype not present
in Lua so that
you could program in Lua as though it were, perhaps,
Lisp, a
language in which you are also presumably fluent.
This does not strike me as the best way to learn Lua.
In fact,
this sort of approach is likely to end up with your
fighting
with Lua and ultimately abandoning it for some language
you feel
more comfortable with. It rather reminds me of the
sadly typical
marriage in which both partners, although they have
fallen in love
with each other, immediately set out to change the
other into
someone else, someone who they had not fallen in love
with. This
can only end in tears.
If you want to learn a new language, you should at
least spend a
little time getting to understand how it fits together
on its own
terms, not as though it were some other language.
Lua does not
have linked lists, but it is still a useful and reasonably
fast
language. Why? Because other programming styles and
datatypes
fill that particular gap. Not, perhaps, perfectly,
but well enough.
At the same time, Lua provides other facilities not
common in
scripting languages, which simplify solving other
types of problems.
Despite the kitchen-sinkism of Perl, programming languages
are not
just lists of features. A well-designed programming
language is a
coherent whole whose paradigms complement each other;
things are
present because they fit and other things are absent
because they
don't.
On a more pragmatic level, if you continue with this
project, I think
you will end up getting very frustrated, because what
you seek to do
probably cannot be done, and certainly cannot be done
easily.
Like most scripting environments, Lua is pretty well
a sealed unit.
Internal datatypes are internal, and cannot easily
be extracted and
replaced later. (This is particularly the case for
languages built
around garbage collection, for reasons which should
be obvious. How,
for example, would you anticipate freeing a cons node?)
This is not to say that Lua is unwilling to share.
Its C interface
is very well defined and quite easy to use. You just
have to use it
on its own terms.