attish/heapkeeper — comment on commit 6b548ddf5161f2302f6a947dbb614fe3496f839e
File:  line 0
By hcs42:

Yes, there is no problem with that if you make the code more testable, maintainable, readable.

Advocates of test driven development usually say that a great benefit of TDD is that the architecture and design of your code will be better, because you will keep easy testability in mind, and that correlates with maintainability and readability.

Now we just modify the code to look like the code that we would have written in the first place, had we used TDD.

_A little elaboration about the concrete case:_

For example a code where 90% of the code is pure functions (which means that they give the same output to the same input regardless of global variables and other implicit parameters, and don't have side effects) and 10% uses these functions and takes the impicit parameters into account and calls them others accordingly is more testable, maintainable and readable than if all the functions used the implicit parameters.

We did not use TDD for get_web_args, and although it could easily be a pure function (it basically parses the query items), it is not: it reads its input from the impicit parameter webpy.input().items(). When I saw your tests, I had a feeling that it should be made a pure function, but then all the callers should call webpy.input().items() first and pass its result to get_web_args. The problem with that is that the best place for this knowledge (that webpy.input().items() is usually the query list we want to parse) is get_web_args itself. So I suggested to make it an almost pure function as a compromise: if query_items is not None, then works as a pure function, otherwise not.

ps. I noticed some errors in my get_web_args suggestion, so I changed it.