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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Yoda conditions

9 点作者 z0a大约 11 年前

3 条评论

RKearney大约 11 年前
I use Xcode for development and it already warns against assignment within conditions[0]. gcc also warns against it[1]. Python just errors out all together[2]. I don&#x27;t have my Windows instance up with Visual Studio but I&#x27;m fairly certain that it too notifies you of assignments within conditions.<p>So the question is, why would you sacrifice readability to help solve a non-issue?<p>[0]<a href="https://www.dropbox.com/s/sjtefd55mwigq3y/Screenshot%202014-03-09%2020.51.54.png" rel="nofollow">https:&#x2F;&#x2F;www.dropbox.com&#x2F;s&#x2F;sjtefd55mwigq3y&#x2F;Screenshot%202014-...</a><p>[1]<a href="https://www.dropbox.com/s/yx01tdeykpkespv/Screenshot%202014-03-09%2021.00.13.png" rel="nofollow">https:&#x2F;&#x2F;www.dropbox.com&#x2F;s&#x2F;yx01tdeykpkespv&#x2F;Screenshot%202014-...</a><p>[2]<a href="https://www.dropbox.com/s/ex9dskab82n52qf/Screenshot%202014-03-09%2021.04.24.png" rel="nofollow">https:&#x2F;&#x2F;www.dropbox.com&#x2F;s&#x2F;ex9dskab82n52qf&#x2F;Screenshot%202014-...</a>
wfn大约 11 年前
Not sure of readability, but this surely is a neat trick to avoid null pointer exceptions, etc. (and it can be extended to cover other, related cases..):<p><pre><code> String myString = null; if (&quot;foobar&quot;.equals(myString)) { &#x2F;* ... *&#x2F; }</code></pre>
评论 #7370982 未加载
bitmilitia大约 11 年前
Do, or do not use Yoda conditions. There is no try.