Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
empty arguments
#11
I'm not against increasing the performance of code when it makes sense. But I suspect a decorator is a better solution than a hack with default arguments.
Reply
#12
(Apr-28-2017, 06:07 AM)micseydel Wrote: I'm not against increasing the performance of code when it makes sense. But I suspect a decorator is a better solution than a hack with default arguments.
You would be very surprised, but the hack in question was implemented in the internal function of 2-layered decorator. Decorated functions had to be able to share cache - that why I couldn't use closure. And class decorator did not work for some reason - I don't remember why.

I am not overfond of hacks - they may be a major pain in the ass, especially when those are not documented (I've seen one or two, well - some people strive for job security Angry ). That's why my function had more line of comments than lines of actual code.

On the other hand - if BDFL in his "for-life" wisdom Pray made that loophole in the language, probably he saw a reason for that.
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#13
When I've wanted caching, I just used a decorator. Using something that might be an implementation detail feels susfishous to me.
Do lists in function arguments work that way in other versions of python, like pypy or ironpython? I don't have anything but cpython installed at work to test it.
Reply
#14
(May-11-2017, 04:03 PM)nilamo Wrote: When I've wanted caching, I just used a decorator.  Using something that might be an implementation detail feels susfishous to me.
Do lists in function arguments work that way in other versions of python, like pypy or ironpython?  I don't have anything but cpython installed at work to test it.

I don't know, there are some think like system limitations? Compensation for design deficiencies?! If every problem could have been solved by trivial methods Naughty .....
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#15
I can't cite anything, but I'm fairly certain that it's a language spec and not an implementation detail, so unless you find evidence that it really is implementation-specific I wouldn't cite that as a reason.
Reply
#16
Can we stop the pissing content Doh ? Just curious....
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#17
Do you mean pissing contest? I don't see that here, though I didn't realize we got off topic. If people want to continue the discussion about mutable default arguments being a hack or not, that should probably be a separate thread.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 3,819 Mar-02-2017, 10:23 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020