Quote:
Originally Posted by jmakin
Instead of 50 flags as params cant you just make them one integer that gets OR’d with whatever you need?
So first of all, those aren't all flags. It would be like
do_some_query(user_id=2, page=1, limit=20, sort='username', include_count=True)
and so forth. do_some_query will probably take a half dozen argument that can be used to limit the results, like say user_id, username, email, etc. All query functions take at least the page/limit/sort/include_count params so it's really easy for functions to have more than 7 args.
Also I would say that if I was really just taking a bunch of flags, using distinct params is still better because the function prototype is self-documenting.
Code:
def foo(include_email=False, include_username=True):
pass
both tells you what parameters are available and what the defaults are. If they instead took flags, you'd have to look deeper into the code or somewhere else that the constants are defined. That kind of thing makes a lot more sense in languages that don't support named parameters, like C.