On Fri, Nov 1, 2019 at 12:42 AM DL Neil via Python-list <python-list@python.org> wrote: > > Is the practice of TDD fundamentally, if not philosophically, somewhat > contrary to Python's EAFP approach? >
[...] > > In encouraging my mind to think about testing the code, I find myself > searching for edge-cases, and attempting to anticipate the unusual. > Accordingly to the gospel of TDD: so far, so good. > > The 'problem' is, that it puts my mind onto LBYL-rails before the > Python-coding train (of thought) has even left the station. It then > seems natural to start putting a bunch of if-then-else's up-front and > before the 'main line' of code. > > Does TDD bend your mind in this (apparently) non-Pythonic fashion? > Have you developed an answer? > (other than: "@dn is 'nuts'*", which is not worthy of debate) As the pros have yet to chime in, I will attempt to add my amateurish thoughts. In my on again/off again efforts to self-study Python, sound software construction practices, etc., I have been endeavoring to adopt a TDD approach. I find that trying to do this forces upon me more clarity of thought which (hopefully) results in more expressive, simpler and understandable code. As I often find my initial efforts at writing tests murky and hard to understand, I (eventually) realize that the associated code I'm trying to test, which seemed so clear when I first wrote it, is hard to test. So I refactor/simplify the code, it becomes easier to write sensible test code, etc. It may just be me and my lack of experience, but I find this circular process ultimately leads to more Pythonic results -- easier to understand code that (I hope) others can easily read and understand. Though I am sure I am stating the obvious, instead of just thinking about edge cases, I like to have at least one test that proves that what I normally expect to get is, in fact, gotten. I often embarrassingly find myself caught in some sort of simple logic error that this type of test will catch, especially later if I am refactoring my code in the direction I am trying to coerce it to go for the end product. I am probably far from thinking/coding in a proper Pythonic fashion, but the TDD back-and-forth process seems to get me closer to being Pythonic. -- boB -- https://mail.python.org/mailman/listinfo/python-list