<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 15, 2013 at 9:10 PM, Tim Peters <span dir="ltr"><<a href="mailto:tim.peters@gmail.com" target="_blank">tim.peters@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">> _DI4Y   = _days_before_year(5)<br>
> # A 4-year cycle has an extra leap day over what we'd get from pasting<br>
> # together 4 single years.<br>
> <span class="">assert</span> _DI4Y == 4 * 365 + 1<br>
><br>
> To me, the constant should be directly set to its known value.<br>
> _DI4Y = 4*365 + 1.<br>
> The function should then be tested in test_datetime.<br>
>   self.assertEqual(dt._days_before_year(5), dt._DI4Y)<br>
<br>
</div>I think making that change would be pointless code churn.  Harmful,<br>
even.  As the guy who happened to have written that code ;-), I think<br>
it's valuable to have the _code_ (not off buried in some monstrously<br>
tedious test file) explain what the comments there do explain, and<br>
verify with the <span class="">assert</span>.  If anyone needs to muck with the<br>
implementation of <span class="">datetime</span>, it's crucial they understand what DI4Y<br>
_means_, and that it's identical to _days_before_year(5).  Its actual<br>
value (4*365 + 1) isn't really interesting.  Defining _DI4Y _as_<br>
_days_before_year(5) captures its _meaning_.<br></blockquote><div><br></div><div><br></div><div>Interestingly, the corresponding C code is closer to what Terry suggested:</div><div><br></div><div><div>/* Number of days in 4, 100, and 400 year cycles.  That these have</div>
<div> * the correct values is asserted in the module init function.</div><div> */</div><div>#define DI4Y    1461    /* days_before_year(5); days in 4 years */</div><div>#define DI100Y  36524   /* days_before_year(101); days in 100 years */</div>
<div>#define DI400Y  146097  /* days_before_year(401); days in 400 years  */</div></div><div>...  skipping to the init function ...</div><div><div>    /* A 4-year cycle has an extra leap day over what we'd get from</div>
<div>     * pasting together 4 single years.</div><div>     */</div><div>    assert(DI4Y == 4 * 365 + 1);</div><div>    assert(DI4Y == days_before_year(4+1));</div></div><div><br></div><div>This is probably explainable by the limitations of the C language, but I would find</div>
<div><br></div><div><span style="color:rgb(80,0,80)">_DI4Y = 4 * 365 + 1</span><br></div><div><span class="" style="color:rgb(80,0,80)">assert</span><span style="color:rgb(80,0,80)"> _DI4Y == </span>_days_before_year(5)<span style="color:rgb(80,0,80)"><br>
</span></div><div><br></div><div>to be more natural than the way it is currently written.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<br>
Ain't broke - don't fix.</blockquote><div><br></div><div>Agree. </div></div><br><br></div></div>