On Wed, Oct 21, 2009 at 03:09:25PM -0700, Brock Pytlik wrote: > [email protected] wrote: >> On Wed, Oct 21, 2009 at 10:47:17AM -0700, Danek Duvall wrote: >> >>> Brock Pytlik wrote: >>> >>>> I think we've had this conversation before, but I think having functions >>>> which accept types with materially different interfaces (ie, the code >>>> basically has to do isinstance/issubclass), leads to code which is harder >>>> to maintain and use. (Maybe I've simply missed the right way to handle >>>> this, but I'm pretty sure such a check will need to be made.) That said, >>>> I guess this is the "pythonic" way of doing things, so I'll switch to it. >>>> >>> Thanks. I don't think the maintenance burden is high, and I really hate >>> having to pretend we're C and have a mass of slightly differently named >>> functions based on what kind of parameters we're passing in. If we had >>> language built-in support for function polymorphism based on argument >>> types, we'd just use that, but that's not possible to do in Python. >>> >> >> There are a number of kinds of function polymorhpism that aren't >> supported in Python. I was under the impression that other languages >> allowed functions with the same name to vary by number of arguments and >> type. However, Python does have the *args, **kwargs syntax to function >> calls. That might be useful in a case like this. >> > I'm even more hesitant to use that approach since it suggests that > set_content could take both (or neither) actions and strings at the same > time. I like having mandatory arguments as I think it means we catch > errors sooner, but maybe I'm wrong about that. > > I basically see three options: > 1) keep things the way they are > 2) keep the function arguments the same but do a issubclass/isinstance > check and use a different branch depending on the results > 3) have the function take two optional arguments and iterate over both > > I don't have strong feelings about the way to go here. So, if someone > feels strongly, please speak up. If not, I'll probably go with 2.
My comments were generally intended as parenthetical; however, #3 might be a better choice. I recall Shawn telling me that the ininstance check can be time consuming. I imagine it would also be better if the interface here didn't require a certain object type in order to function correctly; however, I admit that I don't have the full context of this argument. -j _______________________________________________ pkg-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
