Why "yield return" rather than "yield"?

This came up in another context, and I thought I'd share the story.

In the first version of iterators, you would use "yield" when you wanted to "return" a iterator value back, and things worked great. So, that's that way it was for quite a long period.

We knew at the start of the 2.0 effort that we were doing some major things to the language, and major things often require new keywords. It seemed likely that some of the generics work would lead to this.

So, we planned on how to deal with it. Now, new keywords are bad. Bad, because developers have the annoying habit of using non-keywords as identifiers (someday I'll tell the story of the generated FORTRAN code I worked on when I was fresh out of college), and if their choice happens to align with a keyword, their used-to-be-working-perfectly code now breaks.

Which is, as they say, bad.

So, we came up with a mitigation strategy - we would provide a utility that you could run over your source code, and it would replace any identifier that had becomeĀ a keyword with the escaped version. It does this by putting an "@" sign in front of it.

I expect to see heavy usage of "@" in any obfuscated C# contests...

So, anyway, we had this plan in place. But as we finished the work with generics, we found that we had managed to do it without any real keywords (see my next post for more information...).

This meant that the only new keyword in 2.0 was "yield", and switching to yield return meant that C# 2.0 would compile all C# code without change.

Which is good.