TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A Preview of C# 8 [video]

125 pointsby plurbyover 7 years ago

11 comments

Sir_Cmpwnover 7 years ago
Found a text reference: <a href="https:&#x2F;&#x2F;www.infoq.com&#x2F;news&#x2F;2017&#x2F;08&#x2F;CSharp-8" rel="nofollow">https:&#x2F;&#x2F;www.infoq.com&#x2F;news&#x2F;2017&#x2F;08&#x2F;CSharp-8</a>
评论 #15104055 未加载
ajenningsover 7 years ago
Very excited about the Nullable Reference Types.<p>Besides that, the feature I want most in C# is enum exhaustion checking. So I can write:<p><pre><code> enum Color { red, green, blue }; public static string SuperheroFromColor(Color c) { if (c == Color.red) { return &quot;Superman&quot;; } else if (c == Color.green) { return &quot;Green Lantern&quot;; } else if (c == Color.blue) { return &quot;Spiderman&quot;; } } </code></pre> and not get a compiler error (that not all code paths return a value). But if I added &quot;yellow&quot; as an enum option, then I would get a compiler error. I realize that Color can be cast from an out-of-range int, so it&#x27;s a little complicated. I&#x27;m willing to put something extra after the last else:<p><pre><code> unreachable return null; </code></pre> or use a special switch statement. I just want something so the compiler checks that I have accounted for all normal enum values.<p>Is anyone talking about such a feature, or where would I request it? Can I write it myself as a Roslyn extension?
评论 #15187766 未加载
评论 #15104073 未加载
评论 #15102022 未加载
评论 #15103308 未加载
评论 #15101698 未加载
评论 #15101709 未加载
_rmt_over 7 years ago
This looks great. I just stepped back into java for a one off project, after not touching it for about 15 years. I was surprised how antiquated it felt compared to modern C#. Glad to see Microsoft is not letting the language languish.
评论 #15099549 未加载
评论 #15099622 未加载
dep_bover 7 years ago
I&#x27;ll crank up those `null` assignments to non-optional references warnings up to compiler errors. There&#x27;s really no reason to ship software that doesn&#x27;t explicitly declare something as nullable.<p>The `!`&#x27;s are always code smells. I hope I can turn them into warnings or build errors.
评论 #15100535 未加载
评论 #15103321 未加载
boukeover 7 years ago
Great to see these Swift features[1] appearing in C#:<p>* 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.<p>* Default Interface Implementations Inherit an interface, and get an implementation &quot;for free&quot;. This makes for a very powerful way to define interfaces and default implementations.<p>* Extension Everything As noted in the video&#x2F;text, the current syntax feels a bit weird -- having to use a static class.<p>[1]: Not saying these are exclusive to Swift, or Swift was the first to implement them.
评论 #15099596 未加载
评论 #15099852 未加载
评论 #15099780 未加载
评论 #15099532 未加载
评论 #15100170 未加载
评论 #15100582 未加载
joostdevriesover 7 years ago
Interesting, the new type IAsyncEnumerable is like an Observable. But it&#x27;s pull instead of push. Ie it supports backpressure like the Reactive Streams [1] standard in the JVM world. I seem to recall that Erik Meijer had some strong opinions when that standard was forming on backpressure and anything that&#x27;s not purely push based.<p>Personally as a developer I really like having the choice whether to buffer in one place in my system (using a persistent queue f.i.) and have the rest of the system cooperate in tandem without running out of memory f.i. Or to choose to ignore elements when stuff is just going to fast. Etc. I feel more in control of the behaviour under load of my system.<p>I guess Lightbend was onto something when they took the old EAI notion of backpressure (as f.i. described in Gregor Hohpes book) and implemented it in stream processing and started an interoperability standard around it.<p>[1] <a href="http:&#x2F;&#x2F;www.reactive-streams.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.reactive-streams.org&#x2F;</a>
SimonPStevensover 7 years ago
I feel like I&#x27;ve been waiting for non-nullable reference types for forever.<p>What they talk about here, with explicit nullable reference types is so close but stumbles at the last hurdle. Having some kind of opt in on the compiler that makes regular references non-nullable is great for new projects (and arguably the best thing for the language itself), but leaves all legacy code out in the dark. You can&#x27;t switch on a compiler option like this on any big existing project without massive effort. (And massive effort means management approval and planning and justification)<p>They got the case by case opt on the wrong part of the feature. It&#x27;s really the non-nullability of a reference that&#x27;s most important to be able to be opted in to on a case by case basis. (And case by case opt in means low effort, so it doesn&#x27;t need big up front approval or planning, you just get on and write better code with fewer bugs.)<p>What&#x27;s really needed is something like this<p><pre><code> String! s = null; </code></pre> Where the ! makes the s reference non-nullable, so any attempt to assign null (or anything that could be null) to it is a compiler error.<p>And it&#x27;s so disappointing because he comes so so close to that at the end with his talk of s!. as a way to say that you know something is not null, but it just doesnt quite get the benefit right.<p>It&#x27;s non-nullability of reference types that should be the central feature here.<p>I&#x27;m just really hoping that these guys know what they are doing, and it&#x27;s just he couldn&#x27;t explain the subtleties in a short video, and this is going to turn out working the right way in the end.
评论 #15113577 未加载
评论 #15103269 未加载
评论 #15103365 未加载
zwiebackover 7 years ago
Why is default interface implementation controversial? I get it for moving existing .Net functionality around but for development of new code, what&#x27;s the downside.<p>Coming from C++ it seemed like C# interfaces (and Java at the time) felt like a punishment. Now I&#x27;m sort of used to them.
评论 #15103375 未加载
eighthnateover 7 years ago
C# 7 was release a few months ago. The video is just a prototype of what C# 8 could have.
评论 #15100603 未加载
nxc18over 7 years ago
There&#x27;s some interesting and controversial stuff in here. I am very excited about extension everything. I also like the new extension method syntax; much cleaner and a much clearer expression of intent.
评论 #15100675 未加载
评论 #15099423 未加载
daxfohlover 7 years ago
Would &quot;extension interfaces&quot; be equivalent to &quot;type classes&quot; in Haskell and&#x2F;or &quot;traits&quot; in Scala or Rust?
评论 #15113563 未加载
评论 #15100780 未加载