I would like to propose an addition to the Python programming language. I think there needs to be a change to arrays. Since the way they are created is confusing enough, the fact that they are not dynamic puts the icing on the cake. Sure, you can get around this fact by allocating the array an insane size, but that is wasteful and unsatisfying. Adding the ability to make dynamic arrays, while maintaining static arrays will make the Python Programmers life better.

            All types of programs can use dynamic arrays. Any time you might want to add an extra element, or possibly remove one, a dynamic array would be handy. For instance, if you make a game that has data that you would like to access, associated with each year, as the game progresses, a dynamic array would be useful. You could store the data for each year in an element, which isn’t a problem in Python now, as long as you know exactly how many years the game will run. Or you could just allocate a huge blank array and set the values as the game progresses. But that could be wasteful, or what happens if a user happens to take more time to complete the game then you planned? In a case like the later, the program could not be done properly without dynamic arrays. This is why Python should have dynamic arrays. A change like this would cause minimal negative impact.

            The only way I could see dynamic arrays cause a problem is if a programmer were to use them when they are completely unnecessary. A good example of this would be in programming physics. If a programmer were to use dynamic arrays for vectors, and accidentally change the number of elements in one array, they would no longer be able to perform certain actions like adding vectors. This is highly unlikely as long as programmers only use the dynamic feature when necessary. Other languages use dynamic arrays all the time, so why shouldn’t Python?

            Here is an example of a large static array in Python:

 

from Numeric import *

my_array = zeros(10000, Int)

 

            This produces an empty array of type Int that can store up to 10000 elements. Now, an easy way to implement dynamic arrays would be to use a key word DYNAMIC like so:

 

from Numeric import *

my_array = zeros(DYNAMIC, Int)

 

            Syntax would be identical to the previous example except instead of having to specify an array length you just specify that you would like the array to be Dynamic. You could then access any element in the array at any position just like you would if you had specified a length. It is obvious that a Python programmer would easily learn the new feature, and it could be useful quite often. As far as performance goes I think there would be little change, but efficiency would increase. Just because memory is cheap, why waste it? Dynamic arrays would work in any language that uses arrays. Also, if this addition were done as I suggest all previous Python code would retain its integrity.