1
Vote

Params ... not a good idea without an explicit definition.

description

I've tooled over this again and again. And the fact remains that if you declare a function like:
function() {
  var args = arguments;
  // Then start checking for if it's length is 1 and contains an array...
 // It does?  Then use that array content.
}
It opens up the function to be misinterpreted. LINQ is a perfect example because you actually may have an array of arrays and get unexpected output. :(

Let's use the method choice as an example: (excuse me if I'm a TypeScript junkie)
choice<T>(...params: T[]): Enumerable<T>;
My suggestion is, to not define choice like this. It should be:
choice<T>(params: T[]): Enumerable<T>;
And then have an explicit call as such:
choiceFrom<T>(...params: T[]): Enumerable<T>{
  return choice<T>(params);
}
This way, there can be no mistake about what the caller wants.

Depending on your coding style and intention, you may do something like this instead:
choiceUsing<T>(params: T[]): Enumerable<T>;
choice<T>(...params: T[]): Enumerable<T> {
  return choiceUsing<T>(params);
}
It simply depends upon what you think is easier for the user to understand, and/or you may want to add these explicit methods without changing the current API and simply reroute them as shown here.

comments