Thursday, March 29, 2007

C# 3.0 inches towards Ruby

On Scott Guthrie's blog he talks about new features in C# 3.0. My first thought on seeing some of these is, "Gee, it's looking kinda Ruby-ish."
The new automatic properties get rid of
public string LastName {
get {
return _lastName;
set {
_lastName = value;
and replace with the much more succinct,
public string LastName  { get; set; }

Which is a backing into the Ruby attr_accessor function.

attr_accessor :last_name

The main difference is that in Ruby attr_accessor isn't part of the core language, it's just a helper function that anyone could add.
Also the new object initializers,

Person person = new Person { FirstName="Scott", LastName="Guthrie", Age=32 };

Look so similiar to the Ruby style of passing in a hash of values.

my_func (FirstName=>"Scott", LastName=>"Guthrie", Age=>32)

These are great new changes in C# as we travel towards the Ruby Way.

No comments: