← Back to team overview

maas-devel team mailing list archive

Re: The Clean Architecture in Python

 

On 2 September 2015 at 19:45, Mike Pontillo wrote:
> Hi all,
>
>    This morning, while reflecting on how the MAAS team could write
> easier-to-maintain code (and thus increase our velocity), LaMont
> pointed me to a great talk about writing clean code in Python.
> Especially since we have some new MAAS hackers getting up to speed, I
> thought it would be helpful for the entire team to have a look:
>
> https://www.youtube.com/watch?v=DJtef410XaM

This was worthwhile, thanks.

It reminded me of two things that have had probably the most influence
over the way I code:

  * David Beazley's trilogy of talks, but the first two especially:

    * Generator Tricks for Systems Programmers
      http://www.dabeaz.com/generators/

    * A Curious Course on Coroutines and Concurrency
      http://www.dabeaz.com/coroutines/

    * Generators: The Final Frontier
      http://www.dabeaz.com/finalgenerator/

  * Learning Haskell.

The Generator/Coroutine trilogy resonates with the moral from the
Knuth/McIlroy story in the clean-code talk, i.e. learn to create small
tools — here they're functions — to do one thing well.

Smaller functions like these are readily testable, easy to reason about,
and can be composed to create complex behaviours. The complex behaviours
are also far easier to debug because the intermediate states are right
there to look at.

Generators are the distillation of this in Python. The talk encourages
us to put "ugly IO" at the top instead of burying it away, then we can
write many clean & fast unit tests for the purer functions, and a few
slower integration tests for the IO functions. Yet generators are all
about IO, and they're clean, and can be tested with plain data just as
well as with ugly IO.

You'll find lots of generators and generator expressions in MAAS, most
directly influenced by that trilogy of talks.

Learning Haskell a few years ago was enlightening, though I am not (thus
far) coding with it regularly. The talk mentions functional languages
and there aren't many/any more seriously functional than Haskell.
Spending time with Haskell has forever rewired my thinking with regards
to IO.

Gavin.


References