From Lua to Python?

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

Re: From Lua to Python?

Coda Highland
On Wed, Jul 12, 2017 at 5:22 PM, Dibyendu Majumdar
<[hidden email]> wrote:

> On 11 July 2017 at 20:46, Dibyendu Majumdar <[hidden email]> wrote:
>> On 1 July 2017 at 00:09, Dibyendu Majumdar <[hidden email]> wrote:
>>> I am thinking about moving to Python in my project where I am
>>> currently using Lua as the scripting language. My reason is a
>>> pragmatic one - Python is becoming popular in the Financial sector,
>>> and is the language most people my project targets will be familiar
>>> with. Additionally some of the tools I use - such as Google's GRPC and
>>> Protocol Buffers - all support Python.
>>>
>>
>> Strange though it may sound, I had never bothered to learn Python
>> until now. Still early days but so far my thoughts are that maybe both
>> Lua and Python have a place in my project. Maybe Lua is the better
>> embedded language, but Python is the more versatile scripting
>> language. Too early to tell though.
>>
>
> I am reading the Python language reference and am completely
> overwhelmed by the complexity - not of the language per se which seems
> slightly more complex than Lua - but the meta mechanisms which are too
> numerous for me to try and remember them all. Makes me appreciate
> Lua's comparative simplicity - there is only one meta mechanism to
> understand in Lua - the metatable.
>
> Regards
> Dibyendu
>

To be fair, Python doesn't just have meta-mechanisms, it has
meta-meta-mechanisms. Most programmers will never need to worry about
this, but the tools are there for the purpose of allowing sufficiently
clever people to extend the class system itself rather than just
extending a class. This is generally useful for things like
automatically hooking up behaviors into subclasses -- a classic
example is data persistence, where a metaclass has the ability to look
at the structure of the subclass and create the necessary functions to
dynamically create them from stored data, without requiring the user
of the persistence library to screw around with decorating all of
their stuff.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Dirk Laurie-2
In reply to this post by Dibyendu Majumdar
2017-07-13 0:22 GMT+02:00 Dibyendu Majumdar <[hidden email]>:

> On 11 July 2017 at 20:46, Dibyendu Majumdar <[hidden email]> wrote:
>> On 1 July 2017 at 00:09, Dibyendu Majumdar <[hidden email]> wrote:
>>> I am thinking about moving to Python in my project where I am
>>> currently using Lua as the scripting language. My reason is a
>>> pragmatic one - Python is becoming popular in the Financial sector,
>>> and is the language most people my project targets will be familiar
>>> with. Additionally some of the tools I use - such as Google's GRPC and
>>> Protocol Buffers - all support Python.
>>>
>>
>> Strange though it may sound, I had never bothered to learn Python
>> until now. Still early days but so far my thoughts are that maybe both
>> Lua and Python have a place in my project. Maybe Lua is the better
>> embedded language, but Python is the more versatile scripting
>> language. Too early to tell though.
>>
>
> I am reading the Python language reference and am completely
> overwhelmed by the complexity - not of the language per se which seems
> slightly more complex than Lua - but the meta mechanisms which are too
> numerous for me to try and remember them all. Makes me appreciate
> Lua's comparative simplicity - there is only one meta mechanism to
> understand in Lua - the metatable.

I've been reading this thread telling myself firmly that I will not
give any opinion whatsoever, and I won't violate that resolution.

However, history is not an opinion. I learnt Python in the mid-2000s,
opened a little trapdoor marked "From Python to Lua" in November
2010, decided to go into that loft just to look around, and after a month
discovered that the trapdoor would not open from the other side.

-- Dirk

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Dibyendu Majumdar
Hi Dirk,

On 13 July 2017 at 07:43, Dirk Laurie <[hidden email]> wrote:

> 2017-07-13 0:22 GMT+02:00 Dibyendu Majumdar <[hidden email]>:
>> I am reading the Python language reference and am completely
>> overwhelmed by the complexity - not of the language per se which seems
>> slightly more complex than Lua - but the meta mechanisms which are too
>> numerous for me to try and remember them all. Makes me appreciate
>> Lua's comparative simplicity - there is only one meta mechanism to
>> understand in Lua - the metatable.
>
> I've been reading this thread telling myself firmly that I will not
> give any opinion whatsoever, and I won't violate that resolution.
>
> However, history is not an opinion. I learnt Python in the mid-2000s,
> opened a little trapdoor marked "From Python to Lua" in November
> 2010, decided to go into that loft just to look around, and after a month
> discovered that the trapdoor would not open from the other side.
>

Sadly when you are developing products for customers they get to say
what they would like to use! Python appears to have become the de
facto standard scripting language in certain domains, just as Lua is
the language for games. If you were developing a game you would
probably not try to get people to use Python.

I am not sure what has propelled Python to this spot - perhaps the
adoption by Google several years ago. The number of Python libraries
available seems astonishing.

There have been several threads here on how to grow Lua. It would be
interesting to understand the driving factors behind Python's
popularity and maybe some of that can be adopted in Lua. I don't
really know but it seems to me:

a) Python has successful built a strong community of contributors. Of
course Lua being controlled exclusively by the Lua team has a
completely different model - there are no external contributors to
Lua.
b) For corporations to get involved they probably need to have some
degree of say in the project. Again the Lua model is not suited to
that. I understand that the reason Microsoft invented .Net and Google
invented Go was that they wanted control - but Java was not open to
sharing that. But Javascript and Python have adopted a more open model
(similar to Linux) which may be a key to their popularity.
c) I think also that the willingness to build a large echo system of
libraries that are blessed by the core team is beneficial.

Some of these things could perhaps be addressed, like (c) above, while
keeping the spirit of Lua - i.e. keep the core simple and uncluttered.

Regards
Dibyendu

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Dibyendu Majumdar
In reply to this post by Coda Highland
Hi Adam,

On 13 July 2017 at 05:11, Coda Highland <[hidden email]> wrote:

> On Wed, Jul 12, 2017 at 5:22 PM, Dibyendu Majumdar
> <[hidden email]> wrote:
>> I am reading the Python language reference and am completely
>> overwhelmed by the complexity - not of the language per se which seems
>> slightly more complex than Lua - but the meta mechanisms which are too
>> numerous for me to try and remember them all. Makes me appreciate
>> Lua's comparative simplicity - there is only one meta mechanism to
>> understand in Lua - the metatable.
>>
> To be fair, Python doesn't just have meta-mechanisms, it has
> meta-meta-mechanisms. Most programmers will never need to worry about
> this, but the tools are there for the purpose of allowing sufficiently
> clever people to extend the class system itself rather than just
> extending a class. This is generally useful for things like
> automatically hooking up behaviors into subclasses -- a classic
> example is data persistence, where a metaclass has the ability to look
> at the structure of the subclass and create the necessary functions to
> dynamically create them from stored data, without requiring the user
> of the persistence library to screw around with decorating all of
> their stuff.
>

You are right but it is a lot to take in! And no wonder it has been so
hard to built JIT technology for Python - because any implementation
has to respect all the meta meta mechanisms.

Regards
Dibyendu

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Javier Guerra Giraldez
In reply to this post by Dibyendu Majumdar
On 13 July 2017 at 10:44, Dibyendu Majumdar <[hidden email]> wrote:
> I am not sure what has propelled Python to this spot - perhaps the
> adoption by Google several years ago.


I think part of the merit is in NumPY library.  it was well known in
number crunching before the "data science" moniker.  Since it removes
the iterations from Python code, it performs quite well, as long as
your process can be expressed with the provided operators.  It also
meshes well with OpenCV and Tensor Flow, so for the current generation
of newcomers it feels as if Python was actually an appropriate
language for today's buzzwords.

it really doesn't feel fair to the Torch project, which manages
similar (or better) crunching performance without taking flow control
away from the language, and had most of the convolutions and kernels
long before Tensor Flow put that in front of the masses.  OTOH, i
think it doesn't make as straightforward to take advantage of SSE/GPU
for extra horsepower...


--
Javier

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Dibyendu Majumdar
On 13 July 2017 at 12:07, Javier Guerra Giraldez <[hidden email]> wrote:

> On 13 July 2017 at 10:44, Dibyendu Majumdar <[hidden email]> wrote:
>> I am not sure what has propelled Python to this spot - perhaps the
>> adoption by Google several years ago.
>
>
> I think part of the merit is in NumPY library.  it was well known in
> number crunching before the "data science" moniker.  Since it removes
> the iterations from Python code, it performs quite well, as long as
> your process can be expressed with the provided operators.  It also
> meshes well with OpenCV and Tensor Flow, so for the current generation
> of newcomers it feels as if Python was actually an appropriate
> language for today's buzzwords.
>

Certainly having something like NumPY has made a big difference. But I
also think that Python's built in support for classes might be a
factor. Having a standard way of doing OO programming probably helps.
For numeric type stuff - the availability of array types / and
associated features such as slicing is helpful - especially as they
can be used in the C API too. This is one thing I wish I could improve
in Ravi - particularly the ability to efficiently handle multi
dimensional arrays.

> it really doesn't feel fair to the Torch project, which manages
> similar (or better) crunching performance without taking flow control
> away from the language, and had most of the convolutions and kernels
> long before Tensor Flow put that in front of the masses.  OTOH, i
> think it doesn't make as straightforward to take advantage of SSE/GPU
> for extra horsepower...
>

BTW there is https://github.com/pytorch project now - so I wonder if
the work has shifted from Lua Torch to a Python based implementation.

Regards

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Enrico Colombini
On 13-Jul-17 13:47, Dibyendu Majumdar wrote:
> Certainly having something like NumPY has made a big difference. But I
> also think that Python's built in support for classes might be a
> factor. Having a standard way of doing OO programming probably helps.

Those considerations could be involved, but I think the main factors in
Python popularity (vs. Lua) are simply the ease of installation of
language and add-ons on Windows for non-experts and the huge amount of
ready-to-use libraries (even if sometimes confusing, overlapping, badly
documented and not always coherent).

I once wrote a program that needed both serial communication and
scientific numerical libraries. It had to run on Linux and Windows and
be simple to install for non-programmers, so I chose Python.
It is fair to note that installing NumPy on Windows proved to be much
more complex than anticipated, in fact not simpler than adding Lua
libraries, so for the Windows version I advised my users to use
pre-built Anaconda (https://www.continuum.io/)... and, having no time to
spare, did the same myself.

I think that the previously-discussed "ActiveLua" from ActiveState could
be quite useful to Windows users in such situations.

--
   Enrico

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

steve donovan
On Thu, Jul 13, 2017 at 2:51 PM, Enrico Colombini <[hidden email]> wrote:
> Those considerations could be involved, but I think the main factors in
> Python popularity (vs. Lua) are simply the ease of installation of language
> and add-ons on Windows for non-experts and the huge amount of ready-to-use
> libraries (even if sometimes confusing, overlapping, badly documented and
> not always coherent).

Exactly - Python is popular because it's popular ;)  It's a more
complex language than Lua but hides its complexity well, until the
fish is on the hook and committed to the experience.  It is an
accessible front end to a large universe of libraries.

As for object-orientation? That's really a programmer cult, and people
who come in just to get work done need not worry about that kind of
thing.

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Javier Guerra Giraldez
On 13 July 2017 at 14:09, steve donovan <[hidden email]> wrote:
> As for object-orientation? That's really a programmer cult, and people
> who come in just to get work done need not worry about that kind of
> thing.
>

but a rather big checkbox in enterprisey decision making

--
Javier

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

steve donovan
On Thu, Jul 13, 2017 at 3:21 PM, Javier Guerra Giraldez
<[hidden email]> wrote:
> but a rather big checkbox in enterprisey decision making

Which is a pity, since people who have learned it seem to be forever
stuck like flies in amber.

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Dibyendu Majumdar
On 13 July 2017 at 14:27, steve donovan <[hidden email]> wrote:
> On Thu, Jul 13, 2017 at 3:21 PM, Javier Guerra Giraldez
> <[hidden email]> wrote:
>> but a rather big checkbox in enterprisey decision making
>
> Which is a pity, since people who have learned it seem to be forever
> stuck like flies in amber.
>

Actually OO is essential tool for organizing large code bases. I am
not talking about inheritance and all - but just the ability to
organize your code into objects of different types. Remember objects
carry state.
I find that even with Lua, when I am exposing an API - I need to make
it OO for the user else user has to manage state and call functions
with potentially large number of arguments which just doesn't make
sense.

Regards

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Enrico Colombini
On 13-Jul-17 15:48, Dibyendu Majumdar wrote:
> Actually OO is essential tool for organizing large code bases. I am
> not talking about inheritance and all - but just the ability to
> organize your code into objects of different types. Remember objects
> carry state.

If you take away inheritance, I do not think you can call it "OO"
anymore (at least not as the term is commonly defined).

> I find that even with Lua, when I am exposing an API - I need to make
> it OO for the user else user has to manage state and call functions
> with potentially large number of arguments which just doesn't make
> sense.

You can easily do encapsulation in Lua, for example using modules as
'objects' with private functions/data and a public API. Of course
polymorphism is there by default.

--
   Enrico

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Dibyendu Majumdar
On 13 July 2017 at 15:06, Enrico Colombini <[hidden email]> wrote:

> On 13-Jul-17 15:48, Dibyendu Majumdar wrote:
>>
>> I find that even with Lua, when I am exposing an API - I need to make
>> it OO for the user else user has to manage state and call functions
>> with potentially large number of arguments which just doesn't make
>> sense.
>
>
> You can easily do encapsulation in Lua, for example using modules as
> 'objects' with private functions/data and a public API. Of course
> polymorphism is there by default.
>

I find that it is better to ensure the OO syntax - i.e.:

object:method()

As this gives an immediate check on valid operations for each object /
class type.

Sure this is easy enough to do in Lua - and I do it all the time. But
for many people an explicit class definition syntax appears to be
attractive - I am not one of those people, but that is what I see.

Regards
Dibyendu

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

steve donovan
In reply to this post by Dibyendu Majumdar
On Thu, Jul 13, 2017 at 3:48 PM, Dibyendu Majumdar
<[hidden email]> wrote:
> Actually OO is essential tool for organizing large code bases. I am
> not talking about inheritance and all - but just the ability to
> organize your code into objects of different types. Remember objects
> carry state.

We used to do that in C just fine ;)  It's a useful set of ideas, but
when it becomes a dogma and its meaning gets fossilized into whatever
the 'class' statement does, then it ceases to be so useful and spawns
its own pathologies, like the 'fragile base class problem' etc.

I've noticed this issue play out with Rust, which also does not have a
'class' concept. People have to wake up from their OO slumbers and
remember important distinctions between interface and implementation
inheritance etc.

This can easily stray too far from our topic, but I'm happy that Lua
does not have a class keyword. I learned that closures are so often
what we need.

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Sean Conner
In reply to this post by Dibyendu Majumdar
It was thus said that the Great Dibyendu Majumdar once stated:
>
> There have been several threads here on how to grow Lua. It would be
> interesting to understand the driving factors behind Python's
> popularity and maybe some of that can be adopted in Lua. I don't
> really know but it seems to me:

  To me, it's obvious---Python is an opinionated program.  There's only
*one* way to do things.  That, and an almost forced programming style.
People really seem to like belligerent software ("don't make me think,
bro!") [1].

  -spc (Oh, and the slow release schedule of Lua is anathema to today's
        CADT hipster programmers [3]).

[1] Like Go.  "There is one way to format code!  [2] And any features we
        deem "difficult" are ignored.

[2] I'm really surprised that the developers of Go dropped the ball and
        didn't enforce the style at the language level.  The wimps!

[3] https://www.jwz.org/doc/cadt.html


Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Sean Conner
In reply to this post by Dibyendu Majumdar
It was thus said that the Great Dibyendu Majumdar once stated:

> On 13 July 2017 at 14:27, steve donovan <[hidden email]> wrote:
> > On Thu, Jul 13, 2017 at 3:21 PM, Javier Guerra Giraldez
> > <[hidden email]> wrote:
> >> but a rather big checkbox in enterprisey decision making
> >
> > Which is a pity, since people who have learned it seem to be forever
> > stuck like flies in amber.
> >
>
> Actually OO is essential tool for organizing large code bases. I am
> not talking about inheritance and all - but just the ability to
> organize your code into objects of different types. Remember objects
> carry state.

  OO is good when you have a large number of nouns (data types) and a few
verbs (actions upon said data).  Reverse the situation, and normal
imperative programming is easier.

  Also, we all misunderstood Alan Kay when he popularized OO [1].  Then
again, he *misunderstood* himself [2] so it's understandable if we all
missed the point of OO.  It's not objects---it's small programs that respond
to messages.  Basically, message based programming.

> I find that even with Lua, when I am exposing an API - I need to make
> it OO for the user else user has to manage state and call functions
> with potentially large number of arguments which just doesn't make
> sense.

  You know that objects are just a poor man's closure, right? [4]

  -spc (But a closure is just a poor man's object ... )

[1] He didn't invent it---that was primarily the developers of Simula.

[2] And is still yelling at us for not reading his mind [3].

[3] Yes, I'm in a cynical frame of mind today.

[4] http://wiki.c2.com/?ClosuresAndObjectsAreEquivalent

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Coda Highland
In reply to this post by Sean Conner
On Thu, Jul 13, 2017 at 12:19 PM, Sean Conner <[hidden email]> wrote:

> It was thus said that the Great Dibyendu Majumdar once stated:
>>
>> There have been several threads here on how to grow Lua. It would be
>> interesting to understand the driving factors behind Python's
>> popularity and maybe some of that can be adopted in Lua. I don't
>> really know but it seems to me:
>
>   To me, it's obvious---Python is an opinionated program.  There's only
> *one* way to do things.  That, and an almost forced programming style.
> People really seem to like belligerent software ("don't make me think,
> bro!") [1].

That's actually an explicit design goal. In opposition to Perl's
"there's more than one way to do it", Python's documented policy is
"there should be one (and preferably only one) obvious way to do it".

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Dibyendu Majumdar
In reply to this post by Sean Conner
On 13 July 2017 at 18:19, Sean Conner <[hidden email]> wrote:
> It was thus said that the Great Dibyendu Majumdar once stated:
>>
>> There have been several threads here on how to grow Lua. It would be
>> interesting to understand the driving factors behind Python's
>> popularity and maybe some of that can be adopted in Lua. I don't
>> really know but it seems to me:
>
>   To me, it's obvious---Python is an opinionated program.

I see Lua as equally opinionated if not more.

Regards

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

djczaski
In reply to this post by Sean Conner

> On Jul 13, 2017, at 1:38 PM, Sean Conner <[hidden email]> wrote:
>
> [2]    And is still yelling at us for not reading his mind [3].
>
> [3]    Yes, I'm in a cynical frame of mind today.

Footnoting and footnote. [1]

[1] LOL

Reply | Threaded
Open this post in threaded view
|

Re: From Lua to Python?

Dirk Laurie-2
In reply to this post by Dibyendu Majumdar
2017-07-13 22:25 GMT+02:00 Dibyendu Majumdar <[hidden email]>:

> On 13 July 2017 at 18:19, Sean Conner <[hidden email]> wrote:
>> It was thus said that the Great Dibyendu Majumdar once stated:
>>>
>>> There have been several threads here on how to grow Lua. It would be
>>> interesting to understand the driving factors behind Python's
>>> popularity and maybe some of that can be adopted in Lua. I don't
>>> really know but it seems to me:
>>
>>   To me, it's obvious---Python is an opinionated program.
>
> I see Lua as equally opinionated if not more.

In either language, the bottom line is that the language is the
way it is. Python has exactly one feature that I really miss in
Lua, which is the built-in help including the docstring. That's
why I made a effort to supply it with `ihelp.`[1]

-- Dirk

[1] luarocks install ihelp

1234