Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Parameter Hell (codeplanet.io)
10 points by jon_kuperman on Jan 13, 2014 | hide | past | favorite | 10 comments


I've used to 'options as array' pattern in PHP plenty of times. While it'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.

   function something(array $options, $defaults=array('foo'=>1,'bar'=>2)){ 
   ...(array_intersect_key or something)... 
   }
Actual named parameters would work so much better.

And Wordpress 'solves' this in the plugins API by suggesting using extract(), which converts an array into variables. Which is even worse.


Absolutely, they would be the ideal answer but a lot of times this gets the job done better than just having 10 parameters to your function.


After six years of programming in Python I've almost forgot that there are languages that don't have named function parameters.

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.


haha a friend just showed me named parameters in python! /jealous


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.


There is currently an RFC for named parameters in PHP 5.6. The spec looks good and I'm hoping it gets approved.

https://wiki.php.net/rfc/named_params


There's been some recent discussion about this[0]. The RFC owner reckons it won't be ready in time for 5.6 (more like 5.7).

[0]: http://markmail.org/message/wgdsntbsnojloxqd


Hadn't seen that, thanks for the share.


The problem with this approach is that you basically lose all IDE support and static code checking - it's a good solution in extreme cases, but I prefer not to use it as the default.





Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: