微软 Mads Torgersen《从C#看开放对编程语言发展的影响》(2)

自诞生以来,C#大部分时间都是微软的专有语言,仅支持Windows,只有Visual Studio一款IDE。不过时代已经变了。C#从设计到实现都已经开源,几乎能运行在各种平台上。编译器变成了开放API,可以实时理解和生成C#代码,可以支持任何我们喜欢的代码编辑器。这背后发生了什么呢?我们一起看看,对C#而言,开放到底意味着什么?
展开查看详情

1.

2.

3.

4.Open source Cross platform Open language API “Roslyn” Cross IDE Open design Open to change “New direction” on the Great Wall

5.from c in customers customers where c.City == "Beijing" .Where(c => c.City == "Beijing") select c.Name; .Select(c => c.Name); from c in customers customers where c.City == "Beijing" .Where(c => c.City == "Beijing") from o in c.Orders .SelectMany(c => c.Orders, (c, o) => new { c, o }) select (c.Name, o.Price); .Select(p => (p.c.Name, p.o.Price));

6.void PlaySongs(int[] ids) { foreach (var id in ids) { try { var data = service.GetEncodedData(id); var song = Decode(data); Play(song); } catch (Exception e) { /* just skip the song */ } } }

7.Task PlaySongsAsync(int[] ids) { foreach (var id in ids) { try { var data = service.GetEncodedData(id); var song = Decode(data); Play(song); } catch (Exception e) { /* just skip the song */ } } }

8.async Task PlaySongsAsync(int[] ids) { foreach (var id in ids) { try { var data = service.GetEncodedData(id); var song = Decode(data); Play(song); } catch (Exception e) { /* just skip the song */ } } }

9.async Task PlaySongsAsync(int[] ids) { foreach (var id in ids) { try { var data = await service.GetEncodedDataAsync(id); var song = Decode(data); Play(song); } catch (Exception e) { /* just skip the song */ } } }

10.async Task PlaySongsAsync(int[] ids) { foreach (var id in ids) { try { var data = await service.GetEncodedDataAsync(id); var song = Decode(data); await PlayAsync(song); } catch (Exception e) { /* just skip the song */ } } }

11.async Task PlaySongsAsync(int[] ids) { foreach (var id in ids) { try { var data = await service.GetEncodedDataAsync(id); var song = await Task.Run(() => Decode(data)); await PlayAsync(song); } catch (Exception e) { /* just skip the song */ } } }

12.async Task PlaySongsAsync(int[] ids) { Task currentlyPlaying = Task.FromResult(true); foreach (var id in ids) { try { var data = await service.GetEncodedDataAsync(id); var song = await Task.Run(() => Decode(data)); await PlayAsync(song); } catch (Exception e) { /* just skip the song */ } } }

13.async Task PlaySongsAsync(int[] ids) { Task currentlyPlaying = Task.FromResult(true); foreach (var id in ids) { try { var data = await service.GetEncodedDataAsync(id); var song = await Task.Run(() => Decode(data)); await currentlyPlaying; currentlyPlaying = PlayAsync(song); } catch (Exception e) { /* just skip the song */ } } }

14.async Task PlaySongsAsync(int[] ids) { Task currentlyPlaying = Task.FromResult(true); foreach (var id in ids) { try { var data = await service.GetEncodedDataAsync(id); var song = await Task.Run(() => Decode(data)); await currentlyPlaying; currentlyPlaying = PlayAsync(song); } catch (Exception e) { /* just skip the song */ } } try { await currentlyPlaying; } catch (Exception e) { } }

15. Evolve... a little a lot Stagnation C#

16. C# 7 C# 6 Work with Eliminate data C# 5 ceremony C# 4 Async Dynamic, C# 3 Concurrency Queries, C# 2 Lambdas C# 1 Generics Hello World

17.East gate to Beihai Park

18.

19.

20.

21.