DEV Community

Juha-Matti Santala
Juha-Matti Santala

Posted on

Is my code self-documenting?

So you know how some people say that "Good code documents itself"?

Is this what they meant?

def self_documenting_sum(a, b):
    with open(__file__, 'r') as source:
        data ='\n')

    with open(__file__, 'w') as source:
        if not data[1].startswith('    "'):
            documentation = '    """Sums up two integers"""'
            new_source = data[:]
            new_source.insert(1, documentation)
    return a + b

Enter fullscreen mode Exit fullscreen mode

(It's a Python script that adds docstring to its only function on the first run.)

edit: I expanded on the idea a bit in hamatti/self-documenting-code

Top comments (0)