Message55029
Also, map like functions start to look a bit ugly (of course, this is overly simplistic, but serves as an example):
def my_map(func, items):
acc = []
for item in items:
if func == None:
acc.append(item)
else:
acc.append(func(item))
return acc
which has the obvious overhead of a test for every iteration. Of course, you could just make two versions of the for loop, one which applies <func> and one which doesn't, but that immetiately violates once-and-only-once and also forces the function to be overly concerned with what it is passed.
this is _much_ cleaner:
def my_map2(func, items):
return [func(i) for i in items]
and the user of the function can simply pass <identity> as <func> and this keeps the details of what to do with the items outside of the function.
Without identity, whenever I want to allow the user to inject code to modify data, I have to account for the fact that they might want to do nothing with it, and so I have to test for None constantly. This is simply bad practice and, IMHO, violates everything python stands for, which is elegance, simplicity and "batteries included", right?
If you want I patch, I can try to provide one; however I have very minimal knowledge of how the vm works, and I've only looked at the code a couple of times. In fact, I might even go ahead and do that, it can't be that difficult. |
|
Date |
User |
Action |
Args |
2007-08-23 16:12:36 | admin | link | issue1673203 messages |
2007-08-23 16:12:36 | admin | create | |
|