Re: C# 3.0 partial methods and automatic properties
Sébastien Lorion <[email protected]> Wed, 29 Nov 2006 02:20:12 +0800
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
Thanks the pointer! Looks almost as good as The commentator: http://www.cenqua.com/commentator/ Sébastien On 11/28/06, Davy J <[email protected]> wrote: > For the comments try ghostdoc, takes the pain out of commenting procedures. > > Dave, > > On 11/23/06, Sebastien Lorion <[email protected]> wrote: > > - Very rarely is there a need to override the behavior of the "event" > > keyword (mostly when the class has many events, needs weak referencing on > > its delegates and/or locking issues). > > > > - We declare variables *all* the time and with generics, the syntax of doing > > so becomes quite cumbersome with never ending lines. Until C# 3.0, you can > > use a trick, which is to use an import statement: > > > > using FooDictionary = System.Collections.Generic.Dictionary<string, > > System.Collections.Generic.Dictionary<string, MyNamespace.Foo>>; > > // or using StringFooDictionary = ... > > > > > > Now for properties, none of the above applies. Except for the most simple > > getter/setter, you need to put more logic in your properties. YMMV, but for > > me, this happens quite a lot, if for no other reason than to raise a > > PropertyChanged event. So the usefulness of the new syntax seems marginal, > > at least in regards to the features you mention. > > > > Really, I think there are areas that need much more attention at this > > moment. > > > > Like the current need to duplicate XML comments everywhere. How great would > > it be if the IDE by default would take the comment on the base/interface > > method and we only need to override as needed? We can put documentation in > > separate files for that, but A) that does not solve the problem when the doc > > is from an external library, B) I like to see my comments inline period. > > > > And what about exceptions? Aren't you tired of writing > > > > /// <exception cref="ArgumentNullException"> > > /// <paramref name="bar"/> is a null reference. > > /// </exception> > > void Foo(object bar) > > { > > if (bar == null) > > throw new ArgumentNullException("bar") > > } > > > > I know I most certainly do! At least, if Intellisense would filter out types > > after we write "throw new " to show only exception types (ending with > > "Exception") like it does for attributes. A solution would be to integrate > > now the "easy" parts of Spec# into C#, such as the "!" type operator: > > > > void Foo(object! bar) > > { > > } > > > > I have many many peeves like this that are not complicated to do (I think) > > and would diminish a lot the bookkeeping programming. > > > > Sébastien > > > > > -----Original Message----- > > > From: Discussion relating to the specifics of the C# and Managed C++ > > > languages [mailto:[email protected]] On Behalf Of Keith > > > Hill > > > Sent: Thursday, November 23, 2006 3:01 AM > > > To: [email protected] > > > Subject: Re: [DOTNET-CX] C# 3.0 partial methods and automatic > > > properties > > > > > > > -----Original Message----- > > > > From: Jon Skeet [mailto:[email protected]] > > > > Sent: Saturday, November 11, 2006 12:23 AM > > > > Subject: Re: C# 3.0 partial methods and automatic properties > > > > > > > > Creating a code snippet or a macro or whatever has a problem in terms > > > of > > > > readability though. Let's take another example of syntactic sugar: > > > > "using". I'm sure that Eclipse can add a try/finally block round my > > > Java > > > > code easily, but I'm *much* happier reading C# code with the "using" > > > > statement. > > > > > > > > Similarly, it's easier to read: > > > > > > > > public property string x; // Or whatever the syntax is > > > > > > > > than the "longhand" version, even if that longhand version *has* been > > > > generated for you. > > > > > > > > Typing speed is rarely an issue for me, but quickly reading and > > > > understanding code often is. > > > > > > I agree. The VS IDE doesn't help when I'm reading code nor does it > > > help when I write code outside of the IDE (yes I sometimes use notepad). > > > I think the automatic property feature complements the "event" keyword > > > which essentially does the same thing - create a private field > > > (delegate) and generates the Add/Remove methods for you. In both cases, > > > if you need more functionality, then you don't use the feature i.e. > > > write your own get/set or add/remove methods. > > > > > > The other issue I think that C# needs to stay on top of is remaining > > > competitive with various dynamic languages. There is a *lot* less line > > > noise in languages like Ruby and Python. Check out this MSDN article > > > on IronPython: > > > > > > http://msdn.microsoft.com//msdnmag/issues/06/10/clrinsideout/default.as > > > px > > > > > > Dynamic languages like Python are popular for a reason - their syntax > > > doesn't get in the way as much, requiring a lot less typing (keyboard > > > typing). By the way I don't agree with the statement in the article > > > that the line noise in C# is necessary. There are places where it > > > isn't. Take for instance the new type inferencing/var feature in C# > > > 3.0. I think this can help reduce line noise a fair amount e.g.: > > > > > > Dictionary<string,Dictionary<string, Foo>> bar = new > > > Dictionary<string,Dictionary<string, Foo>>; > > > > > > versus > > > > > > var bar = new Dictionary<string,Dictionary<string, Foo>>; > > > > > > The automatic property syntax is just another step in the direction of > > > eliminating unnecessary line noise. What I like about these features > > > is that you get some of simplified syntax found in dynamic languages > > > without giving up static type checking and the features that go along > > > with it like Intellisense. > > > > > > BTW, it's interesting that the C++ team thought the simplified property > > > syntax idea worthy enough to add to the managed extensions for C++. > > > > > > -- > > > Keith > > > > > > =================================== > > > 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(r) http://www.develop.com > > > > View archives and manage your subscription(s) at http://discuss.develop.com > > > > > -- > Dave Jones > [email protected] > [email protected] > > b1xml2 : "The one thing that is differentiates VB.NET from C# is the > horrible ability to do this turn Option explicit and strict off, after > which VB.NET can resemble mangled spaghetti. " > > =================================== > This list is hosted by DevelopMentor(r) 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