3 ms·
> EDIT: Plus your observation that you rarely use default values is probably for a good reason: they don't really work. Maybe if they worked, you'd use them? H
by mhurron 13y ago
> EDIT: Plus your observation that you rarely use default values is probably for a good reason: they don't really work. Maybe if they worked, you'd use them?
Honestly, no, it's probably because I don't write methods to be generic enough.
Ignoring that,
>argument that "this is how python does it" is not a very good one
Except that if you're writing Python you have to work by Pythons rules, so yes it is.
> The reason for having the default value on a function in the first place is to allow me to make functions work with a default value
Then in python, make sure you are using datatypes that are passed by value, not by reference. That is the core of the problem and it bites everyone at some point in every language because the rules of passing by reference or value are different in a great number of languages.
def foo(name=[]):
In python, is not saying if I didn't pass something make name an empty list, it says 'if name is not defined in this scope, create an empty list.' But with Pythons rules a name[] was created in that scope when the function was defined. It was the programmers mistake for assuming otherwise.
Once again, we are writing Python here, Pythons rules are the only ones that matter. If you are getting unexpected results because you're not following the rules, the issue is yours. Python is not called C#, or Java, or C or Ruby or whatever because it is not C# or Java or whatever.