I'm a tiny bit disappointed with the inclusion of exception filters, but I suppose it is pragmatic feature. I'm fond of a pattern where error codes can be implicitly converted to Exceptions[1]. It's often argued that exceptions are for things that your program cannot handle and error codes are for things that it can. But, in my experience, whether or not a bad condition is an error or an exception depends upon the la…
What's New in C# 6.0 [video]
81–90 of 145 posts
Re: What's New in C# 6.0 [video]
#82I also love the ?. operator.
Re: What's New in C# 6.0 [video]
#83Seems like a small change but that nameof(argument) method for ArgumentXExceptions is incredibly handy.
And also for INotifyPropertyChanged! (Although CallerMemberName helped that some in C#5.)
Re: What's New in C# 6.0 [video]
#84I think they missed a trick if the goal was to reduce boilerplate; which I'm all for, I'm very much moving away from C# to F# for this reason (and a few others). Why this: public int X { get; } public int Y { get; } = 5; And not this: public int X get; public int Y get = 5; The braces serve absolutely no purpose anymore, the semi-colon doesn't serve as a separator between statements. So why leave them?
If you care about clean code, here's an even better way public readonly int X; They are not exactly the same but they are equivalent in most cases. In exotic cases where you're required to use auto-getters, adding the brackets wouldn't hurt.
Re: What's New in C# 6.0 [video]
#85Re: What's New in C# 6.0 [video]
#86I love the new read-only auto properties. 90% of the objects I write are immutable and it's a pain to declare all those private readonly backing fields just to return them in getters.
Re: What's New in C# 6.0 [video]
#87I think they missed a trick if the goal was to reduce boilerplate; which I'm all for, I'm very much moving away from C# to F# for this reason (and a few others). Why this: public int X { get; } public int Y { get; } = 5; And not this: public int X get; public int Y get = 5; The braces serve absolutely no purpose anymore, the semi-colon doesn't serve as a separator between statements. So why leave them?
public int X { get; } is more consistent with how properties are declared. Consistency is important. If you care about clean code, here's an even better way public readonly int X; They are not exactly the same but they are equivalent in most cases. In exotic cases where you're required to use auto-getters, adding the brackets wouldn't hurt.
As mentioned in my other reply. If that were the case, why have they just changed the method declaration syntax? It's inconsistent and therefore unacceptable right? If everything has to be consistent we wouldn't have LINQ, lambdas, generics, etc.
The braces are for scope in C# and all C derivative languages. There is no scope being created here and no requirement for scope. Also there are other places in C# where the scoping braces can be dropped [when there's only a single statement within]:
if(foo == 1)
{
bar();
}
Can be written: if(foo == 1)
bar();
So I don't see the inconsistency at all if they were to drop the braces.> If you care about clean code, here's an even better way public readonly int X
That's what I use. Cue the next round of discussion about fields and properties...
Re: What's New in C# 6.0 [video]
#88Re: What's New in C# 6.0 [video]
#89The null-conditional operators and string interpolation are really cool. I don't use C# anymore (job change, not out of dislike), but I was always really happy working in it. I'm still not a huge fan of Windows, but C# is a wonderful language.
I wonder how string interpolation interacts with translation though? I thought the whole idea of the numbered placeholders was so that you could translate the string and rearrange them for different languages. Now do your translators have to be careful not to break your code if they're editing it as part of the string?
I also expect that a large fraction of applications never gets localised (in-house tools, scientific software, etc).
In total, I think there are orders of magnitude more lines of message formatting code that do not get translated and likely never will be translated.
It appears modern language designers think it worthwhile to make life for that use case a bit easier.
(it is not that the code gets much shorter, but more that, for true translation, you have to move the format string into a resource, and load it from your code)
Re: What's New in C# 6.0 [video]
#90Earlier quoted context omitted.
I knew I'd seen that somewhere before, good call. There's a lot of things in coffeescript I'd love to see in other languages.
To be fair, the first time I saw this was in Groovy, almost ten years ago.