[Python-ideas] Change the array declaration syntax.

Arthur azrael.zila at gmail.com
Tue Feb 8 12:52:25 CET 2011


(Sorry for any spelling errors, I'm using Google translator to write this
message)

Lists and tuples are data structures dynamically typed, and that's great!
Makes writing code easier, and allows the developer to keep the focus on
more important things. However, when these structures contain large amounts
of elements, or when the program requires a lot of computational resources,
dynamic typingbecomes a waste if the lists and tuples not use it.

One way to avoid wasting resources with dynamic typing where it is
unnecessary is to use the array class.
The current syntax for creating arrays is:

>>> from array import * #necessary to create lists of single type
>>> var = array('i',[1,2,3]) #the first argument is the type and the second
is the list

This class is the solution when working with lists, but there is something
similar when working with tuples.
Thus, the variable "var" is a list, not a tuple,  even if it is declared
with with a tuple instead of a list:

>>> var = array('i',(1,2,3))
>>> var
array('i', [1, 2, 3])

I think, as well as raw strings in Python 2, lists and tuples could be
declared a "single type" using a prefix.

>>> var1 = i[1, 2, 3] # a singletype int list, as a current array
>>> var2 = i('1', '2', '3') # a singletype int tuple, as a current array,
but immutable

My suggestion is to allow the type of element in the list or tuple is
specified if the addition of a prefix before '[' or '('.
This would simplify the use of arrays and improve the performance of
programs that make use of lists of "single type". Besides creating tuples "
single type".

This seems more efficient, not wasting computing resources without polluting
 the code or make the language more complicated.

For more information about the class array, the address of the documentation
is http://docs.python.org/library/array.html .

Thank You and Goodbye!
Sig: Arthur Julião
--------------------------------------------------
----------------------------------------------
"Quero que a estrada venha sempre até você e que o vento esteja sempre a seu
favor, quero que haja sempre uma cerveja em sua mão e que esteja ao seu lado
seu grande amor." (Tempo Ruim - A Arte do Insulto - Matanza)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110208/ffd68f76/attachment.html>


More information about the Python-ideas mailing list