Saturday, March 1, 2008
Saturday, March 1, 2008    

I haven't come across the need to use the ...rest parameter in any of my methods yet, and while I can see where this might sometimes come in handy, I'm not quite sure its a good approach or not.

It seems like a lazy thing to do. I realize having one method instead of two can make sense, especially if the code is nearly identical, however one could argue for three methods instead of the one then... one method per argument type and then a nested call to the third argument to apply logic. If you're going to pass variable amounts of data, wouldn't it be better to just pass an array or an object with properties than use an ambiguous ...rest parameter code loop to inspect it as it comes in? I am not saying that the technique shouldn't be available, as there are probably times when this comes in super-handy (I just haven't come down that road yet).


3 Comments:

Blogger goatmeal said...
 

“I haven't yet needed to use the ...rest parameter yet. But, in other languages when I've needed to use a somewhat more obscure functions/syntax it has been when trying to maintain some really crappy code and performing hacky workarounds.”
 
Blogger Gerrit said...
 

“... values are passed as an array, so for the compiler, it is parsed as an array, making it identical to just passing an array, so why not use it in stead of passing arrays, it writes a tad faster :)”
 
Blogger e.dolecki said...
 

“I think passing an array of arguments is a bad idea. Thats why I don't like it very much. An object with properties is better (order in the array doesn't matter, no type checking 1st, etc.)”
 
Post comment

Links to this post:


Create a Link

gotoAndStop( topOfPage );