Jaa


Weird lambda usage

I had posted previously that I don't like lamda in C#. The reason is that C# had a different nature before. This is drastically changing and soon we'll have huge amounts of code having lambda and other cool new shiny language features which'll make it alien to a large part of its user base. People are already putting up samples that use code as follows

 static void Main(string[] args)
{
    (Printer())(42);
}

static Action Printer()
{
    return (T t) =>
              {
                  Console.WriteLine(t);
              };
}

Comments

  • Anonymous
    February 22, 2007
    I write code like this quite often, what it is issue with it?And that is on .Net 1.1 (originally) and now on .Net 2.0
  • Anonymous
    February 25, 2007
    Nothingis wrong with this if you come from C/C++ background where you are always used to muck up with function pointers. But a whole bunch of C# programmers are not and they completely get lost in these maze
  • Anonymous
    February 27, 2007
    I've done some C++, but have not read anything about lambda. First this code looked really weird to me, but after a while I got the whole call a method which returns a method which you call. However I still do not understand the lambda statement completely. So I do agree  that this will be confusing for a lot of people, me included. I'm not sure I like it either.
  • Anonymous
    March 05, 2007
    Well, it's not the tool's fault that someone abuses a tool.  Would you have the same complain if the same code were written in a more sane fashion:static void Main(string[] args){   Action printit = GetPrinterFunc();   printit(42);}static Action GetPrinterFunc(){   return (T t) =>             {                 Console.WriteLine(t);             };}