Mitch Denny has a post about his feature request for the next version of C#
he wants to have a shortcut to format strings, which would basically allow you to go from this
string s=string.Format(”{0}{1}{2}”, a, b, c);
to this:
string s=@(”{0}{1}{2}”|a|b|c);
I don't think I like the proposed alternative, all you are doing is replacing the "," with the "|" character and making the name shorter.
You could always write your own little wrapper:
//*** you could call it "f" if you wanted
static string fmt(string format, params object[] parameters) {
return string.Format(format, parameters);
}
and get
string s=fmt("{0}{1}{2}",a,b,c);
which is almost the same as the proposed solution
another problem is that this proposal solves a very particular problem which is string formatting and we can get pretty much the same by writing our own little wrapper
but anyway, it gave me an idea for my own feature request
comma-less arguments
string s=fmt("{0}{1}{2}" a b c);
The scope of this change is much wider and actually "desugars" the language
now this change will most likely not happen, since this is a C family language and would take a significant change to the parser but this is my own wish/feature request so there you have it
Thursday, January 10, 2008
Subscribe to:
Post Comments (Atom)
1 comment:
Yes, I have a wish for the next C#. I even mailed to "Ask a language designer" (http://msdn2.microsoft.com/en-us/vcsharp/aa336810.aspx) half a year ago to get some feedback (but I never got any response).
My wish basically is to have support for getting type, property, and method names at compile time. More and more I find myself in the situation that I want to refactor my object model, while properties of these objects are bound to the interface using hard coded strings. And when refactoring the code, those hard coded strings (of course) won't get refactored.
So my proposal was a nameof keyword that could be used like the currently existing typeof keyword, but resolves the name of a property or function during compile time. The syntax I proposed was the following:
string typeName = typeof(MyClass).FullName;
string methodName = nameof(MyClass.MyMethod(int, double));
string propertyName = nameof(MyClass.MyProperty);
Post a Comment