SFML community forums

General => SFML development => Topic started by: Thrasher on March 14, 2023, 12:47:23 am

Title: sf::Clock should be renamed to sf::StopWatch
Post by: Thrasher on March 14, 2023, 12:47:23 am
A clock will tell you the time. This is what the clock on your computer, your wrist, or the wall tells you. It's also how the C++ standard uses the world "clock". A clock will give you a point in time.

sf::Clock does not behave that way. It only measures the elapsed time between two points in time. This is how it's implemented. It creates a time point upon construction then takes the difference between a new time point and the original time point to create a duration which is returned to the caller. Its interface exposes no concept of a point in time. It only understands durations. For that reason it ought to be renamed to sf::StopWatch in SFML 3. With that new name, it becomes much more natural to model the behavior of a stop watch, meaning adding the ability to stop and resume the timer at will.

We might even go so far as to rename sf::Time as sf::Duration since sf::Duration is homomorphic with a std::chrono::duration.
Title: Re: sf::Clock should be renamed to sf::StopWatch
Post by: Thrasher on March 17, 2023, 05:39:08 am
Alternatively `sf::Timer` although "timer" may imply that it's counting down to zero instead of up towards infinity.
Title: Re: sf::Clock should be renamed to sf::StopWatch
Post by: Hapax on March 18, 2023, 07:47:03 am
A clock - in the general sense - is a way of measuring time. That could be a specific point in time or a duration. In fact, a specific point in time is just a duration from a set point in time; this can be observed with the computer's internal clock, for one example. An "actual time" is also relative to location and subject to local time savings. Of course, this can be adjusted to a locale but the base for these times are the internal clock, which, you could say, is a stopwatch.

I'm not saying I disagree with you, by the way, as you can probably see in my own timing library (https://github.com/Hapaxia/Kairos/tree/master/Kairos), I already have used the terms in the way you have suggested (Stopwatch, Timer, Duration)!

It's worth noting a few little things, though: