3 ms·
>You could argue everything above machine language is syntactic sugar. The sugar is sprinkled on top of syntax, the stuff the parser deals with. Typing a += 1
by arketyp 8y ago
>You could argue everything above machine language is syntactic sugar.
The sugar is sprinkled on top of syntax, the stuff the parser deals with. Typing a += 1 instead of a = a + 1 is sugar because it parses the same. This assignment syntax seems different. IMHO.
- blattimwind 8y ago> because it parses the same Does not. One is addition, the other is in-place addition; they're different things and can behave differently. E.g. in "a += b" and "a = a + b", the former might not construct an intermediate object, but mutate the existing a.
- ben-schaaf 8y agoTo be more specific for python: "a += b" -> "a = a.__iadd__(b)" "a = a + b" -> "a = a.__add__(b)" "__iadd__" and "__add__" can do whatever they want.