I know that there are a lot of large, professional-level Python projects out there. But, in terms of number of applications, most Python code is simple stuff, often written by beginners. For that purpose it is sort of the Arduino for programming in that it's easy to learn and there are a huge number of easy to use libraries available that do all the hard work. Is it possible that all of those hobbyists are being counted when it's said that Python is the most popular?
Of course, the fact that the code is often platform independent (without the need for recompiling) helps a lot.
I was not amused.
Clearly the designers went off the rails when they decided that going around in either direction was a good idea. That seems to defeat the purpose of a round about.
I think the same for a college level.
In the other side, for children from kindergarten to high school, the best language invented so far is Scratch. Developed by the MIT Media Lab's Lifelong Kindergarten group (LLK) and based on Google's blockly.
https://scratch.mit.edu/projects/editor/
IMHO Python is one of the easiest languages for casual programmers and for beginners. I'm not only talking about the language syntax, but being also interpreted is a plus for a newbie. What other language will any use at school? Bash ? Perl ? Java ? C++ ? Maybe Lua is the only contender in such category. In some way Python is the new Basic.
One nice thing about Python in a teaching environment is that it has pretty good support for most programming paradigms. It can be a common thread from scripts to procedural, to OO, to functional programming concepts and can be a comfortable home from beginner to expert. It's also an 'easy' entry point to more high-level concepts like AI/ML, data processing, etc. When I went to college, a lot of time was spent teaching Scheme or Java or whatever else I've now forgotten about just to have an environment to explore a fundamental concept, which wastes at least half the semester on 'boilerplate'. There are other languages that have this property, but Python was one of the first to do it well, and as a popular language is a marketable skill for schools to teach in its own right, though the primary goal of a computer science education is not to teach languages. Alongside C/C++ for data structures and systems, it's all you need.
Lua is currently ranked number 19 in popularity according to TIOBE, which is not bad at all.
Being so light is also a big advantage. But that itself is a disadvantage by not providing even a minimal standard library.
And what about array limits?
This Lua code:
array = {"Hello", "world"}
for i = 1, 5 do
print(array[i])
end
returns:
Hello
world
nil
nil
nil
I don't think this is a good example for an introductory programming course.
It's better than a seg fault.
Yes, but worst than Python return.
array = ['Hello', 'world']
for i in range(5):
print(array[i])
Return:
Hello
world
Traceback (most recent call last):
File "<pyshell#6>", line 2, in <module>
print(array[i])
IndexError: list index out of range
But, if you want a null return, is very easy to achieve:
array = ['Hello', 'world']
for i in range(5):
try:
print(array[i])
except:
print(None)
Return:
Hello
world
None
None
None
Clearly the designers went off the rails when they decided that going around in either direction was a good idea. That seems to defeat the purpose of a round about.
If road designers are blatantly confusing drivers, they look bad. So, they find roundabout ways to achieve the same goal.
Picuino, can you elaborate on what's the problem?
And, Lua doesn't have "arrays" in fact. It only has tables, which are collections of key-value pairs. Tables can loosely act as arrays if they only contain items without an associated key, in which case they get assigned a numeric index. But they still operate as tables.
Accessing an item that doesn't exist in a table yields 'nil', which basically means an object that doesn't exist. Seems consistent to me. Actually, this model looks more sane to me for beginners than the low-level, C-like arrays, which you always can learn about later on once your have your bases covered.
Lua has metatables too, so you can override the indexing function for a given table, and do some fun (or interesting) stuff. You can for instance define tables that will not return 'nil' when accessing an item that doesn't exist, but will do something else entirely. Pretty powerful.
Oh, and otherwise, you have iterators, so you can access tables in a more elegant way than directly indexing them.
Picuino, can you elaborate on what's the problem?
Not much, really.
They are two equally valid points of view.
I see it from the point of view of teaching how important it is not to exceed the limits of an array. The array is the structure most used by other lower level languages that any programmer will later have to learn. Dictionaries (tables) are a different concept and Python distinguishes them well, which for me is an advantage when teaching the different types of data that exist.
Oh, and otherwise, you have iterators, so you can access tables in a more elegant way than directly indexing them.
Both Lua and Python, but this way you can't get out of the array.
About Lua: I'm surprised it doesn't get that much traction nowadays. I like it far better compared to Python and it is very easy to integrate Lua in applications in order to add scripting.
About Lua: I'm surprised it doesn't get that much traction nowadays. I like it far better compared to Python and it is very easy to integrate Lua in applications in order to add scripting.
Lua certainly shines for scripting. Its such a lightweight add on.
About Lua: I'm surprised it doesn't get that much traction nowadays. I like it far better compared to Python and it is very easy to integrate Lua in applications in order to add scripting.
It's pretty easy to integrate in applications indeed, and the bonus is that you can allocate several instances of the Lua interpreter in the same app, whereas I'm not even sure this is possible with Python.
But popularity? Again a complex and intricate matter. Lua comes from a uni in Brazil, and I have no doubt they teach Lua over there.
Picuino, can you elaborate on what's the problem?
Not much, really.
They are two equally valid points of view.
I see it from the point of view of teaching how important it is not to exceed the limits of an array. The array is the structure most used by other lower level languages that any programmer will later have to learn. Dictionaries (tables) are a different concept and Python distinguishes them well, which for me is an advantage when teaching the different types of data that exist.
That is debatable to no end. I quite like the unified data collection type in Lua, with which again you can actually implement any data structure you like. This is not restrictive.
Whether accessing an non-existing item returns nil or causes an exception/crash is not a sign of a good implementation per se or what should really be done.
Generalizing data collection is not a bad thing IMO. Beginners certainly do not need to make a difference. What matters is whether the data collection is ordered or not, and this is the key point. Key-value pairs in Lua tables are NOT ordered, but keyless values are assigned a numeric, increasing index, and are ordered. This is really all you need to know. The rest is pretty low-level, and if/when you need to learn about more low-level structures, you can do that later. I'm not sure starting with them is that good of an idea.
Note that print() in Lua will print 'nil' for nil values, but using nil values in arithmetic/string/whatever operation will usually yield an exception too. So if there is an invalid item access, you'll get an exception at some point, unless you explicitely deal with that in the code.
Now you can implement "arrays" that would act as you expect, using metatables. That'd actually be an interesting first exercise for learning about metatables.
function NewArray(A)
A = A or {}
return setmetatable(A, { __index = function (Table, Key) error("Out of Bounds!", 2) end })
end
A = NewArray({"Hello", "world"})
for i = 1, 5 do
print(A[i])
end
About Lua: I'm surprised it doesn't get that much traction nowadays. I like it far better compared to Python and it is very easy to integrate Lua in applications in order to add scripting.
It's pretty easy to integrate in applications indeed, and the bonus is that you can allocate several instances of the Lua interpreter in the same app, whereas I'm not even sure this is possible with Python.
I've seen Lua scripting being used in things like VoIP server applications, where every call has a Lua script running. So, it seems to do a good job when you have a quite a large number of concurrent instances.
The only reason that I have ever even heard of Lua is because it's the scripting language used in FEMM. I leaarned to use it to get some work done. To that end, I found it easy to learn and capable enough to do what I needed to do. I have always had the vague impression that that sort of thing is exactly what Lua was designed for.
How is comparing Lua to Python to C at all productive without context? I think Picuino is supplying his context when he talks about using Python as a learning tool. I can easily see how it would be well suited for teaching programming concepts without getting distracted by programming details. OTOH, a large fraction of my coding time is spent writing firmware for microcontrollers. There C seems a much more natural fit. Both C and Python win!!!
Yes, but worst than Python return.
array = ['Hello', 'world']
for i in range(5):
print(array[i])
Return:
Hello
world
Traceback (most recent call last):
File "<pyshell#6>", line 2, in <module>
print(array[i])
IndexError: list index out of range
Cause this isn't the pythonic way.
array = ['Hello', 'world']
for x in array:
print(x)
See how much easier it is? If you really really need the index, you enumearte it.
One possible enumerated version in Python being
array = [ 'hello', 'world' ]
for x in range(len(array)):
print("array[{key}] = '{value}'".format(key=x, value=array[x]))
which outputs
array[0] = 'hello' array[1] = 'world'As to Lua, I still need to experiment more with
LGI and
LQT. The former provides GObject introspection bindings for Lua (and thus one can use e.g. Gtk+ and WebKit in Lua with that, the same way one can use them in Python); the latter provides Lua to Qt5 bindings. (I'm not interested in microbenchmarking, though. What matters to me, is finding out any drawbacks and downsides; the types of situations or problems they have performance or other issues with.)
I do love how embeddable Lua is to an application, but I do have some reservations and prejudices about the abstract stack model that Lua uses to exchange data with non-Lua code. For some things, such an interface works really well; I just have trouble fitting the model to streaming data and concurrent processing with Lua and non-Lua code. (I'm not saying it cannot be done, I'm only describing the limitations of my current understanding, hopefully explaining why I haven't used Lua more.)
It's as contrived as example gets, but I would
array = ['hello','world']
for index,value in enumerate(array):
print(f'array[{index}] = {value}')