Download - C# Today and Tomorrow
![Page 1: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/1.jpg)
C# Today & Tomorrow
![Page 2: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/2.jpg)
http://stackoverflow.com/research/developer-survey-2015
![Page 3: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/3.jpg)
http://stackoverflow.com/research/developer-survey-2015
![Page 4: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/4.jpg)
http://stackoverflow.com/research/developer-survey-2015
![Page 5: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/5.jpg)
Changing our tune…
Run on Windows
.NET as system component
Run on VM (CLR)
Black box compilers
Edit in Visual Studio
Proprietary
Run everywhere
Deploy with app
Compile to native
Open compiler APIs
Use your favorite editor
Open source
![Page 6: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/6.jpg)
Project Roslyn
“Let’s rewrite the C# and VB compilers and IDE from scratch!”
• Evolve
• Enable
• Dogfood
![Page 7: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/7.jpg)
The compiler/IDE dichotomy
Compiler
Batch
Throughput
Correctness
Prevent badness
Reactive to what you did
IDE
Incremental
Responsiveness
Error tolerance
Enable goodness
Predictive of what you will do
![Page 8: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/8.jpg)
The Roslyn Compiler API
There should only need to be
one code base in the world
for understanding C#
![Page 9: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/9.jpg)
Other IDEs On other platforms
Custom diagnostics Style, API usage, patterns…
Source transformation Refactorings, fixers, migraters, updaters…
Scripting Batch scripts, hosted code…
Coding in execution REPL, edit-and-continue…
Documentation Hyperlinked API docs, web playgrounds…
Static analysis Code metrics, graphs, telemetry, code querying…
Metaprogramming Source generators, injectors, weavers…
Other language understanding scenarios
![Page 10: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/10.jpg)
Custom analyzers and fixes
Plug in to diagnostic reporting and code fixing infrastructure
Batch and interactive
“Code-aware libraries”
APIs can ship with analyzers and fixes to guide their users
Toolboxes
Style enforcement, discovery of opportunities
![Page 11: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/11.jpg)
Language evolution explained
Stagnation
C#
![Page 12: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/12.jpg)
Evolution of C#
C# 1
Hello World
C# 2
Generics
C# 3Queries, Lambdas
C# 4Dynamic, Concurrency
C# 5
Async
C# 6Avoid boilerplate
C# 7
???
![Page 13: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/13.jpg)
Demo: REPL and C# 6
![Page 14: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/14.jpg)
C# “7”
![Page 15: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/15.jpg)
Pattern matching
if (o is Point p) { WriteLine($"({p.X}, {p.Y})"); }
if (o is Point p && p.X == 5) { WriteLine($"Y: {p.Y}"); }
if (o is Point(5, var y)) { WriteLine($"Y: {y}"); }
![Page 16: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/16.jpg)
Patterns in switch statements
switch (o){
case int i:WriteLine($"Number {i}");break;
case Point(int x, int y):WriteLine($"({x},{y})");break;
case string s when s.Length > 0:WriteLine(s);break;
case null:WriteLine("<null>");break;
default:WriteLine("<other>");break;
}
![Page 17: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/17.jpg)
Tuples
public (int sum, int count) Tally(IEnumerable<int> values)
{
var s = 0; var c = 0;
foreach (var value in values) { s += value; c++; }
return (s, c);
}
var t = Tally(myValues);
Console.WriteLine($"Sum: {t.sum}, count: {t.count}");
(var s, var c) = Tally(myValues);
Console.WriteLine($"Sum: {s}, count: {c}");
![Page 18: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/18.jpg)
Records
class Person : IEquatable<Person>{
public string First { get; }public string Last { get; }
public Person(string First, string Last) { this.First = First; this.Last = Last; }
public (string First, string Last) Deconstruct() => (First, Last);
public bool Equals(Person other) => First == other.First && Last == other.Last;
public override bool Equals(object obj) => obj is Person other ? Equals(other) : false;public override int GetHashCode() => GreatHashFunction(First, Last);
…}
class Person(string First, string Last);
![Page 19: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/19.jpg)
Creating immutable objects
var p1 = new Point { X = 3, Y = 7 };
var p2 = p1 with { X = -p1.X };
![Page 20: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/20.jpg)
Nullable and non-nullable reference types
string? n; // Nullable reference type
string s; // Non-nullable reference type
n = null; // Sure; it's nullable
s = null; // Warning! Shouldn’t be null!
s = n; // Warning! Really!
WriteLine(s.Length); // Sure; it’s not null
WriteLine(n.Length); // Warning! Could be null!
if (n != null) { WriteLine(n.Length); } // Sure; you checked
WriteLine(n!.Length); // Ok, if you insist!
![Page 21: C# Today and Tomorrow](https://reader034.vdocuments.us/reader034/viewer/2022050614/589dad0d1a28ab21728b59e5/html5/thumbnails/21.jpg)
?