I don't think I'd heard of CQS before. I'll have to think more about it. It does make the code clear in this case.
On first examination, one issue I have with the general concept is that it seems that functions that act like constructors, such as file_or_stdout() in my example, or even just output = open(...) would violate it because they both do something (e.g. open the file, build a context manager) and return a reference to the thing they've opened or created.
CQS seems similar to a rule of thumb that parameters are for input and return values are for output, which I'm violating with do_something(), because it was a stand-in for a couple lines in the original code.
Maybe the larger takeaway of this exercise is that mutability has its pitfalls.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I don't think I'd heard of CQS before. I'll have to think more about it. It does make the code clear in this case.
On first examination, one issue I have with the general concept is that it seems that functions that act like constructors, such as
file_or_stdout()
in my example, or even justoutput = open(...)
would violate it because they both do something (e.g. open the file, build a context manager) and return a reference to the thing they've opened or created.CQS seems similar to a rule of thumb that parameters are for input and return values are for output, which I'm violating with
do_something()
, because it was a stand-in for a couple lines in the original code.Maybe the larger takeaway of this exercise is that mutability has its pitfalls.