Python's Keyword Arguments Have Always Been a Feature
Description
This image uses the popular 'Always has been' meme format, which depicts two astronauts in space against a starry background. One astronaut, looking at a snippet of Python code, asks, 'How long does Python act like this?'. The second astronaut, standing behind the first and pointing a pistol at their back, replies, 'Always has been'. The code snippet in the top-left corner shows a Python function being defined as 'def f(a, b, c): print(a, b, c)'. The function is then called with keyword arguments in a different order: 'f(c = 3, a = 2, b = 1)', which correctly produces the output '2 1 3'. The humor comes from a developer's apparent surprise at discovering named (or keyword) arguments, a fundamental and long-standing feature of the Python language. The meme playfully suggests this feature is as old and established as the universe itself, mocking the idea that it might be a new or strange behavior
Comments
37Comment deleted
Discovering keyword arguments in Python is the programmer's equivalent of realizing the screwdriver has a Phillips head on the other end. It's not a new feature; you've just been using it wrong the whole time
“Wait - Python lets me permute kwargs and it just works?” Old-timer Python devs: “Always has been.” Me, eyeing our decade-old Java module with 14 telescoping constructors: “So that Builder pattern was just us LARPing as a compiler?”
After 15 years of Python, you realize the real backward compatibility nightmare isn't Python 2 vs 3 - it's explaining to junior devs why your legacy codebase has defensive **kwargs everywhere because someone in 2008 thought positional-only parameters were 'unpythonic'
Keyword args have bound by name since before your codebase existed - the only positional thing here is the gun
Python's keyword arguments have been flexing their positional independence since before most frameworks were born - proving that sometimes the real legacy code is the language feature that's been there all along, quietly enabling every config function with 47 optional parameters you've ever written
Keyword args: decoupling param order from sig rigidity, until that sneaky positional slips in and nukes your spaceship
We’ve spent quarters bikeshedding parameter order in API reviews; Python shipped kwargs ages ago - our RPC generator just never got the memo
Python kwargs: order is a suggestion; names are the ABI. Rename “timeout” to “deadline” and your “minor” release becomes an incident - always has been
i don't get it... Comment deleted
Neither do I Comment deleted
I admittedly don't know or use python, but this IS what I would expect it to do Comment deleted
It's called named arguments in python Comment deleted
no Comment deleted
https://stackoverflow.com/a/9450673 Comment deleted
Do other languages not have that ability? IDK I am teapot Comment deleted
C++: no ability to do this except some shitty workarounds like struct kek { int a, b, c; }; void fun(kek a) { cout << a << " " << b << " " << c; } fun(kek{.c = 3, .a = 2, .b = 1}); (syntax may be incorrect bc i dont use this feature) Comment deleted
almost Comment deleted
declaration order? try clang OR g++ witg std=gnu OR visual studio Comment deleted
What does . do before struct parametr names Comment deleted
In JavaScript it's possible. Comment deleted
Also in dart you can do this Comment deleted
Lol, but true 😂 Comment deleted
A lot of languages can do that, I'm using it a lot in C#, so I didn't get this meme Comment deleted
>>> f(c := 3, a := 2, b := 1) 3 2 1 Comment deleted
It's even better in OCaml where you can: let foo = 1; let bar = 2; func(.foo, .bar) As a shorthand to func(foo=foo, bar=bar) Comment deleted
This is handy when you are passing same named argument through several functions for example. Comment deleted
This is what HTCPCP-TEA exists for... Its a real rfc. Comment deleted
Don't you feel bad while posting something like this? Comment deleted
why should he? Comment deleted
because cringe shortens life expectancy Comment deleted
https://m.xkcd.com/1053/ Be kind. Comment deleted
Lmao Comment deleted
i still don't get where this error is used Comment deleted
April 1st Comment deleted
ah Comment deleted
afaik it's meant for when you make a request for a server which it doesn't handle because it's not the right kind of server - e.g. when you make a https request to a http server. Though the code was introduced on April Fool's, so it was named humorously and nobody uses it for anything. Maybe there's a good replacement, idk. But a 404 or 403 usually suffices for those situations. Comment deleted
thanks a lot! Comment deleted