Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Python or Lua - which should I use / learn?

"Should I learn and use Python or Lua" - a question to me. The questioner was perceptive, knowing that he shouldn't try to learn lots of languages at the same time, and that he should always limit the "basket" of languages used within his applications - in fact, he was wondering if he could select just a single language as his route forward.

All programming languages are different. BUT they all start from the same basic tennents ...
• A series of executable statements performed one after another
• Comment statements to allow the author to provide documentation for others coming back to the code later on
• Variables used to store information between statements
• Conditional statements or groups of statements performed only if a particular expression is true when the group (block) is reached
• Loops - blocks of statements which may be performed multiple times while a particular expression is true
• Loops and conditionals within loops and conditionals to deal with more complex cases
• Collection variables, in which you can gather a group of pieces of information under a single name.
• The ability to name blocks of code so that you can run them multiple times (with different inputs to the block too).
• Libraries of commonly used blocks of code which can be shared between programs. Many of these libraries provided with the language itself so you can easily call up common tasks such as reading keyboard or file inputs, and writing outputs.
• Storage of all of the above into disc files so you can write it once and run it may times.

The differences between the languages come in HOW they achieve the above - and how they achieve much more too. And those differences will effect what language is best for any particular task. You also need to consider:
• Licensing Issues and cost
• Knowledge of your existing team, and existing codebases
• The future availability and support of the language.

Let's look at the specifics of Lua v Python.

Lua is a small language - it has a tiny footprint which allows it to be used on almost any size of computer without grabbing a significant proportion of resources. That's fantastic news for applications such as computer gaming, where every byte and cycle can cost over thousands and (perhaps) millions of systems. But there's a sting in the tail - it's smaller because it doesn't include as many facilities and (especially) standard libraries, so that the programmer will often have to do a lot more work in writing code that a user of a larger language.

Python is a much larger language in comparison. I've been careful so say "in comparison" because it does not include the bloat that you'll find in languages like Java and Perl, leading them towards applications with yet different metrics. So in Python, you don't have to do all the low level level "roll you own" coding that you sometimes need in Lua, but that's at the price of a bigger memory footprint and somewhat slower operation ... which doesn't really matter if you're running the code on a bigger computer such as a web server, or if you're not looking for the high speed dynamic graphics expected of a game.

Both Lua and Python are open source, with good licenses that allow you to use the language free at the point of distribution. Lua has an especially open license - you can distribute it as a part of your product (the license must be included) without charge, and without making your code conform to the same open source license (i.e. it is not a "Viral" license that transfers to all code written in Lua). So - again this places Lua ideally for inclusion in games, and in other commonly and heavily distributed bits of code such as virus scanners.

When you decide to invest - and it's often a heavy investment - in writing a large code base, you'll also want to know that it will have a long life. New hardware products seem to come out every year (like new car models!), but underlying them is the same programming - or at least the same libraries. You get to realise just how important this is, and how long the life of code is, when you look at Perl, PHP and Python and their major releases - how comparability, or at least a route forward to save redevelopment, is paramount in their plans, including ongoing support for facilities that are last-millennium, pre-web. Good news - both Lua and Python have strong, and ongoing, support and because they're open source they're not as susceptible to being withdrawn as a commercial product - you aren't going to suddenly hit a wall where you can do nothing, or find yourself having to buy an expensive contract for continued support and use. I'm afraid I can't say that "Open source = never an ongoing support problem" - there are several open source languages around at the moment where new versions and facilities are commercial / much more commercial, and I see the free-to-use approach fading onto older, more limited and more difficult to use versions. I can't say "never" for Lua or Python, but I'm not worried about them - whereas I am worried about MySQL and Java.

So - back to the original question - "Should I learn Lua or Python". The questioner's involved in the writing and production of computer games, sold and supported via a web service / site. His team are already writing in Lua (for the game) and Python (using a Django framework) on the web server. Good news - from what I've been told of the game and web site, the use of two different languages seems a sensible decision in this case, and both languages are well suited to the particular use / application to which they'll be put, as described to me.

With regards to learning, I'm going to answer a question with a series of question.
"Do you want to work on the game end or the web end of the business?"
"Are you a good learner who revels in getting deep into projects and detail"
"Might you do better actually be better placed getting an overview so that you can better support your existing team of programmers?"
These are very business-specific and personal questions, and it's up to the personal answers given by the questioner to find the best answer to the original question.




I have added two comparative examples, showing a program to tackle the same simple application if Lua and Python.

[Here] is a program in Lua which reads from the keyboard, and calculates on a loop outputting the results. And [here] is the same thing programmed in Python. You'll note that even in a short program like this, the prompt-read is much shorter and cleaner in Python, but the Lua runs perfectly well.

[Here] is a program that opens and reads a file in Python, sorts the lines and outputs the sorted results. Again, it's longer in Lua - see [Here]. I was very tempted to write a more complex data analysis - in Python that would have been trivial. In Lua it would have been very practical, but I would need to spend a lot more time on a course explaining the algorithms behind it. For completeness, the data file that both these programs use may be found [Here].

We run public Python and Lua courses. Here are some links ...
Public (open) Lua classes
Public (open) Python classes
These courses run at our Melksham, Wilthshire, UK training centre where we have residential accommodation available for delegates to stay overnight during courses.

We also run private (single company) classes in both Python and Lua - either at our training centre, or on site at your facilities. You can find further details ...
Private Lua or Python courses at your own offices
Private Lua or Python courses at our training centre in Melksham
Private course can be tailored to meet you exact needs.

(written 2011-12-21, updated 2011-12-24)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Q102 - Choosing your language
  [3785] Programming languages - what are the differences between them? - (2012-06-27)
  [3764] Shell, Awk, Perl of Python? - (2012-06-14)
  [3619] Ruby v Perl - a comparison example - (2012-02-21)
  [3169] Rekeying a table - comparison in #Ruby #Perl and #Python - (2011-02-14)
  [2866] Ruby - how does it compare and where is it the right language? - (2010-07-11)
  [2700] The same very simple program in many different programming languages - (2010-03-31)
  [2536] All the Cs ... and Java too - (2009-12-13)
  [2535] When should I use Java, Perl, PHP, or Python? - (2009-12-13)
  [2507] Admission - (2009-11-19)
  [2048] Learning to program in PHP, Python, Java or Lua ... - (2009-02-19)
  [2001] I have not programmed before, and need to learn - (2009-01-19)
  [1990] Speaking all the languages - (2009-01-12)
  [76] Learning to program in - (2004-10-07)

U103 - Lua - Conditionals and loops
  [4323] Learning to program - Loop statements such as while - (2014-11-22)
  [4322] Learning to Program - the conditional statement (if) - (2014-11-21)
  [4272] Lazy operators in Lua - what they mean, and examples - (2014-05-05)
  [3686] The goto statement in Lua - (2012-04-06)
  [3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
  [2455] Lua examples - coroutines, error handling, objects, etc - (2009-10-15)
  [2454] For loops in Lua - (2009-10-14)
  [2351] Ternary operators alternatives - Perl and Lua lazy operators - (2009-08-12)
  [1738] Clean code, jump free (Example in Lua) - (2008-08-06)
  [1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
  [1685] Short circuit evaluation (lazy operator) in Lua - (2008-06-22)

U110 - Lua - Input / Output
  [2344] Reading a data file and sensing EOF in Lua - (2009-08-10)
  [1841] Formatting with a leading + / Lua and Perl - (2008-10-15)
  [1744] Lua examples, Lua Courses - (2008-08-08)

Y103 - Python - Conditionals and Loops
  [4210] If elif elif elif - multiway selection in Python - (2013-11-16)
  [4092] Identity in Python - (2013-05-17)
  [3895] Flowchart to program - learning to program with Well House - (2012-10-14)
  [3762] Learning to program - the if statement. Python. - (2012-06-12)
  [3620] Finding the total, average, minimum and maximum in a program - (2012-02-22)
  [3439] Python for loops - applying a temporary second name to the same object - (2011-09-14)
  [3200] How a for loop works Java, Perl and other languages - (2011-03-12)
  [3083] Python - fresh examples from recent courses - (2010-12-11)
  [2899] Groupsave tickets - 3 or 4 train tickets for the price of 2 - (2010-08-02)
  [2778] Learning to program in Python 2 ... and / or in Python 3 - (2010-05-24)
  [1661] Equality, sameness and identity - Python - (2008-05-31)
  [1477] Decisions - small ones, or big ones? - (2007-12-18)
  [1201] No switch in Python - (2007-05-23)
  [909] Python is like a narrowboat - (2006-10-30)
  [835] Python - when to use the in operator - (2006-08-16)
  [788] New - Conditional expressions in Python 2.5 - (2006-07-01)
  [668] Python - block insets help with documentation - (2006-04-04)
  [657] The ternary operator in Python - (2006-03-25)
  [353] Wimbledon Neck - (2005-06-20)
  [299] What - no switch or case statement? - (2005-05-03)

Y110 - Python - File Handling
  [3465] How can I do an FTP transfer in Python? - (2011-10-05)
  [3442] A demonstration of how many Python facilities work together - (2011-09-16)
  [2870] Old prices - what would the equivalent price have been in 1966? - (2010-07-14)
  [2282] Checking robots.txt from Python - (2009-07-12)
  [2011] Conversion of OSI grid references to Eastings and Northings - (2009-01-28)
  [1442] Reading a file multiple times - file pointers - (2007-11-23)
  [183] The elegance of Python - (2005-01-19)
  [114] Relative or absolute milkman - (2004-11-10)


Back to
Melksham Christmas Lights - Town, Shops and Private Houses
Previous and next
or
Horse's mouth home
Forward to
Well House Consultants - Open Source Programming Courses for 2012
Some other Articles
Christmas Day - for unique pictures
Happy Christmas ... a Christmas morning walk in Melksham
Melksham, Month by month through 2011
Well House Consultants - Open Source Programming Courses for 2012
Python or Lua - which should I use / learn?
Melksham Christmas Lights - Town, Shops and Private Houses
Aeryn at 1
Football league tables - under old and new point system. Python program.
Learning more about our web site - and learning how to learn about yours
Changes to morning routines
4316 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3558_Pyt ... earn-.html • PAGE BUILT: Thu Sep 18 15:30:25 2014 • BUILD SYSTEM: WomanWithCat