Suggestions for making clock exercise more idiomatic
See original GitHub issueI teach Python and I sometimes send folks I’m mentoring to Exercism for more practice. 👍
I have some suggestions to make the clock exercise feel slightly more Pythonic. As I noted below, I’m very happy to open pull requests for each of these suggestions.
Comparability
Equality of Clock
objects is tested, but other comparisons (e.g. <
and >
) are not checked.
It might be a good exercise to add a few tests implementing those. Most objects that rely on custom equality also implement the other forms of comparability in Python. I’d think it’d go something like this: 00:00 < 00:01 < 23:59.
add method
The add
method looks very odd to me. It makes this object feel more JavaScript-like than Python-like.
>>> Clock(6, 15).add(-160) == Clock(3, 35)
True
I’d think either of these options might make more sense:
Option 1: Implementing +
and -
with integers (either only left-hand or right-hand also):
>>> Clock(6, 15) - 160 == Clock(3, 35)
True
Option 2: Implementing +
and -
with other Clock
objects (this doubles up these objects as both times and time differences, but that may be fine in this case):
>>> Clock(6, 15) - Clock(0, 160) == Clock(3, 35)
True
repr
I’m not sure if this one is necessary, but this seems like the perfect object to test for a nice repr output on:
>>> Clock(6, 15)
Clock(6, 15)
I’d be happy to write a pull request for any/all of these suggestions. I wanted to open an issue for discussion first.
Thoughts on the above suggestions for the clock exercise? 😸
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (10 by maintainers)
Top GitHub Comments
Hello @behrtam and @TruthfulTechnology. I was wanting to get started with contributing to exercism and the python/c++ tracks. Would this be an issue that I might be able to pick up?
This issue has been automatically marked as `on hiatus because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.