Default param, rest param and built-in arguments obj

I'd just like to suggest a couple FRs if possible, going or a hat trick here :crossed_fingers: , to take advantage of built-in JS features for workflows with heavy use of functions (helps with code readability, maintainability, duplication and size):

Default Parameters

Workaround: currently I pass null (or, in some instances I forget and "" sneaks in there) as the parameter value. inside the function I check if each parameter is null/empty then set it to a default value if so).

Problem: lots of parameters. for every additional parameter we're requiring the equivalent of a validation check to do what JS does in the background, probably not a big deal unless you're using the function in a loop (in which case you now literally have an exponentially growing problem).

It's def personal preference here , but I'd rather have lots of parameters w default values than have to remember which of these functions is my entry point... mostly because I can't even remember to add 'entry_' to the function name in the first place :rofl: so this might just be a 'me' problem
image

Rest Parameter

Huh?:

function addAllParameters(...args){
  let sum = 0;
  for (arg of args) sum += arg;
  return sum;
}
addAllParameters(1, 2, 3, 4, 5, 6, 7); // valid
addAllParameters(9, 10);  //valid

Workaround: using lots of parameters, which now sounds like a catch 22 after the above :rofl:

Problem: functions with unknown number of parameters either can't be done or have to have custom limits, requiring more code.

JS Function Arguments Object

Huh?:

function sumAll() {
  let sum = 0;
  for (let i = 0; i < arguments.length; i++) {
    sum += arguments[i];
  }
  return sum;
}

This is actually just another way to support an unknown number of parameters, it's just less common because of how deceiving it can be to anyone who didn't directly write the function or didn't read the docs or function header... it's an object though so I'd assume it'd be easier to pass the object reference around so we have access to it than supporting the rest param ...?

actually just realized if you could add the dynamic/fx button thingy to toggle between 2 inputs for key/value and 1 text input for something like {{ ...args }} it might be easier than the arguments obj :man_shrugging:

3 Likes

Hello @bobthebear!

Great ideas, I just filed three different FRs for them :sweat_smile:

I was a little confused by the last one, it sounds like you are thinking of having a piece of JSON data but as a reference that can then be keyed into to grab out nested args.

Or alternatively a text input field with {{ ...args }} that would be grabbing data from another workflow block, correct?

Default params/false value checking is something we can definitely abstract away for the first request.

The second request makes sense, but might be trickier as I have a hunch that the current GUI of key value pairs was either set up for a reason programmatically or to avoid errors regarding naming and accessing across different params.

Will keep you posted on any news that I hear from the team :partying_face: :three: :saluting_face:

my bad, I forgot to add a link for that one:

Default Parameters
Rest Parameter
Arguments Object

ya in this case, the text input field would list all items in the args array (like the spread operator).

1 Like

hey @bobthebear,

Our engineers say that for having a function block handle an unknown number of params, that the blocks can use an object or list as input.

Let me know if that works for you :+1:

1 Like

Heh, plz tell your engineers thank you, I've learned something new and I find it interesting :rofl: .... I'ma put the TLDR; first cause it's a doozie bellow here. using a parameter as an Array is faster than using Rest Parameters ie:

const foo = function(my_array){ }
foo([1, 2, 3, 4])

// that is faster than this:

const bar = function(...my_array){}
bar(1, 2, 3, 4)

test source
I do this everywhere, and some in big workflows that can possibly be part of longer chains or loops involving polling making memory and speed precious commodities down the line. for me, the operator ... shows the intent of an array better than relying on the variable name and the operator would prevent any unnecessary copies in memory. whoopsie. I don't even wanna consider how many years I've assumed this :cry:

I had to do some searching, I wasn't positive on how JS handled the array in the background. on one hand, JS doesn't implement c-style pointers, but they do use references. small difference, but from my POV: "when I call a function and pass an array, JS actually passes the memory address of the array.... neat.... but if there are no pointers what's the reference stored in on the other side after I call the function?". At this point, I assumed JS would copy the array at that location into the parameter variable... there's no base type to store a memory address in, so the only option is to store the data at that address.

Its like I got to the VERY LAST step, where you see 1 + 1 = 0 + 2 at the end of a math proof and instead of doing the work I just gave up and said the answer was "nope". the one thing everybody gets stuck on when learning c (pointers & references.... pun intended) is like those pictures that if you stare at them long enough you see some hidden 3d image... there's always that one jerk who just sees it, but he's secretly One-Eyed Willy (go me, Goonies reference) when it comes to finding Waldo. Yup, me. I just got pointers, but Waldo/JS 'secrets' are always just outta sight(darn you JS), so again, thank you retool engineers as I probly never would have found a reason to have bothered with that benchmark test. ** whispers ** don't worry I know it was on purpose ** wink ** ** wink **. :smirk: I joke I joke, but please don't send scarry reddit engineers after me :innocent: (if those freaks can find a flag in the middle of no where with next to no context in like 48hrs for fun-sie I don't wanna know what they'd do over a bad joke :rofl:)

1 Like

Glad you were able to learn something new :sweat_smile:

I definitely did as well. Thank you for breaking it down with the TLDR.

I agree that seeing the spread operator ... is a much better visual queue for me to remember that a function is taking many arguments and switching them over to an array or vice versa.

I also don't want to think about how many times I have not efficiently managed memory is JS :melting_face:

References vs points always blurs together in my mind but do have some odd quirks between them. I haven't worked with C that much but would defintiely benefit from diving back in and jogging my memory pun intended on how computers do their business under the hood.

JS is a fickle mistress and always finds ways to surprise me :joy: we will not be sending any reddit engineers anywhere, are you talking about geo-guessing?

Have a good one Scott! :handshake:

1 Like