5 ms·
Problem is, we already have a syntax for empty lists [], empty tuples (), and {} is taken for an empty dict. So having a syntax for an empty set actually makes
by augusto-moura 1y ago
Problem is, we already have a syntax for empty lists [], empty tuples (), and {} is taken for an empty dict. So having a syntax for an empty set actually makes sense to me
- kurtis_reed 1y ago{:} should have been the empty dict, now there's no good solution
- augusto-moura 1y agoI agree that {:} would be a better empty expression for dicts, but that ship has already sailed. {/} looks like a good enough alternative
- sitkack 1y agoThere is a way to make it work. Python has no problem breaking things across major versions.
- baq 1y agoPython needed a breaking change for Unicode and a breaking change for exceptions and took it ages ago for a better future today - and it's still remembered as a huge PITA by everyone. I think you'll find everyone in the Python community disagreeing with you about a not-backwards-compatible Python 4.
- sitkack 1y agoEvery minor release of Python is a breaking change. They deprecate stuff all the time, and remember the stdlib and the wider ecosystem has to also move in concert so the breaking changes cascade. By major version I meant minor version, 3.13 -> 3.14 is a minor version in Python, but a major source of breaking changes, that is what I meant. There will be no Python 4
- gkbrk 1y agoIf Python actually incremented the major version every time they broke backwards compatibility, we'd be on something like Python 36 by now. Almost every version they break existing code. This is why it's common for apps written in Python to depend on specific Python versions instead of just "anything above 3.x".
- JohnKemeny 1y agoAre you suggesting to bump to Python 4 in order to be able to write `{}` instead of `set()` (or `{/}`) and simultaneously break all existing code using `{}` for dicts?
- IshKebab 1y agoJesus can you imagine if they announced Python 4? :-D
- augusto-moura 1y agoBreaking {} to be an empty set would be a HUGE breaking change, a _lot_ of code is already written where it is expected to be an empty dict. I don't think anyone in the Python committee would agree with breaking that
- rand_r 1y agoYou can use “set()”. Introducing more weird special cases into the language is a bad direction for Python.
- thayne 1y agoAnd you can use dict() for an empty dictionary, and list() for an empty list.
- mickeyp 1y agoYes but they are not equivalent. dict and list are factories; {} and [] are reified when the code is touched and then never reinitialised again. This catches out beginners and LLMs alike: https://www.inspiredpython.com/article/watch-out-for-mutable-defaults-in-function-arguments https://www.inspiredpython.com/article/watch-out-for-mutable...
- thayne 1y agoThat article is about how defaults for arguments are evaluated eagerly. It doesn't real have to do with dict vs {}. However, using the literal syntax does seem to be more efficient. So that is an argument for having dedicated syntax for an empty set.
- fainpul 1y agoYour link doesn't support your argument.
- slightwinder 1y agoMaking sense, and being good, is not necessary the same. Yes, having a solution for this makes sense, but the proposed solutions are just not good. Sometimes one has to admit that not everything can be solved gracefully and just stop, hunting the whale.