When C# Dresses Up Like Ruby
blog.wekeroad.com
blog.wekeroad.com
I am currently working on a Silverlight app using RIA Services. Here on the server side you have to have each CRUD method for each type you are surfacing. You can't do
public IQueryable<T> Get<T>() { }
It has to be public IQueryable<Foo> GetFoos() { }
public IQueryable<Bar> GetBars() { }
Same with all update, insert and delete methods. It drives me insane that I literally have several thousand lines of CRUD methods. Can some kind of dynamic solution jump in here and help? I doubt it, but I can dream. (Generics don't work here because RIA services can't support sending generic arguments across the wire).I've found MS's less-typed APIs like MVC to be more annoying to use. Taking "object" everywhere? Just means the tools (IntelliSense/compiler) can't provide the info I need, and I'm forced to go read documentation for small things.
Especially silly is the whole "use an anonymous type as a dictionary" idea. (E.g, SomeFunction(new { width=100, height=200, style="bla"}). The only reason I can see a need for this is because the language doesn't have handy list/sequence and tuple syntax.
There are good places for using dynamic typing. Unfortunately, it seems MS is mainly doing it for interop and as a patch for other annoyances.
In C# you can make your objects implement IDynamicObject with this signature ...
public interface IDynamicObject {
MetaObject GetMetaObject(Expression parameter);
}
That returned MetaObject is responsible for defining the runtime dispatching, and you can do it however you want. The "binders" defined in MetaObject are returning Expressions, which means that the DLR library also has a chance to do inline caching.F# uses the same API.
> Just means the tools (IntelliSense/compiler) can't provide the info I need, and I'm forced to go read documentation for small things.
Yeah, reading documentation in this day and age. The horror!
As far as reading documentation, I shouldn't be forced to lookup tiny things here and there because an API decides to use object type for each parameter.
Is it only to support interop with dynamic languages (Iron*)?
I'm not against the idea but it seems like a minor use-case to add a major language feature for. Unless there's something else I'm missing.
In the past, C# added new language features in order to support some specific goal.
Extension methods, lambdas and expression trees were added mainly to support LINQ. They're good features on their own, for sure, but the reason they were added is because the language team wanted to do LINQ.
What's the larger goal here?
I've been fortunate enough to avoid having to interop with COM that directly recently, so haven't had to find out whether or not it makes a difference.
http://msmvps.com/blogs/jon_skeet/archive/2009/11/17/where-d...
COM interop is a popular culprit for this subject too.
Another possibility, although one that is somewhat dimmed by the virtual demise of Iron* within Microsoft, is that Microsoft wanted C# to be able to interop with other dynamic languages like IronRuby and IronPython. I can imagine a scenario where an IronRuby application could pass off a dynamically typed object to a shared library implemented in C# which supported DLR (dynamic language runtime) for some set of common functionality. I don't know much about what's possible today with respect to CLR objects passing between the DLR and the statically typed portions of the CLR, but I figured it was worth hazarding a guess.