Skip to content

Commit

Permalink
Address reviewer comments:
Browse files Browse the repository at this point in the history
* Fix several typo-s.
* Beef up example code.
* Explain why hours, minutes and seconds are divided the way they are.
  • Loading branch information
HowardHinnant committed Oct 6, 2023
1 parent 4b5de83 commit 0568bfe
Showing 1 changed file with 108 additions and 21 deletions.
129 changes: 108 additions & 21 deletions rebuttal.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<address align=right>
Document number: DxxxxR0
<br/>
Date: 2023-10-05
Date: 2023-10-06
<br/>
Audience: Library Evolution Working Group
<br/>
Expand All @@ -27,6 +27,8 @@ <h2>Contents</h2>
<li><a href="#Existing">The <code>%S</code> flag as specified in the
<code>&lt;chrono&gt;</code> library is existing code</a></li>
<li><a href="#Good"><code>%S</code> is a good design</a></li>
<li><a href="#Acknowledgments">Acknowledgments</a></li>
<li><a href="#References">References</a></li>
</ul>

<a name="Introduction"></a><h2>Introduction</h2>
Expand All @@ -36,10 +38,16 @@ <h2>Contents</h2>
meaning of <code>%S</code> as proposed in <a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2945r0
.html">P2945R0</a>. To be perfectly clear, this paper expresses no
objection to adding syntax to specify precision to <code>%S</code>.
This would not break any code. The only objection is to changing the
meaning of <code>%S</code> from representing seconds exactly, to
representing only the integral part of seconds.
objection to adding syntax to specify precision to <code>%S</code> as
proposed in the <a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2945r0
.html#less-preferred-proposal-wording">Less-Preferred Proposal
Wording</a>. This would not break any code. The only objection is to
changing the meaning of <code>%S</code> from representing seconds
exactly, to representing only the integral part of seconds as proposed
in the <a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2945r0
.html#preferred-proposal-wording">Preferred Proposal Wording</a>.
</p>

<a name="Bad"></a><h2>
Expand All @@ -48,17 +56,20 @@ <h2>Contents</h2>
</h2>

<p>
The proper way to change a standard is to deprecate the old behavior,
and provide new syntax for the new behavior. Let both behaviors
coexist for a few cycles, then remove the deprecated specification.
The proper way to change existing behavior in a standard is to
deprecate the existing behavior, and provide new syntax for the new
behavior. Let both behaviors coexist for a few cycles, then remove
the deprecated specification.
</p>
<p>
Doing otherwise risks introducing run-time errors to existing code by
simply upgrading to a new version of C++. Such run-time errors have
the potential for raising safety and security issues.
the potential for raising safety and security issues. It also
undermines the important claims about C++ being stable and standards
being backwards compatible.
</p>

<a name="Existing"><h2>
<a name="Existing"></a><h2>
The <code>%S</code> flag as specified in the
<code>&lt;chrono&gt;</code> library is existing code
</h2>
Expand All @@ -78,7 +89,7 @@ <h2>Contents</h2>
syntax and behavior in my date library.
</p>

<a name="Good"><h2>
<a name="Good"></a><h2>
<code>%S</code> is a good design
</h2>

Expand Down Expand Up @@ -129,6 +140,25 @@ <h2>Contents</h2>
using namespace std::chrono;
return floor&lt;milliseconds&gt;(system_clock::now());
}

void
foo()
{
auto tp = GetCurrentTime();
// ...
// maybe do some arithmetic or conversions to local time here
// ...
// Formatted with milliseconds precision as specified back in the implementation of GetCurrentTime()
datafile << std::format("{:%FT%TZ}", tp);
}

void
bar()
{
decltype(GetCurrentTime()) tp;
// Same format string (minus the "{:}") to parse it back in
datafile >> std::chrono::parse("%FT%TZ", tp);
}
</pre></blockquote>

<p>
Expand All @@ -139,17 +169,22 @@ <h2>Contents</h2>
statements with their specification’s precision. They can just ask
for the time: <code>“%F %T”</code> (etc.). And when their
specification changes, there is no pain point. Formatting and parsing
<em>by default</em> automatically adjust.
<em>by default</em> automatically adjust. Change
<code>milliseconds</code> to <code>seconds</code> in
<code>GetCurrentTime()</code> and things just work, but now at
seconds-precision. Change <code>floor</code> to <code>ceil</code> or
<code>round</code> to achieve alternative rounding modes from the
OS-supplied precision.
</p>

<p>
<code>&lt;chrono&gt;</code> does not (and should not) carry all of
this respect for the client around and then when the client gets ready
to create a logging statement suddenly say: Oh, you probably want the
precision a bunch of committee members decided upon. No,
<code>&lt;chrono&gt;</code> should give the client the precision he
has already asked for (as the default, of course there should be a way
to change it).
<code>&lt;chrono&gt;</code> should give the client the precision they
have already asked for (as the default, of course there should be a
way to change it).
</p>

<p>
Expand All @@ -159,16 +194,68 @@ <h2>Contents</h2>
parsed, and reads up to that amount of precision from the input
stream. A piece-wise redesign of <code>&lt;chrono&gt;</code> without
an in-depth knowledge of the entire library is foolhardy at best. And
in this case also disruptive and dangerous.
in this case is also disruptive and dangerous.
</p>

<p>
<a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2945r0
.html">P2945R0</a> questions why the current spec offers fractional
seconds, but not fractional minutes or hours. The answer<sup><a
href="#ref1">1</a></sup> dates back to Egyptians who divided the day
into 12 periods around B.C. 1500. At that time no one cared enough
about fractional hours to invent a system for them. Hours were not
divided into minutes until the first mechanical clocks that displayed
minutes appeared near the end of the 16th century. Minutes were
defined as <sup>1</sup>/<sub>60</sub> of an hour based on the
sexagesimal system developed by the Sumerians around 2000 B.C. This
was used many centuries later first to divide circles, and later to
divide the round mechanical clock faces. Minutes were subsequently
divided using the sexagesimal system into seconds. In the 1500s
seconds were not displayed on the clock face but rather measured by
swings of the pendulum.
</p>

<p>
It was not until the late 19<sup><i>th</i></sup> or early
20<sup><i>th</i></sup> century that technology advanced enough for
people to even consider dividing seconds. And at that time,
civilization chose to use the base 10 system which had become well
established. And this is why hours are divided by minutes, minutes by
seconds, and seconds by powers of 10. It is simply history.
</p>

<p>
Nevertheless, if someone really wants fractional hours, that is certainly doable:
</p>

<blockquote><pre>
duration&lt;double, hours::period&gt; d = ...
cout &lt;&lt; format("{:.4}, d) &lt;&lt; '\n';
</pre></blockquote>

<p>
Finally <code>%S</code> does not need to have identical functionality
to other languages as argued by <a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2945r0
.html">P2945R0</a>. There are many ways in which
<code>&lt;chrono&gt;</code> differs from other date time libraries.
These differences are what makes the <code>&lt;chrono&gt;</code>
solution superior, in safety, functionality and performance.
</p>

<a name="Acknowledgments"></a><h2>Acknowledgments</h2>

<p>
<code>%S</code> does not need to have identical functionality to other
languages. There are many ways in which <code>&lt;chrono&gt;</code>
differs from other date time libraries. These differences are what
makes the <code>&lt;chrono&gt;</code> solution superior, in
safety, functionality and performance.
Thank you to Tomasz Kamiński, Stephan T. Lavavej, Bjarne Stroustrup,
David Vandevoorde, and Ville Voutilainen for the corrections,
suggestions and comments. This paper improved from its original draft
because of your generously donated time and attention.
</p>

<a name="References"></a><h2>References</h2>

<a name="ref1"><sup>1</sup> <a href="https://www.scientificamerican.com/article/experts-time-division-days-hours-minutes/">Why is a minute divided into 60 seconds, an hour into 60 minutes, yet there are only 24 hours in a day?</a>

</body>
</html>

0 comments on commit 0568bfe

Please sign in to comment.