Re: Some notes on C# 3.0 (was RE: [DOTNET-CX] How to overload == for System.Double)

"Bart De Smet [MVP]" <[email protected]> Tue, 6 Feb 2007 17:17:11 +0100
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <008701c74a0a$41e3e050$c5aba0f0$@net>
For your first question, the answer is no: you need to specify the select
clause in a query but expect the compiler to be smart enough to rule out
"select p" when no projection is done.
For the second question, you spotted one of the basic concerns one might
have with extension methods. IMO, the chaining possibility outweighs the
concern of not knowing the static method equivalent. As you say, when
multiple classes extend System.String, you might end up with conflicts
(although you can still escape from it by reverting to the static method
call syntax = "desugaring" the syntax). Take a look at
http://community.bartdesmet.net/blogs/bart/archive/2006/12/10/C_2300_-3.0-Ex
tension-Method-Versioning-Troubles-_2D00_-Some-thoughts-and-random-ideas.asp
x for some of the issues that might arise and some random thoughts around
it.

-Bart

-----Original Message-----
From: Discussion relating to the specifics of the C# and Managed C++
languages [mailto:[email protected]] On Behalf Of Alan Baljeu
Sent: dinsdag 6 februari 2007 16:50
To: [email protected]
Subject: Re: [DOTNET-CX] Some notes on C# 3.0 (was RE: [DOTNET-CX] How to
overload == for System.Double)

> Sure here we go. This is what the compiler does consecutively:
>
> > IEnumerable<string> selectedWords =
> >  from p in EinsteinQuote
> >  where p.Equals("any") != true
> >  select p;
>
> becomes (using lambda expressions)
>
> > IEnumerable<string> selectedWords =
> >  EinsteinQuote.Where(p => p.Equals("any") != true).Select(p=>p);

Now this form makes sense!  But as you say, the Select(Identity) call is
pointless so it
could be dropped.  Can I also write
  from p in EQ where p.Equals("any") != true
?

> Which allows you to write something like this:
>
> string r = s.ToUpper().Reverse().Trim().PadLeft('*',
> 9).Substring(1,5);
>
> whereas in the past you'd have to write:
>
> string t = s.ToUpper();
> string r = MyExtensions.Reverse(t).Trim().PadLeft('*',
> 9).Substring(1,5);
>
> effectively breaking the convenient call chain.

Try:

string r = MyExtensions.Reverse(s.ToUpper())
   .Trim().PadLeft('*', 9).Substring(1,5);

I do find it troubling that these extensions allow you to access Reverse
without even naming
the class it is defined in.  This seems to be a great source of potential
name polution.
What's going to happen after several classes extend string?

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com