C# as seen by languages with Type Inference…

by justin 29. December 2009 22:54

via @HamletDRC

tumblr_kvdv7l891W1qz9bgeo1_400[1]

 

Ever since I started playing around with Boo this is exactly how I feel about declaring types for my variables…

C#

IFoo foo = (IFoo)Fetch(arg);

 

Boo

foo = Fetch(arg) as IFoo

 

IFoo only ever needs to be written once on any given line. And if Fetch returned IFoo it wouldn’t need to be written at all. Being explicit is great and all, but being redundant is absolutely not.

Tags: , ,

C# | boo | Software Development

Comments

12/27/2009 11:18:47 AM #

But in C# 3.0 it would be
var foo = Fetch(arg) as IFoo;

Jeff Klawiter |

12/27/2009 11:51:54 AM #

var is a great improvement but it's still not as nice as nothing. Also, where I work we are forbidden from using var except for linq expressions as a matter of code style guidelines.

I use it almost exclusively outside of work though.

justin |

12/27/2009 11:53:36 AM #

Also I just noticed a bug in my above boo code. It should be:

foo as IFoo = Fetch(arg)

That will be a cast as opposed to the code in the original post which would be the same as using the "as" keyword in C#.

justin |

Comments are closed

About Me

sweetest hat ever

I'm a software developer from Minnesota and this blog largely focuses on various technical concepts I am thinking about at the moment. I currently work for Microsoft in the St. Paul office of the Expression product group.

RecentPosts