C# 7.0 – What to Expect
dotnetcurry.com
dotnetcurry.com
Feature such as With expression has been pushed to version 7+. They have also trim down the ambition of pattern matching for c# 7.
The best way to keep track of C# 7 feature is through their public roadmap https://github.com/dotnet/roslyn/blob/master/docs/Language%2...
3 references
public int Damage { get; }
4 references
public int Durability { get; }
public class Sword(int Damage, int Durability);
This single line will result in a fully functional class: public class Sword : IEquatable<Sword>
{
public int Damage { get; }
public int Durability { get; }
public Sword(int Damage, int Durability)
{
this.Damage = Damage;
this.Durability = Durability;
}
public bool Equals(Sword other)
{
return Equals(Damage, other.Damage) && Equals(Durability, other.Durability);
}
public override bool Equals(object other)
{
return (other as Sword)?.Equals(this) == true;
}
public override int GetHashCode()
{
return (Damage.GetHashCode() * 17 + Durability.GetHashCode())
.GetValueOrDefault();
}
public static void operator is(Sword self, out int Damage, out int Durability)
{
Damage = self.Damage;
Durability = self.Durability;
}
public Sword With(int Damage = this.Damage, int Durability = this.Durability) =>
new Sword(Damage, Durability);
}They are fundamentally different models, though.
F# uses a "cold task" model where invoking an async function returns a specification of work, which you must then start. You can start this work in different ways so that you have control over the semantics of how it executes.
C# uses a "hot task" models, where invoking the async method returns a handle to background work that has already been "kicked off". This is actually an oversimplification, because the semantics of what is actually the asynchronous thing you're awaiting can differ. But the overall concept follows this pattern.
I can't wait to have Async + ValueTask in C# 7 to help reduce the penalty of Async a bit more.
¹ http://www.ps.uni-saarland.de/alice/manual/futures.html
² Well, it used "spawn" instead of "await". The semantics are very similar though.
That was the new idea that suddenly made those decades-old promises useful for the software industry, as it allowed both blocking-style code simplicity and callbacks-style IO scalability.
The ML link says “evaluates the expression exp in a new thread and returns immediately with a future of its result” which translates to “not scalable”.
Also, that's not a new idea. Blocking-style code with async I/O scaling was pioneered by Oz in 1991. (It did it a little bit differently from Alice ML.)
That means outside Windows, asynchronous event-based IO was only possible after 2002 (that’s when the first version of libevent was released).
And yet you’re telling me the ML threads in 2000 were capable of high-performance async IO? You sure about that? In 2000, which kernel API you think that runtime used for IO?
And yes, of course? Erlang could do scalable async I/O in 1988.
Alice ML and Erlang both emulate async I/O by having a few OS level threads each switching between a large number of userspace/VM threads. They queue I/O operations then preempt VM threads when results are ready. For a while that was the only sane way around the clusterfuck that is async I/O on *nix. It still scales fine and I think there's rather little interest in converting either Alice ML or Erlang to libevent/libev/libuv.
¹ The initial Erlang VM was very slow, but the I/O model was there. BEAM was created in 1992 and was fast enough for Ericsson to use in production.
² NT and VMS were both designed by David Cutler, who is more or less the father of asynchronous I/O at the OS level.
³ Incidentally, if you think async I/O in 1977 was advanced, you should look at AS/400 or VOS sometime.
Only 1024 sockets per select because FD_SETSIZE constant? How’s that scales fine? You have 10k sockets = you need 10 native threads, with 10 native stacks, on a quad code machine each of them is guaranteed to be out of CPU cache when IO completes. Not fine, very inefficient.
> there's rather little interest in converting either Alice ML or Erlang to libevent/libev/libuv.
Well, Erlang developers don’t care about windows. And for BSD, Linux and Solaris they already support native event-based async IO for many years. They call the feature “kernel poll”.
> if you think async I/O in 1977 was advanced
I aware on some systems it was widely used. Just not on the mainstream *nix systems where that Alice ML ran in 2000.
BTW you don't really need kernel support for concurrency although it helps a great deal if you have. One way to do it would be to compile coroutines to an eventloop runtime and break read and writes into smaller concurrent chunks.
Edit: I stand by my statement even though I guess pattern matching and immutable types will have to wait for C# 8. The Python-esque tuples allowing for multiple return values without out params or Tuple<> is enough to keep me happy :)
For example, many languages (Python, JavaScript, Scala, C++) already “stole” async-await stuff from C#.
As long as they don’t break IP or patent laws, I don’t see any problems with that.
https://en.wikipedia.org/wiki/Futures_and_promises
The only one that "stole" it was maybe Swift.
It’s compile-time + runtime mechanism that builds those promises from the code that looks like blocking calls (i.e. easy to read, write and debug), but uses asynchronous IO under the hood (i.e. scalable).
BTW, have you read the article you linked? Because among other things, it currently says the following:
Several mainstream languages now have language support for futures and promises, most notably popularized by the async and await constructions in .NET 4.5 largely inspired by the asynchronous workflows of F#, which dates to 2007. This has subsequently been adopted by other languages, notably Dart (2014), Python (2015), Hack (HHVM), and drafts of ECMAScript 7 (JavaScript), Scala, and C++.
0: https://github.com/dotnet/roslyn/blob/master/docs/Language%2...
I agree. When they added dynamic and functional concepts, I though: great, a dynamic/statically typed imperative/functional oo language. Too many different ways to do things, makes it harder to understand code written in a different style. Basically the opposite of python's "pythonic way" idiomatic style.
I do love functional programming, which is why I am trying to move to f#. People at work are open to the idea!!
Anecdotally I have some friends writing business software at various BigCo companies that use C#.
Edit: it's perhaps worth mentioning that there is some more nuance to the Unity situation with their IL2CPP tech. Bottom line: engine users are writing C#.
On all enterprise customers that we work with, think DAX, if the application is to run native on the desktop, which is usually means Windows workstations, the software stack tends to be .NET with some C++ here and there.
Sun never managed to understand the desktop and Oracle even less.
So unless the customer has requirements for portable desktop applications, the solution is .NET.
Almost everybody doing in-house enterprise desktop apps (and those are a heck of a lot) and tons of people doing desktop Windows apps that don't need to be C++ (e.g. not Photoshop, Office and co).
Again, those are in the tens or hundreds of thousands. Check any Windows app review site or repo for examples.
It is _massively_ faster to write a quick UI in .Net than it is to write one in HTML.
I have been doing WPF development in the last two years for enterprise customers.
Also as a Windows user, there are plenty of applications to choose from.
C# and .NET used to be tied to Windows and IIS, Microsoft's web server, but recent developments are making it possible to create self-hosted applications and services written in C# that run in Linux. The self-hosting functionality is fairly mature by now, but the Microsoft implementation of cross platform C#/.NET is very early in its development.
It'll be interesting to see if Linux becomes a popular environment for developing and hosting .NET applications.I predict that it will be used, but it won't overtake the widely-used open-source alternatives such as Ruby, Python, and Node.js.
It's very easy to use C# to develop Windows services. I've written a few Windows services with C#, and it was pretty simple.
The typical model for most of our applications is we have three components - background agent, UI, and database. The UI handles configuration, user management, controls starting and stopping of processes, and also handles incoming API calls. The background agent is usually a windows service and the database is usually SQL Server.
Our products are used by hospitals as installable products and also by software vendors as libraries and bolt-on applications.
My condolences.
BTW, here's the third-party C# Windows app I use most often: https://windows.github.com/
Including a new higher performance/lower allocation text formatting API: https://github.com/dotnet/corefxlab/wiki/System.Text.Formatt...
Joe Duffy's first implmentation of it is here: https://github.com/joeduffy/slice.net
The more recent work for CoreFX is here: https://github.com/dotnet/corefxlab/tree/master/src/System.S...
This is of course expected for languages which keep piling up stuff but still disappointing.
Are you arguing that some people rely on ArraySegment being slow?
So making it compatible would probably require breaking its semantics.
Span/slice was a much more ambitious type that not only provided fast array segment like access, but also introduced a way to provide typed views into byte[] without the cost of casting or copying memory.
Span<T> is low level enough that they considered calling it Array<T> but decided against it to avoid even more confusion.
If you want to see an example of a API failure it is with System.Tuple<>. That type is effectively being deprecated when ValueTuple comes into the BCL with proper compiler support.
In all seriousness, the culture behind C# is way too conservative for it to ever to become like Scala. They add features, but they're nowhere near as bold and daring as the Scala team. As a language, Scala's is both incredibly impressive and terrifying from an Abstraction Astronaut's perspective. Even F# is very conservative compared to Scala.