Python optional args - great for evolving source code
Optional args are not part of the Haskell Way. I have about 20 calls to this function:
def archive_zip(my):
for f in path(my.zip).files('*'):
f.move(my.archive)
but then I needed to do the same thing but I needed to prepend the date to the file for one particular invocation of this. So, in Python, I simply tacked on an optional argument and used a default value which led to the behavior that the oroginal 20 calls to this function would expect and then I added some code to handle prepending of date:
def archive_zip(my, prepend_date=False):
for f in path(my.zip).files('*'):
f.move(my.archive)
if prepend_date:
today = datetime.date.today()
s = today.strftime("%b-%d-%y")
newfile = "%s-%s" % (s, f)
syscmd = "cd %s; mv %s %s" % (my.archive, f, newfile)
print syscmd
os.system(syscmd)
Now, I'm not sure how quickly I could evolve this function in Haskell, but I'm dead curious to know.
- metaperl's blog
- Login to post comments
Oleg (who else?) has Haskell code to do keyword arguments at his site. YMMV, of course.