python: unintentionally modifying parameters passed into a function

前端 未结 4 890
死守一世寂寞
死守一世寂寞 2021-02-04 10:05

A few times I accidentally modified the input to a function. Since Python has no constant references, I\'m wondering what coding techniques might help me avoid making this mista

4条回答
  •  感动是毒
    2021-02-04 10:56

    There is a best practice for this, in Python, and is called unit testing.

    The main point here is that dynamic languages allows for much rapid development even with full unit tests; and unit tests are a much tougher safety net than static typing.
    As writes Martin Fowler:

    The general argument for static types is that it catches bugs that are otherwise hard to find. But I discovered that in the presence of SelfTestingCode, most bugs that static types would have were found just as easily by the tests.

提交回复
热议问题