Lots of programming languages already have the compound statements +=
, -=
, /=
, etc. A relatively new style of programming is to "chain" method calls onto each other, e.g. in Linq, JQuery and Django's ORM.
I sometimes, more often than I'd like, find the need to do this in Django:
# Get all items whose description beginning with A
items = Items.objects.filter(desc__startswith='A')
if something:
# Filter further to items whose description also ends with Z
items = items.filter(desc__endswith='Z')
I think it would be easier and actually more readable if there was a compound method call statement such as .=
which could work like this:
items = Items.objects.filter(desc__startswith='A')
if something:
items .= filter(desc__endswith='Z')
- Are there any programming languages that support this or something like it?
- If the answer is no, why not?
- Is this style of programming really that new?
- Are there any PEPs (Python Enhancement Proposals) that support this idea?