Hey everyone! I'm trying to wrap my head around programming in dynamically typed languages. While I've come across a lot of discussions about static vs dynamic typing, I'm more curious about how to effectively test code in a dynamic environment. I've read some views from Martin Fowler and Robert Martin suggesting that with proper testing, types might become less significant for reliability. I get how to write tests, but I struggle with what that looks like, especially for more complex structures. For instance, I want examples of code that involve various data structures with multiple fields, optional arguments, and interactions across different modules. I'm already familiar with JavaScript, but I would like to explore examples in Python or Ruby. If anyone has links to open-source projects with good, not overly complex tests, I'd really appreciate it!
2 Answers
In my opinion, it’s best to balance types and tests. Types help define strict contracts and prevent invalid states, while tests push you to think critically about breaking your code. I love utilizing both; refining types clarifies what values are allowed, and robust tests ensure your code functions as intended. Plus, writing tests is often simpler and can deliver equally effective results over time. It’s key to combine both for optimal results, especially in dynamic languages!
It sounds like you might benefit from using a solid testing framework. Python's built-in **unittest** is great, and many developers also rave about **pytest** for its simplicity and powerful features.
Thanks for the insight! I get how types can help, but I’m still struggling to see it in practice. I’ve never worked on a larger dynamic codebase, so I’m looking for some real examples to study.