Theme Graphic
Theme Graphic

$jonathan.ramble(topic => 'work' & 'play');

My random-ish ramblings about my work at Programmer's Heaven and on the Parrot project, my crazy conference schedule and whatever else I...

Subscribe

Author

I wrote my first computer program when I was 8 years old, and I haven't bothered to stop since! I graduated from the University Of Cambridge, England, in June 2006 having read Computer Science at Emmanuel College. Currently I'm doing consultancy work, a lot of it for this very site. I'm into a whole range of music, including metal, trance, old skool, and industrial. I'm a Christian and have previously been involved in youth and children's work with what was then my local church.

Archive

Tags

Posted on Monday, February 04, 2008 at 8:25 AM

A wish for C# 4.0


OK, OK, so C# 3.0 is only just out of the door. As anyone who has been reading my stuff for a while will have realized, I like what they've done with the language. Here at PH, we have now fully migrated all our solutions to Visual Studio 2008, and can now use C# 3.0 language and .Net 3.5 framework features everywhere they're useful. This makes me happy (though some annoying issues migrating to Web Deployment Projects 2008 decidedly aren't making me happy).

I haven't thought long and hard about what I'd really like in C# 4.0. I think I need C# 3.0 to settle in a bit more. I've used it quite a bit, but it takes a while to fully realize the power of all that is there, and I certainly don't want to start suggesting additions to the language when there is already a perfectly good solution to that problem.

There are many principles in programming language design. I'm quite heavily influenced by Larry Wall, designer of Perl, probably because I've listened to him talking about language design more than anyone else. One of the principles he has is known as huffmanization. Huffman coding is an approach to compression where you give the most frequently occurring things the shortest codes, so the things that occur most in the file you are compressing have the shortest representations. The analogy in programming language design is things that you do regularly should have a compact syntax, whereas things you do infrequently can be longer - because you do them less.

C# doesn't score badly overall alongside this principle generally, but there is one area that I really feel could use some improvement. How often do you write:
private string _Foo;
And then an accessor and mutator method:
public string Foo
{
    get { return _Foo; }
    set { _Foo = value; }
}
I find myself doing this a lot, and it's 6 lines of boilerplate (OK, only four lines if you ignore the braces, which don't have any understanding cost, but do take up screen space). By contrast, anonymous types let you declare fields and and accessors all in one go (and yes, I know it's a tad different).

What I'd really like is a way, in a single declaration, to declare an underlying private field with either protected, internal or public simple accessors. I'm not sure how it could look, or of some nice syntax for it. I guess an attribute could do it:
[Accessor("Foo", Scope.Public)]
private int _Foo;
Though that's still quite a bit to type. I've still not found any syntax to suggest that I like, though. Ideas, anyone? But anyway, I'd really like to see some improvement here. It's not a Big New Feature, but it would save a lot of trivial, boring code.
Bookmark: Submit To Digg Submit To reddit Submit To del.icio.us Bookmark With StumbleUpon Bookmark With FaceBook Bookmark With Google Bookmarks   Share: Share By Email By Email

2 comments on "A wish for C# 4.0"
Posted by Rudy on Thursday, February 21, 2008 at 12:18 PM
Image Of Author
Accessor
google for C# automatic properties
Posted by Jon on Monday, October 13, 2008 at 2:03 PM
Image Of Author
Automatic Properties?
You could write it in one line using an automatic property:

public int Foo { get; set; }

Leave A Comment
Subject:


Comment:
   Bold Italic Underline          Code Link Image Horizontal Rule


Because you do not have or are not logged in to your Programmer's Heaven account, please enter your name.

Name:


To help prevent comment SPAM, please enter the magic code '378' in the box:




Posting Rules
Please follow these rules when posting comments on blog posts.
  • Do not post anything that is racist, hate speech or of a sexual or adult nature.
  • Do not post or link to anything that infringes copyrighted laws.
  • Posting about security or legal topics is fine so long as you are not glorifying or encouraging people to perform illegal activities.
  • Both the author of this blog and the Programmer's Heaven administrators may delete any inappropriate comments without notice at their own discretion.
 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.