Friday finking: TDD and EAFP

Mark Turner mturner865 at gmail.com
Mon Nov 18 19:00:41 EST 2019



> On Nov 18, 2019, at 4:07 PM, Peter J. Holzer <hjp-python at hjp.at> wrote:
> 
> On 2019-11-13 15:16:55 +1300, DL Neil via Python-list wrote:
>> On 4/11/19 9:44 AM, Peter J. Holzer wrote:
>>> TDD does in my opinion encourage EAFP thinking.
>>> 
>>> The TDD is usually:
>>> 
>>>     1 Write a test
>>>     2 Write the minimal amount of code that makes the test pass
>>>     3 If you think you have covered the whole spec, stop, else repeat
>>>       from 1
>>> 
>>> This is often (e.g. in [1]) exaggerated for pedagogic and humoristic
>>> reasons. For example, your first test for a sqrt function might be
>>>     assert(sqrt(4) == 2)
>>> and then of course the minimal implementation is
>>>     def sqrt(x):
>>>         return 2
>> 

I think this simple test like has value. It’s just not where you expect it to be. In order to get this test to pass you have to have your development environment set up, your testing environment set up and perhaps some basic dependencies resolved. If this test doesn’t pass then it’s not the code that needs debugging, it’s the environment. Later on, after this module of code is finished, if a lot of tests start failing for some reason and this simple test is one of them, then a good place to start debugging is the environment.

 - Mark


More information about the Python-list mailing list