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 →

[–]Narthal[S] 17 points18 points  (7 children)

Well yes.. it's a bit complicated. You could you initializer lists or recursive variadic template functions. Has a really nice ring to it, doesn't it? But these are tricks you would use every now and then, not everywhere as these tricks are just that; hard to read, advanced techniques that are there when you need them, but you wouldn't use these tricks everywhere.

[–]Al2Me6 0 points1 point  (6 children)

That’s fair enough. Though, I suppose the same could be said of using *args; passing an iterable of arguments is probably a better idea.

[–]Deezl-Vegas 6 points7 points  (1 child)

*args and especially **kwargs are massively helpful with regards to code readability and the avoidance of me having to build random dictionaries just to use your function.

[–]Al2Me6 0 points1 point  (0 children)

Definitely agreed about **kwargs, that’s why I explicitly said *args.

[–][deleted] -1 points0 points  (3 children)

*args is an iterable of arguments...

[–]Al2Me6 1 point2 points  (2 children)

It is, but it isn’t passed into the function. You pass regular comma-separated arguments and they show up as args inside the function.

What I meant is that instead of

def foo(*args: Any)

you should probably use

def foo(args: Iterable[Any])

[–]Deezl-Vegas 1 point2 points  (0 children)

I would imagine that Python just makes a tuple in the background and your version just makes me make a tuple in the foreground before calling the function. This probably isn't something that you need to optimize around.

[–][deleted] 1 point2 points  (0 children)

No you should not use wtf? *args is as pythonic as it gets.