robtillaart:
If you find this interesting, let me know what you think.
At first sight it looks like a great improvement, thanx,
Thank you for your interest in my edits. It's a pleasure to work on good code
robtillaart:
Resolution is selected at object creation time
good, backwards compatible, ==> OK
I wanted the code default behaviour to be the same as the original one.
Regarding the resolution selection time, I thought about two possible choices: set it once at object creation time, and/or allow the user to select it at (re)start() time. As the former looked simpler to implement and use, I opted for it, but I'm open to discussion on the latter.
API-wise, it would look something like:
obj.start(MILLIS) // this would be the default, obviously
obj.start(MICROS) // next value() or elapsed() would return micros, instead of millis.
As for the implementation, I think some complexity would arise due to conversion between millis and micros...
Do you think this would have a use case ?
robtillaart:
elapsed() is a better name than value()
Agree partially, because of ambiguity of definition elapsed time:
- if a stopwatch is stopped and started a few times the elapsed time since first start is longer than the time on the stopwatch.
That said , think elapsed is better than value though, other words I considered were counts and ticks ... what do you think of them?
==> OK
I'm not a native english speaker, so take this with a grain of salt... elapsed makes me think about the time since the last start, not the first start. From ticks() I would expect instead to receive the number of time units since the first start. Those would be millis, micros or seconds based on what was was passed to the constructor.
robtillaart:
I've replaced the #defines with an enum
Good step, add SECONDS too?
==> OK
Agreed.
robtillaart:
Open issues
- the version number should be updated, propose 1.0.00 as it is a major step
I'd stick with something a little below 1.0, since it's not really feature-complete, IMHO.
robtillaart:
How could I disagree ?
robtillaart:
- missing function to ask the mode. enum Resolution resolution() { return _res; }
Agreed.
robtillaart:
- _getTime() could be inline to minimize the time used by the class itself. (speed versus size discussion)
I thought the compiler was smart enough to inline such a trivial function, treating it more or less as a #define.
robtillaart:
What do you think?
Rob
Now it's my turn to ask you this question
Macello
PS: updated code will follow soon.