3 ms·
This is just a product of bad design Perhaps, rather, a product of an infelicitous programming language? You don't have to worry about extra function arguments
by jessaustin 11y ago
This is just a product of bad design
Perhaps, rather, a product of an infelicitous programming language? You don't have to worry about extra function arguments in javascript.
It seems common in C, python, and similarly arity-concerned languages to just accept a pointer to a struct (dict, etc.) when coding a callback for an API like this. That way the callback can examine as much or as little of the struct as it wants, and much less needs to change in future when the callback needs more.
- nostrademons 11y agoThere are trade-offs for everything. The extra function arguments in Javascript cause all sorts of bugs when you alter the signature of a callback, miss a call site, and the new argument is suddenly being interpreted (without any crash or error message!) according to the semantics of a different argument. The callback-args struct is common, but has its own set of trade-offs too: it frequently becomes a "data whale", a dumping ground for everything that could happen with no indication in the source code of which parts a subsystem actually uses. Frequently, I've seen these replaced by a dependency injection framework as the software and team gets larger (which has its own set of problems, with it becoming difficult to holistically understand the data flow within the system). Keyword args are popular in languages that support them, too. They solve the semantic problems of missing positional args, and are semantically identical to the option struct approach but with a bunch of syntactic sugar.
- tazjin 11y ago> Perhaps, rather, a product of an infelicitous programming language? You don't have to worry about extra function arguments in javascript. I can't even tell when these things are troll posts and when they are meant to be serious anymore.
- jessaustin 11y agoTFA had, "I had to tweak my original code to include those two inputs!!?#\!" If that's such a severe "problem", I think I've suggested a plausible "solution". b^)
- squeaky-clean 11y agoIt's an extremely easy change in python, and depending on how you're writing your functions, it may work without any changes (just like Javascript). If you write your functions in python to accept args and *kwargs, it will automatically handle any number of positional arguments and keyword arguments.
- klibertp 11y ago> in C, python Python actually has much better support for varargs than JavaScript used to have. See: https://docs.python.org/dev/tutorial/controlflow.html#keyword-arguments https://docs.python.org/dev/tutorial/controlflow.html#keywor...