News for hackers. Stuff that matters.
Re:N-Params vs. Single Param by ashtuchkin on Thursday April 17, 2025 @07:31PM (#43723370)
python does this pretty elegantly:

    def my_func(a: int, b: int):
        print(a+b)

    # both of these can be used
    my_func(1, 2)
    my_func(a=1, b=2)
Re:N-Params vs. Single Param by ziofill on Friday April 18, 2025 @12:34AM (#43725056)
Also `my_func(**{a:1, b:2})`
Re:N-Params vs. Single Param by ImageXav on Friday April 18, 2025 @09:39AM (#43727990)
Even better, python has named tuples [0]. So if you have a tuple that you are sure will always have the same inputs you can declare it:

``` Point = namedtuple('Point', 'x y') pt1 = Point(1.0, 5.0) ```

And then call the X or Y coordinates either by index: pt1[0], pt1[1], or coordinate name: pt1.x, pt1.y.

This can be a really handy way to help people understand your code as what you are calling becomes a lot more explicit.

[0] https://stackoverflow.com/questions/2970608/what-are-named-t...

Re:N-Params vs. Single Param by sixo on Saturday April 19, 2025 @07:23PM (#43740253)
This isn't what I'm talking about. I would want

    def my_func(a: int, b: int):
      ...

    def my_func2(args: my_func.__args_type__):
      ...
with `my_func.__args_type__` standing for an object like `{a: int, b: int}`.