Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Clock should be renamed to sf::StopWatch  (Read 1263 times)

0 Members and 1 Guest are viewing this topic.

Thrasher

  • Moderator
  • Jr. Member
  • *****
  • Posts: 53
    • View Profile
sf::Clock should be renamed to sf::StopWatch
« 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.

Thrasher

  • Moderator
  • Jr. Member
  • *****
  • Posts: 53
    • View Profile
Re: sf::Clock should be renamed to sf::StopWatch
« Reply #1 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Clock should be renamed to sf::StopWatch
« Reply #2 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, I already have used the terms in the way you have suggested (Stopwatch, Timer, Duration)!

It's worth noting a few little things, though:
  • Stopwatch should be just one word,
  • a watch (or wristwatch) is just a clock for the wrist and
  • stopwatches are also called stopclocks.

Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*