Re: [Tutor] Python vs. Lua

Magnus Lycka magnus at thinkware.se
Mon Dec 8 10:07:38 EST 2003


Daniel Ehrenberg wrote:
> Magnus Lyckå wrote:
> > I didn't get this part. How can it be used in more ways
> > because it lacks OO? You don't have to use OO in Python.
> > 
> It's more flexible than a builtin OO because it
> doesn't force you to do one thing in particular. For
> example, it is much easier to use prototypes (as in
> the Self programming language) in Lua than in Python. 

Ok, so it seems a  bit like Tcl in the respect that it's
more "half-cooked" and open-ended. You can make it into
something different...

Assuming I understood you right, I think this is a mixed 
blessing. I suppose it might be a good quality for an embedded 
macro language, where the user is expected to be able to make 
some specialized macros, and might not even know that he's 
actually programming Lua (or whatever). Then it would be a
good thing to fit the syntax for the particular needs of
the application.

In most cases, I think Python has a very good mix of rigidity
and flexibility. While it's very flexible concerning data
handling, it's fairly rigid in its syntax, and that helps
people read code they haven't written (or forgot what they
wrote :). I think the mantra "There should be one-- and 
preferably only one --obvious way to do it" is one of the
strengths of Python, but naturally, there is not one tool 
which is best at everything.

> There are far more projects that use C++ than Python,
> yet we're using Python.

Sure (although I use C++ as well).

There is far, far more substance in the Python standard
library than in the C++ standard library though. Most of the
C++ standard library consists of convoluted ways of doing what
Python very easily does with lists, strings, tuples and
dictionaries. How much code there is, and what other projects 
use isn't very important for me. What *I* can use from other 
projects is important. How much value does a module add? 

Python comes with most of what I need, and the few remaining 
gaps can be downloaded from some nearby site on the net. I 
think it's much easier to build a new app by glueing a few 
different Python modules together than to do something like 
that in C++, how ever many C++ libraries there are out there.

Both Python and Lua can make use of C++ libraries though,
by turning them into extension modules, so the wealth of
C++ code is a resource for both Python and Lua. But since
Python has so many more users, there is much higher likelyhood
that someone else have already written a Python wrapper for
that nice C or C++ library I need. For Lua I'd probably have
to do it myself. Programming Python is very convenient.

C, C++, Java and Visual Basic are very widely used, and everybody
have heard of them, it's easy to find books, training etc. Python 
is in the second league, most people I talk to never heard about 
it, but it's still possible to find Python training in little 
Sweden, there are about 40 Python programming books at Amazon 
etc. I never met a Lua programmer in the flesh (not that I 
know) and the only printed Lua book I heard of is "Game 
Programming With Python, Lua, and Ruby", which has sales rank 
1,157,473 at Amazon... These sorts of things matter if you
try to convince your boss to use Python or Lua in a project.

And while there might ten times more C++ than Python code 
freely available on the net, the amount of Python code seems
to be hundreds of times larger than the amount of Lua code.

It all depends on what you are trying to do. I use Python a
lot for testing, for data cleaning and transformation etc,
for system and database administration tasks, for web site 
development, business administration, document production
etc. I usually run the code on Windows or Linux. I don't
see that Lua would buy me anything here. Quite contrary, I
would miss things like ReportLab, wxPython etc.

On the other hand, if I were to write a game for a Palm
handheld, I would certainly prefer Lua.

> I forgot to mention that that Lua programs tend to be
> "flatter" than Python programs, something recommended
> by import this. The standard Lua distribution is
> written in pure ANSI C (like Python) with no real
> dependencies (unlike Python), so it is extremely
> portable and compiles anywhere tested without
> modification.

I assume less dependencies also mean fewer features. If
you could make good use of these features, you will miss
them, if you wouldn't, you might be happier with a smaller
language.

Python is obviously fairly portable as well, but as I said, 
I think Lua would be better in e.g. embedded devices. As
far as I understand the Lua core and standard library uses
around 64kB of RAM, and of course, that's much, much less
than Python. I imagine Lua is a much more reasonable language
if you are developing applications for a mobile phone or a
handheld. (But in a few years, I imagine running Python will
be less of a problem, also on cheap handhelds.)

Actually, I've been thinking of getting a Palm, and I
guess Lua would be a good programming language for that.
See http://netpage.em.com.br/mmand/plua.htm Hm... maybe I
should give myself a christmas gift and learn a new language?

-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus at thinkware.se



More information about the Tutor mailing list