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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Parameter Hell

10 点作者 jon_kuperman超过 11 年前

6 条评论

krapp超过 11 年前
I&#x27;ve used to &#x27;options as array&#x27; pattern in PHP plenty of times. While it&#x27;s probably the closest thing to named parameters you can get in that language, it can get kind of ugly and clumsy when you have to validate it.<p><pre><code> function something(array $options, $defaults=array(&#x27;foo&#x27;=&gt;1,&#x27;bar&#x27;=&gt;2)){ ...(array_intersect_key or something)... } </code></pre> Actual named parameters would work <i>so much better</i>.<p>And Wordpress &#x27;solves&#x27; this in the plugins API by suggesting using extract(), which converts an array into variables. Which is even worse.
评论 #7051027 未加载
NigelTufnel超过 11 年前
After six years of programming in Python I&#x27;ve almost forgot that there are languages that don&#x27;t have named function parameters.<p>I remember the horror of working with WINAPI. There are WINAPI functions with 10 or so arguments and I was using Delphi which as far as I remember had no support for dictionary literals, let alone named parameters.
评论 #7050943 未加载
mdxn超过 11 年前
Back in highschool, I wrote an Uno clone for a final project in Java. I ended up encountering a similar issue for when I was defining constructors for Card objects. At some point, I had to cast null as an Object to rid of some ambiguity. Still pretty embarrassed about it.
mlntn超过 11 年前
There is currently an RFC for named parameters in PHP 5.6. The spec looks good and I&#x27;m hoping it gets approved.<p><a href="https://wiki.php.net/rfc/named_params" rel="nofollow">https:&#x2F;&#x2F;wiki.php.net&#x2F;rfc&#x2F;named_params</a>
评论 #7051709 未加载
评论 #7051163 未加载
chaghalibaghali超过 11 年前
The problem with this approach is that you basically lose all IDE support and static code checking - it&#x27;s a good solution in extreme cases, but I prefer not to use it as the default.
omervk超过 11 年前
<a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Builder_pattern</a>