On 2019-11-04 07:41:32 +1300, DL Neil via Python-list wrote: > On 3/11/19 6:30 AM, Bev In TX wrote: > > > On Nov 1, 2019, at 12:40 AM, DL Neil via Python-list > > > <python-list@python.org <mailto:python-list@python.org>> wrote: > > > > > > Is the practice of TDD fundamentally, if not philosophically, > > > somewhat contrary to Python's EAFP approach? > > > I’m not an expert on either TDD or Python, but as no one else has > > responded, I’ll put in my 2 cents worth... > > You are mixing paradigms. TDD is about testing code, regardless of the > > style in which it was written. > > Agreed: (in theory) TDD is independent of language or style. However, I'm > wondering if (in practice) it creates a mode of thinking that pushes one > into an EAFP way of thinking?
This is exactly the opposite of what you proposed in your first mail, and I think it is closer to the truth: 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 Which just means that we don't have enough test cases yet. But the point is that a test suite can only check a finite (and usually rather small) number of cases, while most interesting programs accept a very large (if not really infinite) number of inputs, so the test suite will always be incomplete. At some point you will have to decide thet the test suite is good enough and ship the code - and hope that the customer will forgive you if you have (inevitably) forgotten an important case. There is very little emphasis in TDD on verifying that the code is correct - only that it passes the tests. hp [1] Harry J.W. Percival, Test-Driven Development with Python, O'Reilly, 2017 -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | h...@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list