def divide_numbers(a, b):
# FIXME: Handle division by zero
return a / b
# Example usage
= divide_numbers(10, 0)
result print(result)
Incremental development
- Some strategies (not necessarily exclusive):
- Iterative development: Develop the software in a series of iterations, with each iteration adding new functionality or improving existing features based on feedback and requirements.
- Divide and conquer: Break down the overall project into smaller, more manageable tasks or modules. Focus on completing and testing one module at a time before moving on to the next.
- Test-Driven Development (TDD): Write tests for the desired functionality before writing the actual code. This ensures that the code meets the requirements and can be easily tested for correctness.
- Some good practices:
- Version control: track changes, collaborate with team members, and revert to previous versions if needed.
- Code refactoring: rewrite parts of the code to improve its design, readability, and maintainability. Refactoring should be done incrementally to avoid introducing bugs.
- Feature flags: code mechanisms to enable or disable new features in your program This allows you to gradually roll out new functionality and test it in a controlled manner.
- Code stubs…
Code stubs
- Sometimes good programming is like in drawing: leave specific details to the end!
- You can mark what should be done later with code stubs:
As comments
- Later, you can search for the word “FIXME” in your code and start to “polish” these parts.
As output messages
def steps_to_calories(steps):
print('FIXME: finish steps_to_calories')
return -1
With the “pass” keyword
class Person():
pass
# FIXME implement constructor later
def ride_bike():
pass
With exceptions
def get_points(num_points):
"""Get num_points from the user. Return a list of (x,y) tuples."""
raise NotImplementedError