9 ms·
C# 6: First reactions
- AndrewDucker 13y agoIs there a list anywhere of all the new functionality?
- sz4kerto 13y agohttp://damieng.com/blog/2013/12/09/probable-c-6-0-features-illustrated http://damieng.com/blog/2013/12/09/probable-c-6-0-features-i... ... so, in short, nothing definite yet, but the list above should be more or less accurate.
- _random_ 13y agoYes, of course: https://roslyn.codeplex.com/wikipage?title=Language%20Feature%20Status&referringTitle=Documentation https://roslyn.codeplex.com/wikipage?title=Language%20Featur...
- nbevans 13y agoHow tragic it is that VB gets type cases, guard cases and exception filters well before C#. I guess that's why F# is starting to hit the prime time.
- MichaelAza 13y agoSome of these seem undocumented anywhere that I could find. I posted an SO question about some of them, if anyone has any input on the matter: http://stackoverflow.com/questions/22881465/what-do-these-new-c-sharp-6-features-do http://stackoverflow.com/questions/22881465/what-do-these-ne...
- fekberg 13y agoI've written a little bit more about them using the examples from CodePlex on my blog ( http://blog.filipekberg.se/2014/04/04/microsoft-open-sources-c-compiler/ http://blog.filipekberg.se/2014/04/04/microsoft-open-sources... ). There were also some interesting discussions on the C# sub-reddit: http://www.reddit.com/r/csharp/comments/225g4b/microsoft_open_sources_c_compiler/ http://www.reddit.com/r/csharp/comments/225g4b/microsoft_ope... Hope that helps and answers some of the questions you have!
- icambron 13y agoLot of good stuff in there. I don't use C# day-to-day anymore, but I always wanted string interpolation.
- bruceboughton 13y agoI'm not sure of this direction. It looks like a rather large syntax explosion to cover a bunch of corner cases. C# doesn't want to become Perl. That's my initial gut feeling but perhaps that will change. Does anyone know what the dollar syntax is? Similarly, the new dictionary initialiser syntax? Fisnlly, what is private protected? Edit: these are from https://roslyn.codeplex.com/wikipage?title=Language%20Feature%20Status&referringTitle=Documentation https://roslyn.codeplex.com/wikipage?title=Language%20Featur...
- chrisoverzero 13y agoGiven C# Dictionary access as Dict["key"], the equivalent using dollar syntax is Dict.$key. C# Dictionary initialization is currently something like this: var d = new Dictionary<string, string> { { "key", "value" }, { "but this one", "has spaces" } } The new syntaxes appear to be these: var d = new Dictionary<string, string> { $key = "value", ["but this one"] = "has spaces" } (Also, with C# 6's new abilities around constructor type inference, the type parameters may now be superfluous. I'm not certain, though.) The access modifier "private protected" appears to mean "only derived types that are also in the same assembly."
- bruceboughton 13y agoGood explanation, thanks. I don't understand the advantage of the dollar syntax though. One character shorter, and makes it look more object-y, obscuring the perf difference.
- philh 13y ago(Two characters shorter.) At least in python, I would love to have syntax like that. (I would use :: instead of .$, but maybe :: is already used in C#.) Maybe it's just because I work with JSON a fair amount, but I frequently have an it-might-as-well-be-an-object that happens to be stored in a dict. And in theory, this means I need to do foo['bar']['baz'], which is hard to read and unpleasant to type. In practice, I often use a class which overloads attributes as being dict keys, so I can use foo.bar.baz, but this has its own problems. foo::bar::baz would be great.
- zwieback 13y agoLooks good but I don't know if I'll be able to keep these fresh enough in my head to be able to use these things without looking them up. Trying to keep up with the explosion of features in the curly brace languages starts getting really hard. Moving between low level FW (C), desktop apps (C++/C#) and Android (Java) something will have to give, my code will probably continue to just look really 2005-ish. I really like the what the monadic null checking does but aesthetically it looks pretty ugly right now.
- greatdox 13y agoWell it is nice that C# 6 becomes cross platform, can someone please explain to me the license behind it? Microsoft usually does the license thing that takes away some of your rights. Is it the Apache2 license or something else? What are the limitations on this project? Thanks in advance.
- danabramov 13y agoThe new compiler is Apache 2.
- platz 13y agoThis is perhaps a bit trollish but hopefully someone will get some enjoyment out of it. http://tomasp.net/blog/2014/csharp-6-released/ http://tomasp.net/blog/2014/csharp-6-released/
- bananas 13y agoGreat read actually and definitely on topic - thanks for posting :)
- Spearchucker 13y agoNot as familiar with C# as I am VB.Net, but this (the before scenario) strikes me as a little odd (incorrect, or not the whole story, maybe?): Readonly properties require less syntax. Before private readonly int x; public int X { get { return x; } } The only scenarios where I require readonly properties are where I set or otherwise calculate a private variable at runtime, and then enforce readonly to the public getter. In the example above, it looks like the private variable is readonly, and must therefore be initialized with a value that cannot be changed. Am I reading this correctly?
- gnaritas 13y agoYes; they can only be written to by a constructor.
- jksmith 13y agoHjelsberg is continuing the tradition from Delphi that "less is less." Golang, stay disciplined and focused my friend.
- django-fanboy 13y agoWhat ever new feature C# includes, people will still hate it, whatsoever.
- Hominem 13y agoSeems like 6.0 is all about reducing boilerplate. Those default constructors and null checking will probably save me hours of typing as the ctor that does nothing but set stuff and null checking properties all the way down are such common code patterns.
- louthy 13y agoI think Declaration expressions are a mistake and proper support for tuples (and pattern matching) shold have been put in. It feels like an inbalanced expression with the result on the left and the right: var success = int.TryParse(s, out var x); I'm a bit 'meh' about Primary constructors, Auto-property initializers, Getter-only auto-properties. It seems a bit messy and incomplete. Personaly I don't use properties anymore and just use readonly fields with constructor initialisation (which is enough to capture the property setting logic). What I would like to have seen in this area is 'readonly' classes, with mechanisms for cloning objects using named parameters for partial updates: readonly class ReadOnlyClass(public int X, public int Y, public int Z) { } Usage: ReadOnlyClass obj = new ReadOnlyClass(1,2,3); ReadOnlyClass newObj = obj.X = 10; Instead of the current system for creating immutable classes in C#, which becomes quite unweildy and error prone as the number of fields grows. class ReadOnlyClass { public readonly X; public readonly Y; public readonly Z; public ReadOnlyClass(int x, int y, int z) { X = x; Y = y; Z = z; } public ReadOnlyClass SetX(int x) { return new ReadOnlyClass(x, Y, Z); } public ReadOnlyClass SetY(int y) { return new ReadOnlyClass(X, y, Z); } public ReadOnlyClass SetZ(int z) { return new ReadOnlyClass(X, Y, z); } } Usage: ReadOnlyClass obj = new ReadOnlyClass(1,2,3); ReadOnlyClass newObj = obj.SetX(10); I think 'using' static members will be a huge win for creating functions which appear to be part of the language. For example I use the following to do type inference on lambda expressions: static class lamb { public static Func<T> da<T>(Func<T> fn) { return fn; } } var fn = lamb.da( () => 123 ); I'v tried to make it look like part of the language by making it all lowercase, but it's still a little odd. Being able to 'using' a static class in would be perfect for this kind of stuff. To be used sparingly obviously. Expression bodied members, yes please! So pretty... public double Dist => Sqrt(X * X + Y * Y); Typecase and Guarded Cases would be lovely too. Basically anything that enables expression based coding in C#. It would be nice if the LINQ language functions were extended too: count, take, skip, tolist. It's slightly less pretty when having to wrap the expression in brackets to call .ToList();
- Hakeashar 13y ago
- Pxtl 13y agoI looked at this earlier - on the one hand, I like that they're directly tackling known pain-points in the language. The declaration expression "out var x" thing is, imho, great. The TryParse syntax has always been a problem because you have to declare the variable the line before, which means no type inferencing and whatnot. Also, good for casting as they show. Using static is great - finally we've liberated the verbs in the kingdom of nouns. However, some of them have really ugly syntax. I know they wanted to get rid of the boilerplate problem of declaring and setting into a read-only member, but the primary constructor syntax is monstrous - declaring local variables inside of your constructor? Really? I feel like just having a "readonly set" access modifier on properties (both auto and explicit) would have been sufficient. The new dictionary accessor seems silly. Exception filters seem just as pontless in C# as they did in VB (nesting an "if/else throw" into a catch clause wasn't too hard). The crazy null ?. operator I'm unsure about... that one I'll have to use. I've run into the problem enough times to see why they did it, though.
- theflagbug 13y agoException filters aren't pointless. They preserve the stacktrace, meaning the debugger will break at the original throw and not the throw; in your catch (I'm on mobile so I don't have a code sample, sorry, I hope you get what I mean)
- Pxtl 13y agoThrow in a catch block with no exception argument preserves stack-trace. That is catch(Exception ex) {throw;} Rethrows without meddling with ex.
- Locke1689 13y agoThrow in a catch block with no exception argument preserves stack-trace. No it doesn't. If you then let that exception fall out as unhandled, the stack trace will be centered on the second throw, not on the original.
- 13y ago
- Locke1689 13y agoThanks for the feedback, Jon! FYI, we have discussion threads on http://roslyn.codeplex.com http://roslyn.codeplex.com.