y"S Chapman said:
(*!!*) Lambda expressions : listOfFoo.Where(delegate(Foo x) { return
x.size>10;}) becomes listOfFoo.Where(x => x.size>10);
I've been programming in functional languages a lot, where we use
these, and half the time they're unreadable and the other half they
make things enormously more clear. (how? mainly because the function
definition becomes local rather than at top level, so there are fewer
entities in your code, fewer top-level methods or functions).
(*!!*) Local variable type inference: var x = "hello"; is
interchangeable with string x = "hello";
Unreadable? I'd say the opposite. It'll be like Visual Basic and
Javascript, and wonderful. At the moment I write stuff like this,
SortedList<string,List<int>> x=new SortedList<string, List<int>>();
and it will become
(*!!*) Anonymous types : var x = new { Name = "James" }
I think this solves the horrid problem of object-oriented languages
that you can't return a tuple easily. If you want to write a function
that returns (int,int,string), i.e. a x-y coordinate and a label, then
you have to create a new struct/class. And wrap its fields up in
properties. And write a constructor. And provide an implementation for
Equals and GetHashCode and == and !=. And then construct it and assign
the fields. Yuck.
I actually did this in practice. I wrote my first prototype in F#, a
functional language, where I did return that (x,y,string) anonymous
tuple. And it took 1 line. Then I turned it into clean object-oriented
C# that obeyed FxCop and all the good programming practices of C#, and
it became 150 lines long.
So for all of these changes, I think they'll allow elegant concise
solutions to problems. Because they're more concise they have the
potential to be more readable. And they also have the potential to be
less readable. Good developers will use them in the first case, bad
developers will use them in the second case.
It'll maybe let Python programs program in C# more easily.