system
Given the following post, respond as if you're commenting on Reddit:
human
[Question] A single function should never do several things

I read "A single function should never do several things" advice somewhere. Let's say we have the following code below, where lower\_and\_replace function cleary does multiple things, but when coding it is useful to make such shortcuts.

    def replace(string, a, b):
        return string.replace(a, b)
    
    def lower(string):
        return string.lower()
    
    def lower_and_replace(string, a, b):
        string = lower(string)
        string = replace(string, a, b)
        return string

I think the author of that advice meant that functions shouldn't change their behavior based on parameters, eg.:

    def lower_and_replace(string, a, b, should_lower=True):
        if should_lower:
            string = lower(string)
        string = replace(string, a, b)
        return string

lower and replace are just examples. They could be any arbitrary long functions.

Is my thinking correct? What about naming conventions?
gpt
I do think that's a good example why a function should not do several things (though there are of course exceptions).

It's easier and shorter to do

`replace(lower(inputstring),a,b)`

Than it is to do

`lower_and_replace(inputstring,a,b)`