Re:The future of C# and Visual Basic [video]
by danbruc on Monday November 03, 2014 @12:06PM
(#8551908)
That doesn't work for a standard library - it may make you happy, but the next developer may have very different needs. Int32.TryParse() does not distinguish between null and empty strings and it takes only a minute or two to create an extension method and the problem is solved once and forever.
public static class StringExtensions
{
public static Int32? ParseAsNullableInt32(this String self, Int32? fallback = null)
{
Int32 result;
return Int32.TryParse(self, out result) ? result : fallback;
}
}
Re:The future of C# and Visual Basic [video]
by Pxtl on Monday November 03, 2014 @12:55PM
(#8552253)
Yes, that's the obviously implementation, but so many older framework libs that have not been replaced still use serializers that, when given a Nullable type, fail to use that obvious implementation and blow up on empty strings.
In the case of the XML Serializer, that means that if I declare a class with Nullable<int> Foo {get;set;}
and
<Foo />
appears in the XML body, then it blows up. The WebForms stuff is similarly pathetic about empty strings. There is no useful distinction between empty strings and nulls when we're talking about dates or numbers or something like that, so throwing an exception in this case is just plain wrong. It's not even protecting backwards compatibility because pre-2.0 C# didn't even have nullable ints.
Re:The future of C# and Visual Basic [video]
by jameshart on Monday November 03, 2014 @11:54AM
(#8551828)
Likewise Async. The basic file IO and ADO.NET APIs can be wrapped up in awaitable structures but you pretty much have to do it yourself. For most purposes if you really want to make good use of C#'s cleverest language features you have to write wrapper classes around .NET to make it work.
They've also done a terrible job of making a first class Windows UI library for .NET; WinForms was always clunky and limited in the subset of MFC/GDI it exposed; WPF was too radical and didn't make sufficient use of the underlying native capabilities of Windows - and the WinRT story has been confused from day 1.
Re:The future of C# and Visual Basic [video]
by danbruc on Monday November 03, 2014 @12:19PM
(#8551996)
WPF is so much better than (almost) everything else out there (that I am aware of). Yes, it is very different and switching from WinForms is hard to say the least, but it gets so many things right, is extremely powerful and really fun to use once you wrapped your head around it.
Also, I'm constantly frustrated how many core libs freak the heck out over a null string vs. an empty string. Obviously there are places to distinguish those, but if I'm trying to create a nullable int out of the text that is not one of them.