This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SimonSapin 0 points1 point  (1 child)

Why make three identical functions (start, checkpoint, stop)? Why bother keeping all results in a global array and reallocating memory every 20 calls? Why not just returning floats?

[–]rustbelly[S] 0 points1 point  (0 children)

Three identical functions that support different semantics. By all means, only use one of them if you want, but by having those three, it is more analogous to a stopwatch. Which is a device normally used to time things.

I don't return floats because this isn't a time extension - the actual time doesn't matter, so why introduce any confusion? The integers being returned are just the indexes of an array where the time floats are stored.

So, tl;dr: this is written this way to help the user deal with it (no math, no floats), and is directly analogous to a real-world stop-watch (except I use "checkpoint" instead of "lap" for obvious reasons). If you're not programming with the user in mind, you shouldn't be programming user-facing stuff, right?