I use DbC occasionally to clarify my thoughts during a
refactoring, and then only in the places that continue to make
mistakes. In general, I am not in a domain that benefits from DbC.
Contracts are code: More code means more bugs. Declarative
contracts are succinct, but difficult to debug when wrong; I
believe this because the debugger support for contracts is poor;
There is no way to step through the logic and see the intermediate
reasoning in complex contracts. A contract is an incomplete
duplication of what the code already does: at some level of
complexity I prefer to use a duplicate independent implementation
and compare inputs/outputs.
When you are documenting a method you have the following options:
1) Write preconditions and postconditions formally and include them automatically in the documentation (e.g., by using icontract library).
2) Write precondtions and postconditions in docstring of the method as human text.
3) Write doctests in the docstring of the method.
4) Expect the user to read the actual implementation.
5) Expect the user to read the testing code.
This is again something that eludes me and I would be really thankful if you could clarify. Please consider for an example, pypackagery (https://pypackagery.readthedocs.io/en/latest/packagery.html) and the documentation of its function resolve_initial_paths:
Resolve the initial paths of the dependency graph by recursively adding
*.pyfiles beneath given directories.
Path]) – initial paths as absolute paths
list of initial files (i.e. no directories)
all(pth.is_absolute() for pth in initial_paths)
len(result) >= len(initial_paths) if initial_paths else result == 
all(pth.is_absolute() for pth in result)
all(pth.is_file() for pth in result)
How is this difficult to read,[...]?
Does it work on Windows?resolve_initial_path() is a piece code is better understood by looking at the callers (#7), or not exposing it publicly (#11). You can also use a different set of abstractions, to make the code easier to read:
What is_absolute()? is "file:///" absolute?
How does this code fail?
What does a permission access problem look like?
Can initial_paths can be None?
Can initial_paths be files? directories?
What are the side effects?