Greg Ewing <greg.ewing <at> canterbury.ac.nz> writes: > Giovanni Bajo wrote: > > > Another (similar) way would be to let the user pay for the high typechecking > > price in normal cases *but* provide a list[int] class, which is a list > > decorated with typechecks on modification operations. We could have > > list[int|float]() to construct a list which can hold either ints or floats. > > This is worth thinking about. Recently when pondering the > question of when it would or would not be appropriate to > put in type assertions to help catch bugs, I concluded > that it makes the most sense to do so when building a > data structure, but not when just passing things around > between calls.
This makes total sense to me. You don't check the type of each entry of the list - you check the type of the list itself. This is pretty much the way statically typed languages work. This means that you can't pass a regular list to a function that expects a "list of ints". So its an extra step to convert the list to the proper type. As long as the syntax isn't too hard to type, that shouldn't be a problem, and this way the user knows that they are paying the cost for the conversion. "Explicit is better than implicit". -- Talin _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com