3 ms·
> Provide only one way to do an operation. I thought this was funny because these two are the same: a[i] *(a + i) Likewise all of these are the same:
by asveikau 6y ago
> Provide only one way to do an operation.
I thought this was funny because these two are the same:
a[i]
*(a + i)
Likewise all of these are the same:
(*s).x
s[0].x
s->x
As are these:
if (x)
if (x != 0)
But I guess the point can be applied elsewhere.
- jcranmer 6y agoDon't forget that these two are the same: 0[x] x[0]
- mlyle 6y agoSo are a+b and b+a. ;)
- huhtenberg 6y agoUnless one of them is a sneaky macro. Ha!
- Inityx 6y agoSure, but addition is commutative everywhere...
- mlyle 6y agoSure... I'm just pointing out that reordering operands on a commutative operation doesn't really count as "multiple ways to do things."
- int_19h 6y agoThe gotcha is that the operation is commutative on type system level. C could - as many languages do - restrict the type of the left operand of [] to "something indexable".
- mlyle 6y agoOh, sure, I'm not arguing that 0[a] isn't "weird". I just don't think it's an example of multiple ways to do something.