mariano / disque-php

PHP library for Disque, an in-memory, distributed job queue
MIT License
132 stars 19 forks source link

Is there a reason you are preferring variadic calls? #37

Open kaecyra opened 7 years ago

kaecyra commented 7 years ago

To me, this makes the library a little harder to use for certain cases. Specifically, if you want to query a changing list of queues, you seem to have to call getJob() using call_user_func_array. Unless there's another usage you suggest?

dominics commented 7 years ago

The splat operator ("argument unpacking") is helpful. The only remaining annoyance is the $options array, because you can't use positional arguments after argument unpacking. So, I end up doing something like:

$queues = ['something', 'something_else'];
$options = ['count' => 3];

$args = $queues;
$args[] = $options;

$jobs = $this->disque->getJob(...$args);

Still annoying, but at least avoids call_user_func_array.

mariano commented 7 years ago

@kaecyra I don't have any strong preference towards variadics, I just enjoy writing getJob('q1', 'q2'). I do see how it's annoying when dealing with a dynamic list of queues.

As @dominics suggested this can be simplified using unpacking, and i'd add that you can actually get around the $options issue with a one liner:

getJob(...array_merge($queues, [$options]));

Would you agree that's an acceptable workaround to avoid an API change, or do you feel you have use cases where something else needs to be offered?