PC Review


Reply
Thread Tools Rate Thread

C# Language Specification - Extension Methods

 
 
=?Utf-8?B?TWFyc2hhbA==?=
Guest
Posts: n/a
 
      20th Sep 2005
I think one of the major advancements on C# will be the growing support for
Extension Methods and related concepts...

The current syntax involves a static class with static members using a
warping of the "this" concept applied to function parameters. Surely we'll
see more twisting and warping of language semantics as this technology
evolves...

Rather than warp language symantics... It would be more apparently proper to
allow something like:

(** Proposed syntax:
public class global::System.String {
public static string Encrypt(object key) { ... }
}
**)

Something generally synonymous with partial types... saying, hey look, you
can even partialize an existing type. People will ooh and ahh over it... I
can hear you doing it now as you prepare your rebuttle. Initially only static
members would be allowed, but you could then provide support for more things
without ever warping language concepts.

Currently, we have to teach... "this" means "this", unless it's on a
parameter in an extension class, in which case it means "that".


 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      20th Sep 2005
Marshal,

Unfortunately, the argument doesn't hold. "global" is a language
concept in C#, and you are proposing changing that. Granted, it's not as
ubiquitious as "this", but it is still the same thing.

The same thing applies to other keywords as well. Return doesn't always
mean return. What happens when it is used in an attribute declaration, or
with yield?

It's like anything else, what it means depends on the context it is used
in.

The reason they chose "this" (at least as I see it) was twofold. The
first was to give some sort of indication that the extension method would be
applied to instances. "this" helps convey the idea of an instance pretty
well. The second was to help not introduce new keywords into the language
so as to reduce conflicts with pre-existing code. Your example in this case
helps prevent that as well, so it's applicable here. However, I don't see
"global" as a good way of saying "this should be applied to an instance".


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Marshal" <(E-Mail Removed)> wrote in message
news:4C3D27F0-FB4C-42E2-BF8D-(E-Mail Removed)...
>I think one of the major advancements on C# will be the growing support for
> Extension Methods and related concepts...
>
> The current syntax involves a static class with static members using a
> warping of the "this" concept applied to function parameters. Surely we'll
> see more twisting and warping of language semantics as this technology
> evolves...
>
> Rather than warp language symantics... It would be more apparently proper
> to
> allow something like:
>
> (** Proposed syntax:
> public class global::System.String {
> public static string Encrypt(object key) { ... }
> }
> **)
>
> Something generally synonymous with partial types... saying, hey look, you
> can even partialize an existing type. People will ooh and ahh over it... I
> can hear you doing it now as you prepare your rebuttle. Initially only
> static
> members would be allowed, but you could then provide support for more
> things
> without ever warping language concepts.
>
> Currently, we have to teach... "this" means "this", unless it's on a
> parameter in an extension class, in which case it means "that".
>
>



 
Reply With Quote
 
=?UTF-8?B?TGFzc2UgVsOlZ3PDpnRoZXIgS2FybHNlbg==?=
Guest
Posts: n/a
 
      20th Sep 2005
Marshal wrote:
> I think one of the major advancements on C# will be the growing support for
> Extension Methods and related concepts...
>
> The current syntax involves a static class with static members using a
> warping of the "this" concept applied to function parameters. Surely we'll
> see more twisting and warping of language semantics as this technology
> evolves...
>
> Rather than warp language symantics... It would be more apparently proper to
> allow something like:
>
> (** Proposed syntax:
> public class global::System.String {
> public static string Encrypt(object key) { ... }
> }
> **)
>
> Something generally synonymous with partial types... saying, hey look, you
> can even partialize an existing type. People will ooh and ahh over it... I
> can hear you doing it now as you prepare your rebuttle. Initially only static
> members would be allowed, but you could then provide support for more things
> without ever warping language concepts.
>
> Currently, we have to teach... "this" means "this", unless it's on a
> parameter in an extension class, in which case it means "that".
>
>


And how would this be any less "warping" than the already proposed
syntax? Adding a new "global" keyword and a "::" operator?

Wasn't it you that earlier was against introducing "where" as a new
keyword? How's this different ?

If we're going to talk about new syntax for this, as well as introducing
new keywords, then I like the following better (which I saw somewhere
recently):

public class extend System.String { ....

--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
private.php?do=newpm&u=
PGP KeyID: 0x2A42A1C2
 
Reply With Quote
 
=?Utf-8?B?TWFyc2hhbA==?=
Guest
Posts: n/a
 
      20th Sep 2005
> public class extend System.String { ....

I like it... anything that reuses the concept of "partial types", or reuses
any existing concepts. As far as I know, "global", and "::" are official
elements already. The importance of them are to facilitate something like an
absolute scope versus a relative scope based on existing using statements.
 
Reply With Quote
 
=?Utf-8?B?TWFyc2hhbA==?=
Guest
Posts: n/a
 
      20th Sep 2005
I have always thought that static members should be accessible from instances
as well. I can keep them straight via strong naming and would have no
problems.

I recognize the validity of your comments. I do think my warp of "global" is
less severe than their warp of "this" however.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Common Language Specification Jeff Microsoft Dot NET Framework 1 23rd Nov 2006 05:15 PM
C# Language Specification - Chat =?Utf-8?B?TWFyc2hhbCBbRGlyZWN0WCBNVlAgMjAwM10=?= Microsoft C# .NET 0 22nd Sep 2005 12:39 AM
C# language specification 3.0 =?Utf-8?B?amlt?= Microsoft C# .NET 1 13th Jun 2005 11:55 PM
*** New C# Language V2.0 Specification Now Available *** Eric Gunnerson [MS] Microsoft C# .NET 42 1st Nov 2003 07:10 PM
Ecma-334 C# Language Specification Tony Whitter Microsoft C# .NET 6 12th Oct 2003 11:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:40 AM.