News for hackers. Stuff that matters.
Re:Python 3.11: “Zero cost” exception handling by carapace on Wednesday October 06, 2021 @12:34PM (#28775096)
In Python e.g. instead of doing this:

    if key in some_dict:
        foo = some_dict[key]
        ... # A
    else:
        ... # B
you would do this:

    try:
        foo = some_dict[key]
    except KeyError:
        ... # B
    else:
        ... # A
Re:Python 3.11: “Zero cost” exception handling by albertzeyer on Wednesday October 06, 2021 @02:57PM (#28776863)
You can do that, but:

- Even in this example, I would assume that branch A is more often executed. So the zero cost optimization (which is about branch A) would improve this code performance.

- I would argue, code which uses `some_dict.get(key, fallback)` or explicitly check `if key in some_dict: ...` is both more clean and more Pythonic. See also e.g.: https://mail.python.org/pipermail/python-dev/2014-March/1331...