Skip to content
DevMeme
3920 of 7590
Languages Post #4267 · source on Telegram

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

37
Anonymous ★ Top Pick 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
  1. Anonymous ★ Top Pick

    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

  2. Anonymous

    “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?”

  3. Anonymous

    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'

  4. Anonymous

    Keyword args have bound by name since before your codebase existed - the only positional thing here is the gun

  5. Anonymous

    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

  6. Anonymous

    Keyword args: decoupling param order from sig rigidity, until that sneaky positional slips in and nukes your spaceship

  7. Anonymous

    We’ve spent quarters bikeshedding parameter order in API reviews; Python shipped kwargs ages ago - our RPC generator just never got the memo

  8. Anonymous

    Python kwargs: order is a suggestion; names are the ABI. Rename “timeout” to “deadline” and your “minor” release becomes an incident - always has been

  9. @NexonSU 4y

    i don't get it...

  10. @maggelia 4y

    Neither do I

  11. @farkasma 4y

    I admittedly don't know or use python, but this IS what I would expect it to do

  12. @Odbjorn 4y

    It's called named arguments in python

    1. @dugeru42 4y

      no

    2. @dugeru42 4y

      https://stackoverflow.com/a/9450673

  13. @s2504s 4y

    Do other languages not have that ability? IDK I am teapot

    1. @sylfn 4y

      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)

      1. @feskow 4y

        almost

        1. @sylfn 4y

          declaration order? try clang OR g++ witg std=gnu OR visual studio

        2. @callofvoid0 4y

          What does . do before struct parametr names

    2. @QutePoet 4y

      In JavaScript it's possible.

    3. @sotnii13 4y

      Also in dart you can do this

  14. @s2504s 4y

    Lol, but true 😂

  15. Vitalik 4y

    A lot of languages can do that, I'm using it a lot in C#, so I didn't get this meme

  16. . 4y

    >>> f(c := 3, a := 2, b := 1) 3 2 1

  17. @CcxCZ 4y

    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)

    1. @CcxCZ 4y

      This is handy when you are passing same named argument through several functions for example.

  18. P S 4y

    This is what HTCPCP-TEA exists for... Its a real rfc.

  19. Deleted Account 4y

    Don't you feel bad while posting something like this?

    1. @sylfn 4y

      why should he?

      1. @beton_kruglosu_totchno 4y

        because cringe shortens life expectancy

    2. @CcxCZ 4y

      https://m.xkcd.com/1053/ Be kind.

  20. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

    Lmao

  21. @callofvoid0 4y

    i still don't get where this error is used

    1. @sylfn 4y

      April 1st

      1. @callofvoid0 4y

        ah

    2. @RiedleroD 4y

      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.

      1. @callofvoid0 4y

        thanks a lot!

Use J and K for navigation