Saturday, March 1, 2008
AS3 (...rest) parameter. Good or bad.
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).
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).
Comments:
There are currently 3 Comments:
-
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.”


