Live data from Hacker News

What's New in C# 6.0 [video]

channel9.msdn.com

111–120 of 145 posts

Re: What's New in C# 6.0 [video]

#111
So these lines are now equivalent:

   public override string ToString() { return String.Format("({0}, {1})", X, Y); }
   public override string ToString() => "(\{X}, \{Y})"
Could it go even further? This isn't paper after all, on screen why shouldn't it look like;

   public override string ToString() => "(X, Y)"
where the X and Y are either slight italics or underlined or colored to indicate they mean X and Y the variable not X and Y the letters. The IDE would let you just toggle the state between 'variable' and 'literal' with the keyboard.

We also get better array initializers:

  public JObject ToJson() {
    var r = new JObject();
    r["x"] = X;
    r["y"] = Y;
    return r;  
  }
becomes:

  public JObject ToJson() => return new JObject() { ["x"] = X, ["y"] = Y };
That's cool! Next comes the null-conditional operators:

  public static Point FromJson(JObject json)
  {
     if (json != null &&
         json["x"] != null &&
         json["x"].Type == JTokenType.Integer &&
         json["y"] != null &&
         json["y"].Type == JTokenType.Integer)
     {
         return new Point((int)json["x"], (int)json["y"]);
     }
     return null;
  }
Becomes...

  public static Point FromJson(JObject json)
  {
     if (json?["x"]?.Type == JTokenType.Integer &&
         json?["y"]?.Type == JTokenType.Integer)
     {
         return new Point((int)json["x"], (int)json["y"]);
     }
     return null;
  }
The check against JTokenType.Integer is just to avoid a casting exception. The null checks are just to avoid null exceptions. I wonder if the compiler could ever handle something like 'this if you can, else null', without actually having any exceptions getting throw and caught underneath:

  public static Point FromJson(JObject json) => 
      return new Point((int)json["x"], (int)json["y"]) ?: null;

Re: What's New in C# 6.0 [video]

#112

Earlier quoted context omitted.

F# module == C# static class. What is the problem?

static classes and namespaces seem to have a lot of overlap now. Static partial classes can almost completely replace namespaces now.

So F# modules is an unnecessary concept too?

Re: What's New in C# 6.0 [video]

#113
post #24

Earlier quoted context omitted.

I thought that native compilation was only for "Windows Store" apps. Do they now have that available for regular Windows desktop apps too (or more importantly, server-side Linux apps)?

I haven't played with it much, but it says in the FAQ[1] : "Will Server/Desktop apps benefit from .NET Native and/or the Compiler in the Cloud? Desktop apps are a very important part of our strategy. Initially, we are focusing on Windows Store apps with .NET Native. In the longer term we will continue to improve native compilation for all .NET applications." [1] http://msdn.microsoft.com/en-US/vstudio/dn642499.aspx

I'd love to be able to write drivers in c#.

Re: What's New in C# 6.0 [video]

#114
post #106
post #76

Earlier quoted context omitted.

Go would fit that definition quite nicely as well. It may be worth adding to your list of things to check out.

Better do it before checking out C#....

Thanks exch and pjmlp, I will check out Go before C#

Re: What's New in C# 6.0 [video]

#116
post #60
post #18

While all of the changes look nice in terms of writing less code, they are the kind of syntactic sugar I learned to hate in CoffeeScript. Mostly because the code was so much denser and harder to read. Especially when reading other people's code. As I write more and more code, the more I want simplicity and ease of understanding over typing a few less characters or having more elegant code.

I'm with you, both for your reasons and for another: it makes code harder to teach. "Oh, you'll see this. And this. And this . . . There's this, but no writes it that way. This is idiomatic." There's some of this in all languages, of course, but "this bit of sugar will make the code cleaner and easier to read" assumes that everyone will adopt a new set of idioms wholesale (which they usually don't).

I have spent a large portion of my career teaching new developers. I think C# is a pretty terrible first language already. The sugar here and there is nothing compared to the massive mental burden of OO, inheritance, compilation, DLLs, Visual Studio, etc etc etc.

Scheme, via SICP, is much easier to get started with, and one can learn the basics with that quickly (including getting much more comfortable with the sequence abstractions -called LINQ in .NET- than even the average .NET developer).

All these reasons are also why I greatly prefer F#. If you stay away from much of the OO system, F# is much simpler to teach in my experience. At my company right now another team is putting together an F# training program intended to teach our QA automation.

Re: What's New in C# 6.0 [video]

#118

Earlier quoted context omitted.

static classes and namespaces seem to have a lot of overlap now. Static partial classes can almost completely replace namespaces now.

So F# modules is an unnecessary concept too?

Judging from at least the implementing code, "using static classes" in C# and "opening modules" F# are the same operations.

But we're talking about C# here, not F#. F# is a fine language, but not pertinent to any project I'm working on right now.

Re: What's New in C# 6.0 [video]

#119

Earlier quoted context omitted.

To be fair, the first time I saw this was in Groovy, almost ten years ago.

What is this called? It's impossible to google for

The "Safe Navigation Operator" - http://groovy.codehaus.org/Operators

Re: What's New in C# 6.0 [video]

#120
post #111

So these lines are now equivalent: public override string ToString() { return String.Format("({0}, {1})", X, Y); } public override string ToString() => "(\{X}, \{Y})" Could it go even further? This isn't paper after all, on screen why shouldn't it look like; public override string ToString() => "(X, Y)" where the X and Y are either slight italics or underlined or colored to indicate they mean X and Y the variable not…

>where the X and Y are either slight italics or underlined or colored to indicate they mean X and Y the variable not X and Y the letters. The IDE would let you just toggle the state between 'variable' and 'literal' with the keyboard.

A big nope from me.

Nicer visual representation is OK.

Changing syntax based on visual attributes it's not.

Post reply on HN