4 ms·
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 s
by bouke 9y ago
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.
- dep_b 9y agoSwift 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.
- perfectstorm 9y agoIn Obj-C extensions you can add variables with the help of Obj-C runtime.
- judah 9y agoIn 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#.
- thavalai 9y agoJust wanted to point out that besides creating Typescript, Anders has been the Lead Architect on C# since 2000.
- pjmlp 9y agoApparently 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.
- vram22 9y agoHe was also the original author of Turbo Pascal and the chief architect of Delphi. https://en.wikipedia.org/wiki/Anders_Hejlsberg https://en.wikipedia.org/wiki/Anders_Hejlsberg
- MadsTorgersen 9y agoFor 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#.
- nickspag 9y agoI 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.
- c0wb0yc0d3r 9y agoWith the introduction of this feature, is that the only difference between the two?
- int_19h 9y agoAbstract classes can have state, default interfaces can only have behavior. So state is still single-inheritance, while behavior is effectively multiple-inheritance now.
- wvenable 9y ago> 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.
- bernadus_edwin 9y agoNullable reference without "if let" keyword is disaster
- hungerstrike 9y ago"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.
- bernadus_edwin 9y agoWithout if let, you must add one line for declare local variable. And also must add exclamation mark
- MadsTorgersen 9y ago"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.
- bernadus_edwin 9y agoIf 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
- wuzzard 9y agoC# 7.0 already has the 'is' pattern matching operator that returns true/false and can introduce a new variable that is not null.
- zerr 9y ago> Default Interface Implementations So basically multiple inheritance?
- sandyarmstrong 9y agoExcept for state...
- aardvark179 9y agoFor 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.
- jaredpar 9y agoIt's multiple inheritance of behavior, but not of state.