Abstract
As you start to write more complex programs and deal with larger data sets, you will encounter more edge cases. Examples of this include missing data, data that is not in the type that you expected, or difficulty converting between various formats required by external APIs. Many of these errors cannot be detected until runtime (in part due to Python’s dynamic typing but this is not entirely to blame).
Electronic Supplementary Material The online version of this chapter (https://doi.org/10.1007/978-3-030-36826-5_12) contains supplementary material, which is available to authorized users.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
One common approach to this would be to add a randomizer argument to your function. In your tests, you can pass a randomizer that is in fact deterministic, and thus know exactly what the behavior should be at runtime. This practice is known as “dependency injection” and is frequently a useful strategy for making code more testable.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2020 Springer Nature Switzerland AG
About this chapter
Cite this chapter
Cutler, J., Dickenson, M. (2020). Practical Programming. In: Computational Frameworks for Political and Social Research with Python. Textbooks on Political Analysis. Springer, Cham. https://doi.org/10.1007/978-3-030-36826-5_12
Download citation
DOI: https://doi.org/10.1007/978-3-030-36826-5_12
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-36825-8
Online ISBN: 978-3-030-36826-5
eBook Packages: Mathematics and StatisticsMathematics and Statistics (R0)