Easter Egg in net package

agolangf · · 554 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>In <a href="https://golang.org/src/net/net.go#L449">src/net/net.go</a>, we find this variable:</p> <pre><code>// aLongTimeAgo is a non-zero time, far in the past, used for // immediate cancelation of dials. aLongTimeAgo = time.Unix(233431200, 0) </code></pre> <p>This Unix timestamp converts to May 25, 1977 @ 6pm. What happened on that day at 6pm? Star Wars opened in theaters -- hence &#34;a long time ago.&#34; Cute!</p> <hr/>**评论:**<br/><br/>konrain: <pre><p>It wouldn&#39;t be made at google without an easter eggs</p></pre>the_web_dev: <pre><p>I feel like any Easter egg themed after ~1990 would have a strong camp against it lol.</p></pre>Doxa_to_Theo: <pre><p>Jurassic Park?</p></pre>letsencrypt: <pre><p><a href="https://go-review.googlesource.com/17821">https://go-review.googlesource.com/17821</a><br/> <a href="https://github.com/golang/go/commit/24a83d3">https://github.com/golang/go/commit/24a83d3</a><br/> <a href="https://go-review.googlesource.com/c/17821/10/src/net/net.go">https://go-review.googlesource.com/c/17821/10/src/net/net.go</a></p> <blockquote> <p>Russ Cox<br/> src/net/net.go:430<br/> aLongTimeAgo = time.Unix(233431200, 0)<br/> It&#39;s silly but I&#39;m also slightly worried about overflow<br/> bugs. Easy to avoid by using a more recent date.</p> </blockquote> <blockquote> <p>Brad Fitzpatrick<br/> src/net/net.go:430<br/> hah hah. cute.</p> </blockquote></pre>sh41: <pre><p>What is Russ referring to by &#34;I&#39;m also slightly worried about overflow bugs&#34;?</p> <p>That was his comment on the original <code>timeFarPast = time.Unix(0, 1)</code> variable (before it got changed into <code>aLongTimeAgo</code> as part of code review).</p></pre>Sythe2o0: <pre><p>A shot in the dark here, as I am not Russ, but maybe he meant to say underflow?</p></pre>lapingvino: <pre><p>probably because putting the date really far back makes difference calculation always being about huge numbers, which can cause an overflow...</p></pre>Absona: <pre><p>This only brings it forward seven years and a bit, so any difference calculation is still going to have pretty huge numbers.</p></pre>beertocode: <pre><p>Why does this not throw &#34;variable unused&#34; error? It&#39;s an unexported variable and not used inside the package (is it?). So does go not do this checking for the package global scope?</p></pre>barsonme: <pre><p>Russ summarizes it quite nicely: <a href="https://github.com/golang/go/issues/222#issuecomment-66048620" rel="nofollow">https://github.com/golang/go/issues/222#issuecomment-66048620</a></p></pre>Astrus: <pre><p>it is indeed used:</p> <pre><code>$ cd /usr/local/go/src/net &amp;&amp; pt aLongTimeAgo fd_unix.go 134: fd.setWriteDeadline(aLongTimeAgo) fd_windows.go 346: // cause fd.setWriteDeadline(aLongTimeAgo) to cancel a successful dial. 354: fd.setWriteDeadline(aLongTimeAgo) net.go 450: // aLongTimeAgo is a non-zero time, far in the past, used for 452: aLongTimeAgo = time.Unix(233431200, 0) </code></pre> <p>btw, you can use <a href="https://github.com/tsenart/deadcode" rel="nofollow">deadcode</a> to detect unused variables and functions.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

554 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传