Suitability of Lua as a First Programming Language?

classic Classic list List threaded Threaded
111 messages Options
1234 ... 6
Reply | Threaded
Open this post in threaded view
|

Suitability of Lua as a First Programming Language?

steve donovan
Hi all,

David M and myself were discussing the second question of the FAQ:

http://batbytes.com/luafaq/#T1.2

He thought that Lua is not that commonly used as a general purpose
language, but rather as an embedded scripting language.  This is
probably true.

But the question du jour is more whether Lua can be used as a good
introduction to programming, not necessarily as a 'trade skill'.  In
the same way, CS departments have variously used Pascal or Scheme for
this purpose.  Although Pascal was a rather frustrating language at
the time (Brian Kernighan has an interesting essay on the subject) it
was very good when I was a recovering FORTRAN programmer. (And Scheme
is definitely not a 'trade skill')

So, in other words, does it teach the basic concepts well?  Your
answers will help #T1.2 have a less idiosyncratic answer ;)

steve d.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Jerome Vuarand
2009/9/22 steve donovan <[hidden email]>:

> David M and myself were discussing the second question of the FAQ:
>
> http://batbytes.com/luafaq/#T1.2
>
> He thought that Lua is not that commonly used as a general purpose
> language, but rather as an embedded scripting language.  This is
> probably true.
>
> But the question du jour is more whether Lua can be used as a good
> introduction to programming, not necessarily as a 'trade skill'.  In
> the same way, CS departments have variously used Pascal or Scheme for
> this purpose.  Although Pascal was a rather frustrating language at
> the time (Brian Kernighan has an interesting essay on the subject) it
> was very good when I was a recovering FORTRAN programmer. (And Scheme
> is definitely not a 'trade skill')
>
> So, in other words, does it teach the basic concepts well?  Your
> answers will help #T1.2 have a less idiosyncratic answer ;)

I think Lua would be a very good first programming language, it can
teach most procedural languages features. However teaching some of its
advanced features (like coroutines or tail calls) might make the
transition to real world languages (ie. C++ and Java) harder. But
hopefully raising programmer expectation might help the market improve
by itself.

Another point that could be problematic is that, still compared to C++
and Java, Lua is fully imperative, while these former two are part
imperative, part declarative. However most Lua programs and libraries
are written in a pseudo-declarative style anyway, so that might not be
a concern.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

David Kastrup
In reply to this post by steve donovan
steve donovan <[hidden email]> writes:

> Hi all,
>
> David M and myself were discussing the second question of the FAQ:
>
> http://batbytes.com/luafaq/#T1.2
>
> He thought that Lua is not that commonly used as a general purpose
> language, but rather as an embedded scripting language.  This is
> probably true.
>
> But the question du jour is more whether Lua can be used as a good
> introduction to programming, not necessarily as a 'trade skill'.  In
> the same way, CS departments have variously used Pascal or Scheme for
> this purpose.  Although Pascal was a rather frustrating language at
> the time (Brian Kernighan has an interesting essay on the subject) it
> was very good when I was a recovering FORTRAN programmer. (And Scheme
> is definitely not a 'trade skill')
>
> So, in other words, does it teach the basic concepts well?  Your
> answers will help #T1.2 have a less idiosyncratic answer ;)

Lua's data structures are not that of the underlying computer.  It does
not teach you what is computationally expensive, and what not.  And
since it has only one, it does not teach you how to pick.  For that, C
is a rather good fit (the seminal "Art of Computer Programming"
restricts itself to assembly language), with exceptions in the area of
arithmetic, where accessing the carry flag and mixed precision
operations are not practical.

C++ (also Java) build large complex languages over a C foundation.
Those buildings don't add anything of value that Lua does not also
provide.

C++ is designed like the button layout of a typical bandonion: there is
a small specialized regular area left and right that is just like its
earliest predecessors, the diatonic accordion where you had to change
bellows direction on each note for a scale, and had simple accompaniment
on the left side.  Around that, layers of irregular help buttons have
grown in order to have more and more notes available, like on other
instruments.  And the thing has become so heavy that changing bellows
direction became less feasible, and so more buttons are added to be able
to avoid changing directions.  The thing nowadays has a mostly
feature-complete collection of notes left, right, and for push and pull,
and all of those four are completely different due to historical
reasons.

Now look at a typical Argentinian playing tango: he never even _pushes_
the thing (because then he would have to double the notes and layouts he
has to learn by heart, and on push the thing reaches further, but is not
as complete), so you could just glue half of the reeds shut and improve
the air balance for those reeds that are actually used.  There is
historical sense and reason behind the layout, but unless he actually
learnt playing on one of the smaller predecessors of his instrument,
that's totally lost to him.

Which brings us to chromatic accordions.  You don't get to carefully
select whether to play a phrase or a part of the phrase on the push or
pull (like true masters would), because you get the same sound, anyway:
it is unisonoric.  And the notes are arranged sort of linearly with
regard to pitch.

Oh, by the way: anybody want to buy a Hohner Morino Club N accordion?
Perfectly in tune, and quite more coherent than a bandonion, even though
it is diatonic/bisonoric.

Uh, I digress.

For the FAQ answer:

Lua provides a rather well-sorted toolbox of excellent tools for solving
programming problems.  While it severely limits your ways of tailoring
data structures to make the best fit between problem and machine, the
available possibilities are typically fine.  "Serious" programming
nowadays heavily relies on frameworks and libraries, and those are quite
more limiting usually and also shield you from data structure choices of
your own.  When the difference effectively boils down to "you don't want
to know" vs "there is nothing more to know", the latter choice will let
you focus on your work and provides safety against fighting with strange
side effects.

--
David Kastrup

Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Gavin Wraith
In reply to this post by Jerome Vuarand
In message <[hidden email]>
you wrote:

> > But the question du jour is more whether Lua can be used as a good
> > introduction to programming, not necessarily as a 'trade skill'.

> I think Lua would be a very good first programming language,

I can only speak for myself, but I never really understood object-oriented
programming until I encountered Lua. The reason for this, I think, is
that Lua lets you maintain a reasonably accurate mental picture of
how data is structured in memory. Tables may be implemented in a
subtle way, but one can employ oversimplifications (such as blocks
of pointers) that help imagination. The fact that dot (.) and colon (:)
in Lua are syntactic sugar expressible in terms of table-lookup I
found enlightening.

--
Gavin Wraith ([hidden email])
Home page: http://www.wra1th.plus.com/
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

steve donovan
In reply to this post by David Kastrup
On Tue, Sep 22, 2009 at 11:39 AM, David Kastrup <[hidden email]> wrote:
> Lua's data structures are not that of the underlying computer.  It does
> not teach you what is computationally expensive, and what not.  And
> since it has only one, it does not teach you how to pick.  For that, C
> is a rather good fit

Yes, if you were teaching how computers actually work, which makes it
a good _second_ language.

> Uh, I digress.
But an entertaining comparison! Has C++ _ever_ been compared to an
accordion before?  By comparison, C is one of those little squeeze
boxes that is an essential part of Afrikaans folk music.

> Lua provides a rather well-sorted toolbox of excellent tools for solving
> programming problems.  While it severely limits your ways of tailoring
> data structures to make the best fit between problem and machine, the
> available possibilities are typically fine.

Creativity flourishes through limitation ;)

>  "Serious" programming
> nowadays heavily relies on frameworks and libraries, and those are quite
> more limiting usually and also shield you from data structure choices of
> your own.

Java frameworks always remind me of filling in forms in triplicate.

steve d.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

steve donovan
In reply to this post by Jerome Vuarand
On Tue, Sep 22, 2009 at 10:27 AM, Jerome Vuarand
<[hidden email]> wrote:
> I think Lua would be a very good first programming language, it can
> teach most procedural languages features. However teaching some of its
> advanced features (like coroutines or tail calls) might make the
> transition to real world languages (ie. C++ and Java) harder.

A little feature envy never hurt anyone ;)  Another such feature is
having proper closures,  which opens up the way for the functional
style of programming.  Indeed, a lot of C++/Java class use is
compensating for lack of closures.

> Another point that could be problematic is that, still compared to C++
> and Java, Lua is fully imperative, while these former two are part
> imperative, part declarative. However most Lua programs and libraries
> are written in a pseudo-declarative style anyway, so that might not be
> a concern.

In those languages, declaration is essential, in Lua a matter of
style.  Whether this is considered a good thing, is itself a matter of
style.

steve d.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

David Kastrup
In reply to this post by steve donovan
steve donovan <[hidden email]> writes:

> On Tue, Sep 22, 2009 at 11:39 AM, David Kastrup <[hidden email]> wrote:
>> Lua's data structures are not that of the underlying computer.  It does
>> not teach you what is computationally expensive, and what not.  And
>> since it has only one, it does not teach you how to pick.  For that, C
>> is a rather good fit
>
> Yes, if you were teaching how computers actually work, which makes it
> a good _second_ language.
>
>> Uh, I digress.
> But an entertaining comparison! Has C++ _ever_ been compared to an
> accordion before?

A bandonion.

> By comparison, C is one of those little squeeze boxes that is an
> essential part of Afrikaans folk music.

Actually, my main instrument is like Ada.  Regular layout left and
right, five addressable octaves on each side, and you have a slider for
specifying the location of the octave break in the chord section (which
is not changeable for sane instruments).

--
David Kastrup

Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Tony Finch
In reply to this post by steve donovan
On Tue, 22 Sep 2009, steve donovan wrote:
>
> But the question du jour is more whether Lua can be used as a good
> introduction to programming, not necessarily as a 'trade skill'.

I think a first language needs quite a lot of batteries included, so that
the teacher can provide fun motivating exercises. Graphics, sound,
networking, hooks into the OS and/or apps (like AppleScript), etc.

As a bare programming language I think Lua is great for teaching, but it
needs a load of addons to provide a fun environment. What I would like is
something a bit like BBC BASIC on the Master (i.e. with a full-screen
editor as well as old-school line-by-line input).

Tony.
--
f.anthony.n.finch  <[hidden email]>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

David Given
Tony Finch wrote:
[...]
> As a bare programming language I think Lua is great for teaching, but it
> needs a load of addons to provide a fun environment. What I would like is
> something a bit like BBC BASIC on the Master (i.e. with a full-screen
> editor as well as old-school line-by-line input).

I still think Logo is an excellent teaching language. It's got a lot of
instant gratification (type in a word, press RETURN, something happens!)
while also being a real language underneath (it's pretty much a
Lisp-lite, without the scary parentheses).

Unfortunately it *is* rather dated, with things like not having any
strings (instead there are lists of 'words'), rather peculiar variable
syntax, and you have to build your own OO system if you want one.

Luckily, modern Logos are substantially faster than Acornsoft Logo --- I
remember those five-second garbage collection pauses...

--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────

│ "They laughed at Newton. They laughed at Einstein. Of course, they
│ also laughed at Bozo the Clown." --- Carl Sagan
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

steve donovan
In reply to this post by Tony Finch
On Tue, Sep 22, 2009 at 1:27 PM, Tony Finch <[hidden email]> wrote:
> As a bare programming language I think Lua is great for teaching, but it
> needs a load of addons to provide a fun environment. What I would like is
> something a bit like BBC BASIC on the Master (i.e. with a full-screen
> editor as well as old-school line-by-line input).

I remember BBC BASIC too, on the Archimedes. Fun machines.

LOGO was cool, ahead of its time, especially with Seymour Papert's
idea of 'a dignified mathematics for children'.

It would not BTW be too difficult to do a Turtle Graphics environment for Lua.

steve d.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Pierre LeMoine
In reply to this post by Tony Finch
> I think a first language needs quite a lot of batteries included, so that
> the teacher can provide fun motivating exercises. Graphics, sound,
> networking, hooks into the OS and/or apps (like AppleScript), etc.
>
Our first programming course on my university teached Lisp. The second
one Ada. Graphics and fun functions didn't come until a whole year had
passed, when we started playing with Java, but the focus of that
course was OO and not graphics etc. I think Lua could very well be a
first language, it does have console input/output, just as Lisp and
Ada ;D
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

steve donovan
On Tue, Sep 22, 2009 at 2:02 PM, Pierre LeMoine <[hidden email]> wrote:
> one Ada. Graphics and fun functions didn't come until a whole year had
> passed, when we started playing with Java, but the focus of that
> course was OO and not graphics etc. I think Lua could very well be a
> first language, it does have console input/output, just as Lisp and
> Ada ;D

It's just such _fun_ to do graphics, even if you have to use Java to get there!

Java standard graphics/Swing works very nicely with LuaJava, with a
few helper classes.  Nice tool to learn the Java platform, as opposed
to the language.  E.g. it's not too difficult to have a proper
GUI-hosted interactive interpreter (not just a 'enter and click'
interface) and then you can really boss around Swing windows.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Tony Finch
In reply to this post by Pierre LeMoine
On Tue, 22 Sep 2009, Pierre LeMoine wrote:
>
> Our first programming course on my university teached Lisp.

I was thinking of pre-university teaching or self-discovery.

It's nice that you can now get cheap and robust computers that you can
give to children without worrying too much about breakages. (Not nearly
as simple as the computers of 20-30 years ago, though...)

Tony.
--
f.anthony.n.finch  <[hidden email]>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Gavin Wraith
In reply to this post by Tony Finch
In message <[hidden email]>
you wrote:

> I think a first language needs quite a lot of batteries included, so that
> the teacher can provide fun motivating exercises. Graphics, sound,
> networking, hooks into the OS and/or apps (like AppleScript), etc.
>
> As a bare programming language I think Lua is great for teaching, but it
> needs a load of addons to provide a fun environment. What I would like is
> something a bit like BBC BASIC on the Master (i.e. with a full-screen
> editor as well as old-school line-by-line input).

You should try RiscLua 5.0 on a RISC OS machine. Its access to the OS
resembles that of BBC Basic on purpose, to make it easier for those
weaned on BBC Basic. The 'riscos' library in RiscLua has !,?,$,dim,sys
corresponding to BBC Basic's !,?,$,DIM,SYS, though the syntax in
RiscLua is rather cleaner. This makes a naive conversion from Basic
programs to RiscLua straightforward. The StrongED editor provides an easy
development environment, in which it is possible to write a Lua
program in one window and have it modify text in another - by
dragging onto an icon in the window's toolbar. The (imaginary) file
containing the text accessed as arg[1] and the new text is obtained
from stdout. For example

 #! lua
 for line in io.lines(arg[1]) do
   if not line:match "Basingstoke" then print(line) end -- if
 end -- for

will remove all lines containing "Basingstoke". So not much effort is
needed to produce programs that do things in the desktop.

The access to the OS makes RiscLua as usable on the Master's descendent's
as BBC Basic. It also has facilities such as iteration over objects in
a directory that Basic needed but never had.

--
Gavin Wraith ([hidden email])
Home page: http://www.wra1th.plus.com/
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

David Given
In reply to this post by steve donovan
steve donovan wrote:
[...]
> I remember BBC BASIC too, on the Archimedes. Fun machines.

I've still got one! Er, anyone want a very battered RISC PC?

> LOGO was cool, ahead of its time, especially with Seymour Papert's
> idea of 'a dignified mathematics for children'.

I suspect that being ahead of its time is what killed it --- it was
fundamentally too heavyweight for the day's 8-bit micros. LOGO on the
BBC was painful. Acornsoft LOGO came with some extremely cool demos,
including a Prolog-light written in LOGO that I was way too young to
appreciate at the time, but it took about five minutes to run!

So I think it got a reputation for being a toy suitable for fiddling
around with turtles but not capable of anything more, which is a shame,
as it's vastly more powerful than that. (It has list management
primitives copied intact from LISP, which pretty much invented list
processing. And, like LISP, code and data are interchangeable, which
gave it really good introspection abilities.)

> It would not BTW be too difficult to do a Turtle Graphics environment for Lua.

I'm actually wondering whether it would be possible to do a LOGO
pseudo-JIT in Lua, which converted code into Lua for execution
on-the-fly. You'd need to know more about LOGO's detailed execution
semantics than I do; if I have a sequence [FUNCTION1 arg FUNCTION2 arg
arg] where FUNCTION1 redefines FUNCTION2 to only take one argument, what
happens, for example?

But with that all figured out it might not be particularly hard, and
ought to really fly... Lua is *good* at this sort of thing!

--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────

│ "They laughed at Newton. They laughed at Einstein. Of course, they
│ also laughed at Bozo the Clown." --- Carl Sagan
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Fabio Mascarenhas
In reply to this post by Tony Finch
On Tue, Sep 22, 2009 at 8:27 AM, Tony Finch <[hidden email]> wrote:
> I think a first language needs quite a lot of batteries included, so that
> the teacher can provide fun motivating exercises. Graphics, sound,
> networking, hooks into the OS and/or apps (like AppleScript), etc.
>
> As a bare programming language I think Lua is great for teaching, but it
> needs a load of addons to provide a fun environment. What I would like is
> something a bit like BBC BASIC on the Master (i.e. with a full-screen
> editor as well as old-school line-by-line input).

There is always the more specialized embeddings of Lua like Löve2D
(http://www.love2d.org/) if you want better visuals, I think something
like this would do just fine for a first semester "Introduction to
Programming" course. It would probably be enough to do the computer
graphics examples of SICP, for example.

Diego Nehab also built a nice game where you control prospecting
robots under the ocean, each robot has a few sensors to probe the
ocean floor, and you can set prospecting probes to tap oil and
increase your score. It was used at PUC-Rio in a very introductory
course on computer programming
(http://www.inf.puc-rio.br/~mascarenhas/robots/), which now uses real
robots with pbLua. :-)

Last year Roberto taught an "Introduction to Lua" course at PUC-Rio
that I think had some complete programming newbies, as it was not
intended solely for CS students. He can give his two cents on that
when he reads this thread.

> Tony.
> --
> f.anthony.n.finch  <[hidden email]>  http://dotat.at/

--
Fabio Mascarenhas, Lablua
http://www.lua.inf.puc-rio.br
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Cosmin Apreutesei
In reply to this post by Pierre LeMoine
On Tue, Sep 22, 2009 at 15:02, Pierre LeMoine <[hidden email]> wrote:

>> I think a first language needs quite a lot of batteries included, so that
>> the teacher can provide fun motivating exercises. Graphics, sound,
>> networking, hooks into the OS and/or apps (like AppleScript), etc.
>>
> Our first programming course on my university teached Lisp. The second
> one Ada. Graphics and fun functions didn't come until a whole year had
> passed, when we started playing with Java, but the focus of that
> course was OO and not graphics etc. I think Lua could very well be a
> first language, it does have console input/output, just as Lisp and
> Ada ;D
>

Yea, but that's how school is, boring first, fun later. Only after the
school is over you get interested (even educated) in what you had
(just mechanically) learned in school. But unlike other disciplines,
computers allow us to teach ourselves when everything else fails - so
you even get a chance to get interested in computers while _in_
school. Back in the 9th grade, we were taught Turbo Pascal, and I put
a text-mode colored Matrix screensaver with rolling letters in one of
my first homework programs (The Matrix was screening in our town
then). It was my first outburst of programming creativity, the success
of which (measured both in terms of personal satisfaction and social
affirmation of potential) could well be one of the reasons I set
myself up for programming. The program itself was was some boring
backtracking stuff I had no interest in. Lucky for me I never let my
schooling get in the way of my education :)

But I digress. I think Lua is a wonderful first language because it
gets you hooked quickly (by instant gratification), and after that you
are bound to get way down to C and implicitly to the PC architecture
itself - no blackboxes in the path either. By contrast, Delphi or Java
can keep you ignorant for years :)

Also, one's professional "tool belt" should better not hold
programming languages. If you can't educate the industry, cheat it. My
resume is full of acronyms I can only talk about on an interview. No,
I don't care if my employer reads this message - I already fooled him
:)
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Pan, Shi Zhu
IMO python is by far the better language for "first programming
language" than Lua.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

Rob Kendrick
On Tue, 22 Sep 2009 21:34:54 +0800
pan shizhu <[hidden email]> wrote:

> IMO python is by far the better language for "first programming
> language" than Lua.

If you're going to make an audacious assertion, please back it up with
justification :)

B.
Reply | Threaded
Open this post in threaded view
|

Re: Suitability of Lua as a First Programming Language?

steve donovan
In reply to this post by Pan, Shi Zhu
On Tue, Sep 22, 2009 at 3:34 PM, pan shizhu <[hidden email]> wrote:
> IMO python is by far the better language for "first programming
> language" than Lua.

That may be true, but why? Is it because it has more 'out of the box'?

I like Python, and I use it because my colleagues like it, but the
whitespace thing may confuse newbies.

Plus, you have to learn about lists and dicts (with an awkward
syntax), whereas we just have tables.
1234 ... 6