TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Nerdsniping: A glimpse into a stubborn mind

145 点作者 philip_roberts大约 11 年前

23 条评论

vernie大约 11 年前
Yikes. I understand that companies use these posts as a form of advertising, but seeing your "application security specialist" struggling with such a basic expression gives me pause.
romanovcode大约 11 年前
I was working with this guy - he always tried to prove that everything is possible wasting time. He ALWAYS over-complicated simple things. He was horrible to work with and everyone hated him.<p>Not to say you are just like him etc. but this post reminded me of him because it was probably exactly what he would do.
评论 #7586273 未加载
评论 #7588735 未加载
mncolinlee大约 11 年前
And this is why Javascript can be such an awful language. Leaving off a single equals has such a profound effect, often without a new coder even realizing it while reading the code.<p>Imagine what happens to your code when someone tries to write a function for its side effects similar to the example seen in the blog post. Then releases it in production for it to break in six months with a feature change.
评论 #7587295 未加载
评论 #7586612 未加载
评论 #7587909 未加载
评论 #7587550 未加载
评论 #7586760 未加载
评论 #7588672 未加载
评论 #7587825 未加载
评论 #7588331 未加载
ronaldx大约 11 年前
The differences between programming syntax and elementary&#x2F;Boolean algebra are very awkward to understand clearly and deal with correctly. We clearly understand mathematical algebra to work one way, and we naturally assume programming algebra works the same way, which it doesn&#x27;t at all.<p>Here, the antagonist says that b can&#x27;t be 1 and 2 at the same time, which would be self-evident in mathematical algebra, but turns out to be quite irrelevant to Javascript and to programming paradigms generally (since two statements will never be checked simultaneously).<p>This difference in how syntax is understood actually presents a barrier to programming for modestly trained mathematicians, who would otherwise be expected to excel.
评论 #7585866 未加载
评论 #7590549 未加载
评论 #7585942 未加载
gyepi大约 11 年前
Nerdsniping reminds me of the Walt Whitman poem:<p><pre><code> There was a child went forth every day; And the first object he look’d upon, that object he became; And that object became part of him for the day, or a certain part of the day, or for many years, or stretching cycles of years. </code></pre> It&#x27;s especially bad if you&#x27;d really rather be doing something other than what you&#x27;re currently doing.
tatalegma大约 11 年前
&quot;I want my code to execute if port is 80 or 443, and http is false&quot;<p>Couldn&#x27;t you simply do this?:<p>if ((a===&#x27;80&#x27;||b===&#x27;443&#x27;) &amp;&amp; http===false) { ... }
评论 #7585833 未加载
level大约 11 年前
Call me nitpicky, but it always bugs me when someone references some content, but doesn&#x27;t link to it. Specifically the XKCD and Stackoverflow links. Link to the comic and question specifically, rather than making me go hunt for that content.
alistairjcbrown大约 11 年前
&gt; I guess we’ve messed with the prototype too much, and JavaScript isn’t really convinced it’s still a proper number anymore.<p>You&#x27;re comparing a literal number with an object, which are not the same type.<p><pre><code> 2 === new Number(2) &#x2F;&#x2F; =&gt; false 2 == new Number(2) &#x2F;&#x2F; =&gt; true</code></pre>
scjody大约 11 年前
&gt; Have I learned anything directly useful?<p>You probably haven&#x27;t. But a less experienced programmer has learned why you should always use ===.
评论 #7586051 未加载
tarpherder大约 11 年前
Might not be Java but still interesting, it made me think of one of my favorite little quirks in C++:<p><pre><code> #include &lt;cmath&gt; &#x2F;&#x2F;Floating point model: Strict:Precise:Fast &#x2F;&#x2F;Will code execute float a = nanf(&quot;&quot;); if (a == a)&#x2F;&#x2F;S:No P:No F:Yes (do something); if (a != a)&#x2F;&#x2F;S:Yes P:Yes F:No (do something); if (a &lt; 0.f || a &gt; 2.f)&#x2F;&#x2F;S:No P:No F:Yes (do something); if (isnan(a))&#x2F;&#x2F;S:Yes P:Yes F:Yes (do something); </code></pre> NaN&#x27;s (Not A Number) can propagate a long way through your code, possibly reaching places where they cause real problems. When dealing with input, especially networking, one should always check for NaN&#x27;s. Basically the rule with NaN&#x27;s is: The comparison always returns false if any NaN is involved. But as you can see; specifying the fast model throws that out of the window. (Code was otherwise unoptimized.)<p>In the third statement an otherwise fine check is done to make sure the value in a is sane, it doesn&#x27;t get changed but its certainly not what you&#x27;d want it to be.<p>Whole lots of fun can be had when serving this to game servers. :D
mfonda大约 11 年前
I think there was a more general question here that was missed: can a == x &amp;&amp; a == y ever be true for any arbitrary values of a, x, and y, where x != y.<p>From a logical point of view, no, this can never be true. I would suspect this can never be true in javascript, and could only be made true in a language where you can override == to always return true.<p>I think when most developers use the word &quot;never&quot;, what they really mean is &quot;never (within the current context)&quot;. This makes conversations a lot simpler. Imagine how difficult conversations would be if you always had to qualify never. &quot;This can never be true (assuming a weird valueOf method hasn&#x27;t been defined and assuming I didn&#x27;t modify the javascript interpreter to always return true for == and assuming ...)&quot;.
评论 #7587597 未加载
评论 #7588925 未加载
评论 #7587499 未加载
aaronem大约 11 年前
It&#x27;s not often I see an HN thread which so aptly demonstrates the exact effect under discussion.
antinitro大约 11 年前
var i=0;<p>var b = {};<p>b.valueOf = function () {<p><pre><code> return ++i: </code></pre> };<p>if (b==1 &amp;&amp; b==2) {&#x2F;&#x2F;success}
评论 #7586864 未加载
yeahbutbut大约 11 年前
And so far everyone has missed telling the poor OP how to avoid writing two equality checks...<p><pre><code> if( [80, 443].indexOf(port) !== -1 &amp;&amp; http === false )</code></pre>
评论 #7589289 未加载
评论 #7589308 未加载
gcr大约 11 年前
This kind of abuse is also available in Python!<p><pre><code> In [3]: class TheObjectThatIsEqualToAnything(object): def __eq__(self, other): return True In [4]: x = TheObjectThatIsEqualToAnything() In [6]: x == 3 and x == 5 Out [6]: True</code></pre>
评论 #7591305 未加载
wambotron大约 11 年前
I think the answer to &quot;can something be fuzzy equal to one value and strictly equal to another in JS?&quot; has an easy answer that doesn&#x27;t take much effort to find. This might be cooler in another language, though.<p>var b = 2;<p>b == &#x27;2&#x27;; &#x2F;&#x2F; true<p>b === 2; &#x2F;&#x2F; true
评论 #7588326 未加载
评论 #7586802 未加载
forrestthewoods大约 11 年前
And here we all are reading this post during work hours. My god, the amount of productivity lost because of that simple question in chat!
mathattack大约 11 年前
Is this a case of readability versus theoretical perfection?
drvortex大约 11 年前
0.25 = 0.25<p>1 - 3 + 2.25 = 4 - 6 + 2.25<p>1^2 + 2(1)(1.5) + (1.5)^2 = (2)^2 - 2(2)(1.5) + (1.5)^2<p>Since a^2 - 2ab + b^2 = (a - b)^2<p>(1-1.5)^2 = (2-1.5)^2<p>1 = 2<p>QED.
peterkelly大约 11 年前
And now for exercise 2:<p>Port the solution to Haskell
评论 #7587341 未加载
评论 #7587804 未加载
评论 #7587249 未加载
cinitriqs大约 11 年前
so...<p>(everything == all &amp;&amp; all == everything) == stardust&#x2F;code
Dewie大约 11 年前
Defining a number to be a procedure (or &#x27;word&#x27; in the parlance) is simple in Forth.<p>&gt; : a 2 ;<p>&gt; : 2 3 ;<p>&gt; a 2 =<p>&gt; a 3 =<p>The two flags on the top of the stack are now equal.
ssdfsdf大约 11 年前
This took you 11 days?!
评论 #7587761 未加载