[IronPython] No automatic conversion anymore from list to array
Jacques de Hooge
jdehooge at fugro-jason.com
Thu Aug 3 09:04:45 PDT 2006
Hi,
I've been moving my apps from IP 1 Beta 7 to IP 1 RC1.
I have not tested them completely, but I ran into the fact that automatic
conversion from list to array was removed.
If I remember right, the reason is that a C# function receiving an array
param may alter it.
If a tuple is passed rather than an array, the user would not expect the
tuple to be altered.
- Is there a fundamental reason why the function could not update the
contents of the list offered to it?
- If not, couldn't some kind of optional ('strict' option) warning be
generated rather than prohibiting automatic conversion?
- Are you sure most Python programmers know enough about Python "passing
references by value" to be aware that the function could not replace the
tuple by a new instance (I tought some Python courses and my students,
originally coming from C++, are always baffled by that, even after multiple
years of Python experience)?
One of the places where I use automatic conversion is:
listViewItemsBuffer = []
for ... :
listViewItemsBuffer.append (listViewItem)
listViewItems.AddRange (listViewItemsBuffer)
The alternatives are:
1. listViewItems.AddRange (tuple (listViewItemsBuffer))
Will probably create a third, redundant, copy of the long list of pointers
involved each time its called
2. listViewItems.AddRange (System.Array [Forms.ListViewItem]
(listViewItemsBuffer))
Verbose (One of the things about Python programs is that they are much
shorter than their C# equivalents)
Well I guess you guys will have discussed this extensively.
Still I'd like to share the above thoughts with you.
Kind regards
J. de Hooge
info at geatec.com
More information about the users
mailing list