Freigeben über


Don't Believe Everything you Read on Wikipedia, especially about C# Anonymous Functions

I was reading Wikipedia the other day, and saw this:

C# has partial anonymous function support through the use of delegates. ... Since anonymous methods are not nameless and can only be declared inside methods of classes then C# does not support full anonymous functionality.

Hmph, who's in charge here?  I don't really feel any ownership for Wikipedia, but that is just bad info.  So I rewrote it.

The updated entry, including the comments on C#, is here: https://en.wikipedia.org/wiki/Anonymous_function

If you want to read all about the anonymous function support added in C# v3.0, then go the the source - MSDN.

Leads me to a couple other notes here.

First, yes, I agree it is a pain that the language compiler version has a different version than the framework.  So we have C# 3.0, but it shipped with the .NET Framework v3.5.  Confused?  You should be.  All I can say is, we apologize.  there are good reasons we are confusing you.  We're not doing it on purpose, it just works out that way.

Second, at first I approached the new C# language stuff with a little trepidation.  I mean, lambdas?  Extension methods?  All of this stuff sounds a little esoteric.  But after exploring a little bit, I have found good uses for these new language constructs, even outside the coolness that is LINQ.  It's the little things.  For example, I can convert a version string like 1.2.3.4 into a List<int> with a single line of code, using the ConvertAll() method and a lambda expression.

That kind of thing is just pretty cool.   Also I use the object initializers all the time now.

Last, I wonder how much of the wikipedia thing works this way - people just feel like they don't want bad info out there, and are sort of transparently taxed into writing the articles themselves.  This is sort of like trash collection in Seattle.  When I lived in Pennsylvania, trash collection was just included in the taxes, and you could throw anything away.  I could put a used car on the curb with a note on the windshield saying "Trash", and the trash man would come and haul it away.  But in the Seattle area, you can't throw just anything away.   There's a limit.   If you want to discard an appliance, for example, you have to take it to the dump yourself. 

There's something to be said for the Pennsylvania model - basically it means that there's no reason to be a "bad actor" and throw trash out in an empty lot.  Whatever you want to throw out, they'll haul away.  It's taken care of for you.  (Like Encyclopedia Britannica).  On the other hand the Seattle approach means people who discard a lot of stuff, have to pay more, and make more of an effort.  (like Wikipedia).

Well I'm obviously rambling now. . .

Comments

  • Anonymous
    March 31, 2008
    I don't think you really have to appologize that the .NET version number is different then that of C#. C# is not really the same as .NET. The C# compiler does not have to be updated everytime .NET is updated and vice versa. .NET has a CLR (Common Language Runtime) which means a lot of languages can use it and build libraries against it. VB by the way is at version 9.

  • Anonymous
    March 31, 2008
    Thanks eilert.  What you say is exactly right:  the compiler is different from the CLR which is different than the libraries.  I am apologizing only for the confusion that the various distinct version numbers can cause.

  • Anonymous
    March 31, 2008
    Still doesn't look quite right, "employs the creation of a static function within the class", while true sometimes is not correct when the Anonymous Function is a Closure. With a Closure the the Anonymous Function is implimented via a instance method on a compiler generated class.

  • Anonymous
    April 01, 2008
    I think the point that you are missing is the beauty of wikipedia.  Granted, you must take what you read there with a grain of salt...but you were able to fix the entry :-).  Try doing that with an "Encyclopedia Britannica".

  • Anonymous
    April 01, 2008
    Oh, you're definitely right about THAT.  Wikipedia can potentially get fixed, eventually.  The problem is, (a) between now and then is potentially a very long time, and (b) there is no clear indicator that the Wikipedia article is accurate or not.  Who's to say?  Currently I think it is "last writer wins".  For example, someone followed up my edits with some further edits saying that C#'s use of a compiler to generate a static method on a class, was not an example of a "real anonymous function" because it was not dynamic, in the manner of JavaScript.  This was not a private opinion voiced to me in email, this was an addition to the Wikipedia article.  But there is nothing in the definition of "anonymous function" that says "the implementation must be dynamic, like JavaScript, PHP, or Perl."   I could have followed up with a discussion in the article, or, who knows what, but I decided to just leave it.  I think it is very debatable whether "anonymous function" requires "dynamic."  But that isn't noted in the article (last I checked).  Unless it is policed by an authority, Wikipedia will succumb to the tragedy of the commons.  The article on anonymous functions is just one example. There is some value in the Encyclopedia Britannica, in the same way there is value in having a wise solomon adjudicate a court case versus a jury of my peers, in the same way there is value in giving justices on the Supreme Court lifetime terms. At some point we desire an unassailable and unimpeachable authority.