18. .NET Conf
int a = 2;
int b = 3;
int c = a + b;
Console. WriteLine("before: the value of c is {0}",c);
a=2;
b=7;
Console. WriteLine("after: the value of c is {0}",c);
以下程式結果為何?
30. .NET Conf
Console.Write("Press input A:");
var a = Convert.ToInt32(Console.ReadLine());
Console.Write("Press input B:");
var b = Convert.ToInt32(Console.ReadLine());
var c = a+b;
Console.WriteLine("before: the value of c is {0}",c);
Console.Write("Press input B again:");
b = Convert.ToInt32(Console.ReadLine());
c = a+b;
Console.WriteLine("after: the value of c is {0}",c);
Imperative programming
31. .NET Conf
while (true)
{
Console.Write("Press input A:");
var a = Convert.ToInt32(Console.ReadLine());
Console.Write("Press input B:");
var subscription = Observable
.FromAsync(() => Console.In.ReadLineAsync())
.Subscribe(b => Console.WriteLine("the value of c is
{0}",a+Convert.ToInt32(b)));
Console.Write("enter symbol (or x to exit): ");
…
}
Reactive programming
72. .NET Conf
IObservable<string> subject = new [] { "Jordan", "Kobe", "James"}.ToObservable();
IObservable<string> subject = Observable.FromAsync (() =>
Console.In.ReadLineAsync ());
IObservable<int> subject = Observable.Range(5, 8);
IObservable<int> subject =
from i in Observable.Range(1, 100)
from j in Observable.Range(1, 100)
from k in Observable.Range(1, 100)
where k * k == i * i + j * j
select new { a = i, b = j, c = k };
IObservable<long> subject = Observable.Timer(TimeSpan.FromSeconds(3));
Subject
100. .NET Conf
“Do not forget nor dwell on the past, but do forgive it. Be aware
of the future but do no fear or worry about it. Focus on the
present moment, and that moment alone.”
105. .NET Conf
ReactiveX Official Site
Intro to Rx
Interactive diagrams of Rx Observables
Cloud-Scale Event Processing with the Reactive Extensions
(Rx) - Bart De Smet
The introduction to Reactive Programming you've been
missing
A Playful Introduction to Rx by Erik Meijer
106. .NET Conf
Rx.NET in Action: With examples in C#
.NET Design Patterns
Introduction to Rx: A step by step guide to the Reactive
Extensions to .NET
Opening & Personal Introduction - 3 mins
Reactive Programming Introduction - 8 mins
Reactive Extensions Introduction – 9 mins
.NET Core with Rx.NET - 10 mins
Adv .NET Core with Rx.NET – 15 mins
More Reactive - 2 mins
Summary - 3 mins
Others - 1 mins
Gérard Philippe Berry 是法籍的電腦開學家,由他所提出的Reactive Programming 是一種開發的編碼風格與架構,可以讓我們抱持與環境的互動,並將結果交由與其互動的環境來決定,而非程序本身。
這邊他也同時將所有程序按照其互動,分為了三種類型
Transformational program
Interactive program
Reactive program
響應式系統具備靈活性,鬆耦合和可擴展性。這使得它們更容易去開發、修改。而對 Error 與 Exception 有更大的容忍,並且當狀況發生時它們會更優雅地應對而不是讓直接系統崩潰。反應式系統有著高度的響應性,並會給用戶有效的交互反饋。
響應式系统是:
Responsive 響應式(reacts to events at the speed of environment)系統在任何情況下,都能及時響應,在可靠的時間內提供訊息且有穩定品質的服務。
Resilient 韌性、堅固, 具有容錯性(Fault-tolerant)系統在失敗時,仍然保有 Responsive 特性。這是由 replication (複製), containment (容忍), isolation (隔離)以及 delegation (委託)的方式達成的。系統的任何組件發生問題時,可以隔離此部份,並獨立恢復,過程中不會影響整個系統。
Elastic 彈性(Easy Scale up/down and out)即時量測效能,可透過演算法增加或減少服務的資源分配,滿足不同工作負載量的系統要求。
Message Driven 訊息驅動(modular, pipelined, asynchronous)組件之間透過非同步訊息傳遞方式互相溝通,用以確保 loose coupling (鬆耦合), isolation (隔離), location transparency (與區域無關)的特性。還能提供錯誤訊息的委託處理機制。
Anders Hejlsberg(安德斯·海爾斯伯格)丹麥籍的開發教父,Pascal編譯器的主要開發人員,也是Delph與C#之父進入微軟公後,先後設計出了了Visual J ++,Net,C#和TypeScript。可以說他開發出的軟體和發明的程式語言影響全世界程序員。目前,他是C#語言的首席架構師和TypeScript的核心開發者與TypeScript開源項目的重要領導人functional Programming 允許開發者描述什麼是他們想要程序去做的,而不是強迫他們描述程序該如何去做
資料(data) 與操作(operations)
The .NET Foundation is an independent organization, incorporated on March 31, 2014,[1] by Microsoft, to improve open-source software development and collaboration around the .NET Framework.[4] It was launched at the annual Build 2014 conference held by Microsoft.[5]
Package Manager
Install-Package System.Reactive -Version 4.0.0-preview00001
.NET CLI
dotnet add package System.Reactive --version 4.0.0-preview00001
System.Reactive.Core: Is the heart of Rx and had extension methods for subscribing to subject. It has static class Observer to create observers. It also provides synchronization and scheduling services.
System.Reactive.Interfaces: This provides the interfaces for for event pattern which subject can implement to raise events when data is available. It also has the scheduler interfaces and queriable interfaces for Rx schedulers and LINQ support.
System.Reactive.Linq: This provides the famous static class Observable to create in-memory observable sequence. This extends the basic LINQ feature to Rx.
System.Reactive.PlatformServices: This extends the basic scheduling services provided in System.Reactive.Core and will replace all the scheduling service in future.
Dotnet Core Version:
dotnet new console --framework netcoreapp2.0
dotnet add package System.Reactive --version 4.0.0-preview00001
MyObserver
MyObserver with Lambda
MyObserver with Lambda and NewThread
MyObservable
EvenNumbers
EvenNumbers by Rx.NET Example
Odd and Even Numbers by Rx.NET Example
Asynchronous programming model
Events
Delegates
Tasks
IEnumerable<T>