News for hackers. Stuff that matters.
Re:A Preview of C# 8 [video] by bouke on Friday August 25, 2017 @12:03PM (#15099468)
Great to see these Swift features[1] appearing in C#:

* Nullable Reference Types This makes it so much easier to reason about references. I always found it strange that C# had nullability on value types, but not on reference types.

* Default Interface Implementations Inherit an interface, and get an implementation "for free". This makes for a very powerful way to define interfaces and default implementations.

* Extension Everything As noted in the video/text, the current syntax feels a bit weird -- having to use a static class.

[1]: Not saying these are exclusive to Swift, or Swift was the first to implement them.

Re:A Preview of C# 8 [video] by judah on Friday August 25, 2017 @12:16PM (#15099596)
In the video, Torgersen says the nullability feature was inspired by TypeScript. Torgersen says he consulted TypeScript creator Anders Heijlsberg to build the nullable reference feature.

As a heavy TypeScript user myself, it was easy to see the parallels between the designs: question mark nullability, the compiler-enforced nullability checks rather than runtime-enforced, "dammit operator" to override the compiler. All shared between TypeScript and C#.

I love this feature in TypeScript; it's help me find numerous bugs and helps me reason about my code. I'm looking forward to using it in C#.

Re:A Preview of C# 8 [video] by thavalai on Friday August 25, 2017 @12:27PM (#15099706)
Just wanted to point out that besides creating Typescript, Anders has been the Lead Architect on C# since 2000.
Re:A Preview of C# 8 [video] by MadsTorgersen on Sunday August 27, 2017 @07:52PM (#15113501)
For the past couple of years I have been the lead designer of C#. Anders and I took a break to help create TypeScript, and then he stayed on as it's lead designer, while I returned to take over C#.

Anders and I meet every week to compare notes, and I make sure to get his input on major new features in C#.

Re:A Preview of C# 8 [video] by pjmlp on Friday August 25, 2017 @01:11PM (#15100246)
Apparently he is mostly focused on Typescript nowadays, and not so much on C#, although he still participates on its development.

At least given his latest interviews on Channel 9 and BUILD sessions.

Re:A Preview of C# 8 [video] by vram22 on Friday August 25, 2017 @06:51PM (#15102896)
He was also the original author of Turbo Pascal and the chief architect of Delphi.

https://en.wikipedia.org/wiki/Anders_Hejlsberg

Re:A Preview of C# 8 [video] by wvenable on Friday August 25, 2017 @12:39PM (#15099852)
> I always found it strange that C# had nullability on value types, but not on reference types

Version 1.0 of C# was the same as Java: Nullable reference types and non-nullable value types. Nullable value types didn't come until version 2.0 but at that point ir was too late to make reference typed non-nullable.

I'm glad they're actually putting the effort to fix this issue now. It's a huge task given the amount of legacy code out there.

Re:A Preview of C# 8 [video] by nickspag on Friday August 25, 2017 @12:33PM (#15099780)
I am so, so excited for Default Interface Implementations. Abstract classes are great but when you want (have) to go down a different inheritance tree this will be so nice.
Re:A Preview of C# 8 [video] by c0wb0yc0d3r on Friday August 25, 2017 @02:54PM (#15101152)
With the introduction of this feature, is that the only difference between the two?
Re:A Preview of C# 8 [video] by int_19h on Friday August 25, 2017 @08:23PM (#15103348)
Abstract classes can have state, default interfaces can only have behavior. So state is still single-inheritance, while behavior is effectively multiple-inheritance now.
Re:A Preview of C# 8 [video] by dep_b on Friday August 25, 2017 @12:10PM (#15099532)
Swift extensions do not have the ability to add variables to the scope of the class they extend or into their own private scope. Perhaps because the compiler times would crash through the roof but I find it very limiting. I do use extensions in Swift but I prefer to factor out any code into it's own class once it needs to touch any kind of state.
Re:A Preview of C# 8 [video] by perfectstorm on Friday August 25, 2017 @06:41PM (#15102844)
In Obj-C extensions you can add variables with the help of Obj-C runtime.
Re:A Preview of C# 8 [video] by bernadus_edwin on Friday August 25, 2017 @01:05PM (#15100170)
Nullable reference without "if let" keyword is disaster
Re:A Preview of C# 8 [video] by MadsTorgersen on Sunday August 27, 2017 @07:57PM (#15113522)
"If let" could be easily mirrored by a pattern in C#, and we are starting to discuss that.

However, that's a new way to check for null in the language, where what we need is to recognize the ways people are already checking for null in billions of lines of code. Therefore, the priority is to do a good flow analysis that will just understand when a nullable variable can be assumed to not be null (e.g. after a check, a non-null assignment, etc.), and then let you dereference without challenge.

Re:A Preview of C# 8 [video] by bernadus_edwin on Tuesday August 29, 2017 @06:26AM (#15123319)
If c# 8 has good flow for checking null, then no need "if let". If let also has disadvantage, backward compartibility. For example, maybe i want change my logic class to c# 2
Re:A Preview of C# 8 [video] by hungerstrike on Friday August 25, 2017 @02:24PM (#15100913)
"If let" leads to code that is hard to read IMO. I'd rather be able to easily tell the difference between conditional statements and assignments.

Another Swift feature that I think leads to very poor readability is trailing closures.

Re:A Preview of C# 8 [video] by bernadus_edwin on Saturday August 26, 2017 @01:03AM (#15104154)
Without if let, you must add one line for declare local variable. And also must add exclamation mark
Re:A Preview of C# 8 [video] by wuzzard on Monday August 28, 2017 @04:31PM (#15119824)
C# 7.0 already has the 'is' pattern matching operator that returns true/false and can introduce a new variable that is not null.
Re:A Preview of C# 8 [video] by zerr on Friday August 25, 2017 @01:47PM (#15100582)
> Default Interface Implementations

So basically multiple inheritance?

Re:A Preview of C# 8 [video] by aardvark179 on Friday August 25, 2017 @02:18PM (#15100861)
For method lookup, but not for object structure. That's really important from an implementation viewpoint because field accesses can just be done as a simple offset without any complexity round the type.
Re:A Preview of C# 8 [video] by jaredpar on Friday August 25, 2017 @08:17PM (#15103318)
It's multiple inheritance of behavior, but not of state.
Re:A Preview of C# 8 [video] by sandyarmstrong on Friday August 25, 2017 @01:56PM (#15100670)
Except for state...