for loops and grammar
Posted 2013-09-07 12:52 AM GMT
I often struggle with pluralization. Especially when I try to mix a plural subject and singular object (e.g. "The data is the answer" or "The data are the answer"). I'm sure this is straightforward for most people, but it's hard for me.
Recently I was thinking about code while I was having a conversation (I do that way too often), and the answer to a different, entirely unrelated pluralization problem became clear to me. Take this sentence:
Each of the dogs are brown.
That doesn't sound so bad. Now take a look at this code snippet (it's kinda Python):
for each dog in dogs: assert.equals(dogs.color, 'brown')
Do you see the problem? We're never using the
dog variable, and the
dogs variable is a list of
dogs doesn't have a color attribute. So, how about this:
for each dog in dogs: assert.equals(dog.color, 'brown')
Much better. Therefore:
Each of the dogs is brown.
So, now I know, if I'm using each, the subject is always singular. Thank you, for loops. Now, if only I could figure out that "data is", "data are" problem.