3 ms·
I'm curious about the "Don't use Booleans as parameters" point. I primarily write Python and like to use keyword arguments in these cases. So the function call
by rurp 7y ago
I'm curious about the "Don't use Booleans as parameters" point. I primarily write Python and like to use keyword arguments in these cases. So the function call would look like
get_message(full_message=True)
Is this an OK pattern for Python but not some other languages, or am I writing more confusing code than I had realized?
- ndiscussion 7y agoThat's exactly what the post is warning against. It's really hard to explain without a concrete example, but basically, I would make two functions: get_full_message and get_partial_message or something like that
- ShamelessC 7y agoIs it safe to say that using named keyword arguments mitigates this issue?
- Izkata 7y agoIf you add a safeguard to the function itself that disallows full_message as a positional arg, so no one is able to write "get_message(False)", then it's okay. The key here is the reader being able to tell at a glance what the args are/do, without needing to hunt down documentation.
- prometheus76 7y agoWell, if I'm reading that, I'm wondering what gets returned if I set that parameter to false. Does it return a summary of the message, or does it return the first word or does it return null? Using named parameters doesn't answer that question any more clearly than OP's example.