3 ms·
There are two perfectly valid ways of reading x == y aloud as an English statement: > X equals Y > X and Y are equal The first sentence uses active voic
by jameshart 7y ago
There are two perfectly valid ways of reading
x == y
aloud as an English statement:
> X equals Y
> X and Y are equal
The first sentence uses active voice - the second passive. Active voice ascribes agency to X; It makes a subject/object distinction between X and Y. Passive voice makes them both objects.
When reading code, it makes more sense to ascribe agency to variables than to constants, which is why people are more comfortable reading x == 0 than 0 == x. Zero can’t change, so it can’t do anything to make itself equal something. X can change, so it is capable of equaling things.
If you’re equally comfortable with either formulation, maybe you just prefer the passive reading of the sentence.
But I do wonder if you’d be equally happy if I went through your codebase and replaced every for loop condition from i < length to length > i...
- jerf 7y agoThis is exactly the point I'm making; if we must ascribe agency at all (I'm thinking that's a category error here, but human thought is fuzzy and I'll roll with it for now), it would belong to the "==". Don't read it as English at all; read it natively. There is a reason we call these programming languages, no joke, no pun. "But I do wonder if you’d be equally happy if I went through your codebase and replaced every for loop condition from i < length to length > i..." You'd have a hard time of it; I'm a vigorous believer in doing whatever you can in the language you're in to avoid the old 3-element-style C-style for loops in favor of "for ... in ..." or local equivalent. I'm pretty sure you'd get single digit hits for C-style for loops with multiple clauses in the condition.
- deleted 7y ago[deleted]