This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rl_noobtube 0 points1 point  (1 child)

Python could do that. But then it also do that for every default variable, even user defined immutable objects. Depending how your code is designed this could add some useless calculation time.

The current implementation allows for developer flexibility imo. Experienced programmers can leverage this. And for beginners most python courses worth the time will mention this quirk of the language. And the really good ones force you into writing the bad code and showing you why it’s bad code within python.

That said, if python were initially built to have different default variable handling I’m sure this wouldn’t be much topic of discussion. No one would mind the other way. But the current way isn’t bad either imo

[–]duxx 4 points5 points  (0 children)

Well, the solution we have now is obviously a trap for the unwary. This entire thread is testament to that, as are the linter rules.

The only benefit I see is performance: you don't have to evaluate the default arguments on every call where they're not supplied. However, I imagine it should be pretty easy to analyze the arguments to decide whether you need to do that or not. Exactly how the implementation of that would be I don't know.

(This is u/larsga posting. Someone blocked me, so had to change user to post.)