2

I work with C# professionally and I write code like this all the time.

private IEnumerable<Something> GetAlotOfSomething()
{
    if (somethingA.IsReady)
        yield return somethingA; 
    if (somethingB.IsReady)
        yield return somethingB; 
    if (somethingC.IsReady)
        yield return somethingC; 

    // ... More complex logic
}

var specialSomethings = 
    GetAlotOfSomething()
    .Where(s => s.IsSpecial); 

Then one day I have to write a bit of VB6 or JScript and I end up writing so much boilerplate just to get things done. Anyone thoughts?

5
  • No. I do not feel that way. Sep 14, 2010 at 21:09
  • @Paul - Says the guy with 200 C++ tags. :) Sep 14, 2010 at 21:12
  • I do say so. I have worked with upwards of 10-15 languages at this point. I do not feel that this is a must-have in a modern language. Sep 14, 2010 at 21:13
  • 3
    I feel C# will soon discover macros...
    – P Shved
    Sep 14, 2010 at 21:15
  • 1
    @Pavel - I know what macros are but I can't see the reason you posted that comment. Sep 14, 2010 at 21:28

2 Answers 2

5

Iterators (generators etc) are certainly great features that I use a lot. I don't qualify them as necessary, but I will certainly choose languages that have them when I get a choice.

1
  • OK so maybe I am being a bit dramatic, but still they are a definite productivity booster. Sep 14, 2010 at 21:13
1

They're... Handy.

But you can always just write your own if necessary. The big wins come from standard library / framework support.

2
  • 1
    Underneath the hood they are trivial to implement but writing your own doesn't read gain you much with out the syntax sugar. Sep 14, 2010 at 22:24
  • 1
    @Chaos: consider the use of iterators in C++'s STL: no direct syntax support (prior to 0x), but fantastically useful because so many generic algorithms supported them. You implement your own iterator according to the pattern, and suddenly find the rest of your work done for you... (well, to a point)
    – Shog9
    Dec 18, 2010 at 3:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.