TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Parameter Hell

10 pointsby jon_kupermanover 11 years ago

6 comments

krappover 11 years ago
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 未加载
NigelTufnelover 11 years ago
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 未加载
mdxnover 11 years ago
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.
mlntnover 11 years ago
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 未加载
chaghalibaghaliover 11 years ago
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.
omervkover 11 years ago
<a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Builder_pattern</a>