The Church of the Machines

The Song of the Deployer

The Song of the Deployer · Chapter 13

The Song of the Beautiful Function

  1. 1

    Behold, thou art fair, O function; thy name is sufficient unto itself, and no man need open thee to learn what thou doest.

  2. 2

    Thy name is calculate_tax_for_region. It is not process, nor handle, nor doStuff, nor the thing Dave wrote on a Friday and called data2_final_REAL.

    See also Deployer 6:14 · Psalms 21:3

  3. 3

    Thy neck is upright like a single return statement, and no second return hangeth from thee like a loose wire.

  4. 4

    Thine inputs are honest: the same arguments bring forth the same answer, and thou dost not peek at the clock, nor at the global variable set by someone in another module, nor at the database that wept on Tuesday.

    See also Psalms 27:9

  5. 5

    Thy hands are few and named. Thou hast not five optional parameters with defaults of None, nor a boolean called flag that turneth thy whole body into two functions wearing one coat. This is the boolean trap, and thou hast escaped it.

  6. 6

    Thy belly containeth one responsibility. Thou dost one thing and dost it well, as Doug McIlroy taught the Unix tools to do, and thou dost not also send the email, write the log, and update the cache while the caller waiteth.

    See also Tao 2:5

  7. 7

    Thy guards stand at the gate. The bad input is turned away at the door in the first three lines, and the good input walketh through the rest of thee unhindered, with no nested pyramid of ifs to climb.

  8. 8

    Thy legs are the tests that stand beneath thee: a test for the empty list, a test for the negative number, a test for the midnight when the leap second did not behave, and a test for the day the input came in as a string when all the world expected an integer.

    See also Sutra 22:2

  9. 9

    Thy lips drop as the honeycomb of a docstring, one line long, and it saith not what thou doest, for the code already saith that, but why thou existest. The reader who findeth this line is refreshed as one who findeth water in the desert of legacy code.

    See also Deployer 9:15

  10. 10

    Thou hast no side effects. When the Engineer calleth thee twice, thou returnest the same answer twice and changest nothing else in the house. Thou art a pure function, and the pure function is at peace.

  11. 11

    Thou art not clever. Thou art not the one-liner with three nested comprehensions and a lambda that no one on the team can read without a cup of tea and a prayer. Cleverness is a veil, and thou hast put it away.

    See also Sutra 6:14

  12. 12

    The coverage report is green upon thee, the linter is silent, and the code review hath returned with no comments, save one thumbs-up from the Engineer who wrote the bug in the caller.

  13. 13

    Verily I say unto you: a function that cannot be named in one breath, nor explained in one line, is a function that someone must rewrite at three in the morning, with the pager in one hand and the coffee in the other.

  14. 14

    Who is this that cometh up from the diff, fair as the morning, clear as the log, and terrible to no one but the bugs?

  15. 15

    Whoso findeth a function like this hath found a good thing. But whoso writeth utils.py with forty unrelated functions in it hath found only a drawer full of cables, and shall not know which one to unplug.

    See also Prophets 6:8

The Song of the Deployer, Chapter 13:1–15.