9
Awlex
4y

A: Hey yo, that function should only support up to 20 objects
B: Say no more fam

https://api.flutter.dev/flutter/...

Comments
  • 5
    Some code makes me want to cry.
  • 7
    Burn it.

    Whosever responsible for it, too.

    Nuke it from the orbit.
  • 0
    That seriously looks like someone unrolled a container-processing loop to save some CPU cycles.
    But you normally only do it in high-performance low-level code where such micro optimizations still don't matter most of the time...
  • 6
    It's self aware
  • 3
    Dart doesn't support varargs so this is what that leads to. There is also hashList where you can use a container.
  • 1
    This is so wrong. This shouldn't exist.
  • 2
    @TheSilent but what's wrong with just a list? Even they say if you need more than 20 use a list. I don't know what varargs are but I feel like even if dart did support them, we'd still see this as the problem seems to be elsewhere.
  • 3
    @bananaerror variadic args.

    A function that can take multiple values in usually a list style.

    If you know bash / C / PHP:

    argv and argc as a simple example.

    argc is a counter containing how many values are passed,
    argv is a numerical indexed array containing the values passed into the function.

    Many different forms exist, but it boils down mostly to an array containing the values passed to the function.
  • 3
    @IntrusionCM Ahh thanks, so similar to C#'s "params" keyword then.
  • 2
  • 3
    @bananaerror I guess it's an API design thing. Some people don't enjoy the extra syntax to create the list. So you have f(arg1, arg2, arg3) instead of f([arg1, arg2, arg3]). Basically just syntactic sugar/better to look at.
  • 2
    @TheSilent Yes. No. It's complicated.

    Variadic arguments can support type hints.

    Single arguments, too.

    Lists are a tad more complicated - depending on language they can have a type, but most of the time they don't.

    An object is always passed by reference, a lists behaviour depends on the language. The objects could be bound by reference - it becomes tricky. What happens e.g. when you manipulate the list in the function?

    This is why variadic arguments are a tad different from passing in a regular list... It's not only syntax sugar, it usually "fixes" the corner cases.

    If the language supports reflection, it becomes even more different. :)
  • 1
    @IntrusionCM My comment was referring to why they build the Api like that not an explanation for what varargs are ;) Sorry I didn't make that very clear. Thanks for the explanation anyways :)
  • 1
    @TheSilent Ah sorry. Brain got wrong context.
  • 0
    Lol, wtf.
  • 0
    This is why you need a fixed length array type that can be promoted to the stack and very short syntax for it.
Add Comment