Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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... -
Dart doesn't support varargs so this is what that leads to. There is also hashList where you can use a container.
-
@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.
-
@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. -
@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.
-
@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. :) -
@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 :)
-
This is why you need a fixed length array type that can be promoted to the stack and very short syntax for it.
Related Rants
A: Hey yo, that function should only support up to 20 objects
B: Say no more fam
https://api.flutter.dev/flutter/...
joke/meme
quality code