I've seen several mentions of "mumble typing," such as this StackOverflow answer: Will a future version of .NET support tuples in C#?
I Googled the term and I couldn't find much in the way of an explanation, other than some people hoping that C# would eventually support it.
What is mumble typing?
I don't know if someone on the C# design team came up with this term, or if it is used elsewhere in the industry. We started using it while working on implicitly typed local variables (that is "var x = whatever;") in C# 3.0. A fairly common scenario is to want the compiler to infer part of a type but be explicit about another part. For example, consider the following:
var list = new List<int>() { 10, 20, 30 };
Here the type of "list" is not given, but the type argument of the generic list is given. One imagines that this could be inferred from the initializer:
var list = new List<???>() { 10, 20, 30 };
Here the ??? means "there's a type argument that goes here; compiler, figure out what it has to be from the context".
We call this "mumble typing" because one humourously imagines the code being read as "var list equals new list of hrmhmrhrm initialized with ten, twenty, thirty."
We never implemented mumble typing, which is a bit unfortunate because it means that it is hard to make a list of anonymous type. To do so, you can use the "cast by example" trick.
I like this link, where the explanation is near the end of the page. Basically, my understanding is that the idea of "mumble typing" is type inference without having to specify the entire type. Now, C# 4.0 does have anonymous types, but there are limitations, some of which are explained in the above link and here.
I think the main problem in C# still is that, when you need to name a type, but you just have an anonymous type, there is no syntax that allows you to specify what you need. For example, this does not work:
List<MyObject> myList = SomeFunctionThatReturnsThisList(someParameter);
var afterTransformation = myList.Select<MyObject, var>(o => new { x = o.x, y = o.y });
You cannot specify var
as a type in a generic. That was a somewhat foolish example, but I hope it conveys the idea that there are syntactic constructions with anonymous types that seem like they should be possible but are not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With