Hacker News new | ask | show | jobs
by DaiPlusPlus 9 days ago
To me, “keyword arguments” means actual language keywords being used as arguments, like “minute” or “hour” in T-SQL’s DATEDIFF, for example: `SELECT DATEDIFF( hour, NOW(), someDateCol )`.

…but I think the author meant “named arguments”, like we have in C#, Swift, and Objective-C.

2 comments

I think the author meant "keyword arguments", like they're called in Python, and which they mentioned in the first sentence.

https://docs.python.org/3/glossary.html?hl=en-GB#term-keywor...

Python calls them keyword arguments.
They do, but they're also not strictly required to be named explicitly:

They can be:

    >>> def foo(bar=None):
    ...   print(bar)
    ...
    >>> foo()
    None
    >>> foo(bar="baz")
    baz
    >>> foo(bar="baz", baz="azp")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: foo() got an unexpected keyword argument 'baz'
But you can also use them generically:

    >>> def bar(**kwargs):
    ...   print(kwargs)
    ...
    >>> bar()
    {}
    >>> bar(site="HN", user="tonyarkles")
    {'site': 'HN', 'user': 'tonyarkles'}
And I suppose Lisp started that with :key args
Python’s perversity is fractal.