5 ms·
I find it interesting to see all of the comments on HN about the dislike of args and kwargs, especially given their necessity for higher order programming. If
by ghc 13y ago
I find it interesting to see all of the comments on HN about the dislike of args and kwargs, especially given their necessity for higher order programming.
If you are making functions that modify other functions (like decorators), these are highly useful. In Python you can't guarantee that all functions you will want to modify are going to have the same type signature, so you need to be able to gracefully handle all possible combinations and pass them on to your function body. Sometimes you'll just pass args and kwargs on to a wrapped function...other times you'll do things like pick out a single argument from kwargs and use it to do something useful. But make no mistake, in Python these come in handy to have!
- pixie_ 13y agoPersonally it feels like spaghetti code. Tornado for instance is a web server written in Python and there are classes that have many parents and kwargs is used everywhere to pass named arguments up to each parent class in the constructor. The problem is it's hard to get a grasp by looking at the constructor as to what arguments should actually be passed to a class to initialize it. There's no contract or spec enforced in python so it's easy to see how errors can crop up by missing a random argument a certain parent class is expecting. It also makes it difficult to understand what a class does when the arguments a function expects are not declared.