Python task manager from scratch, part 23: Retrieving tasks by UUID
Now that we've implemented UUIDs, we can implement task retrieval and updating. To do this, we first support those operations in the persistence layer. That means:
- Adding a new abstract method to TaskRepository.
- Instantiating that method in TextFileTaskRepository.
- Testing the changes.
Some architectural decisions that come up:
- Do we implement a reasonable, constant- (or at least sub-linear-)time search, or do we implement a naive linear scan when we're adding the method to TextFileTaskRepository? At this stage it is often better to implement the naive solution. We will be using a "real" database long before we notice any performance penalty from the linear scan. Moreover, a naive linear scan is more likely to be accurate on first implementation. Perhaps more importantly, it's fast to implement. That combination of speed and accuracy is hard to beat at this early prototype stage, however inelegant the solution.
- How do we handle the case where a search by UUID fails? I chose to return None and let the callers figure it out. In the future, raising an error or returning--for all searches, not just failed ones--a custom search result object (that combines an optional returned object and various side information such as failure messages and status codes) is likely to be better.
Here's the current commit in the
Next post: Python task manager from scratch, part 24: Supporting Task modification