SlideShare ist ein Scribd-Unternehmen logo
Functional programming in
C#
Tadeusz Balcer
DISCLAIMER
DISCLAIMER
I’M NOT AN EXPERT IN THIS
TOPIC!
DISCLAIMER
I’M NOT AN EXPERT IN THIS
TOPIC!
But I will try to show you what I have learnt 
Agenda
1. Introduction
a) What is functional programming?
b) Separation between functions and arguments (data)
c) Benefits of Functional Programming
2. Functional programming in C#
a) Data Objects
b) Honest functions
c) Tuple and ValueTuple
d) Option<T>
e) LINQ
What is Functional Programming?
What is Functional Programming?
• Functional programming is a paradigm which concentrates on computing
results rather than on performing actions.
What is Functional Programming?
• Functional programming is a paradigm which concentrates on computing
results rather than on performing actions.
• Functional programming is programming with mathematical
functions - used functions should always provide the same results for the
same input.
What is Functional Programming?
• Functional programming is a paradigm which concentrates on computing
results rather than on performing actions.
• Functional programming is programming with mathematical
functions - used functions should always provide the same results for the
same input.
• At very high level, it's a programming style that emphasizes functions
while avoiding state mutation.
What is Functional Programming?
• Functional programming is a paradigm which concentrates on computing
results rather than on performing actions.
• Functional programming is programming with mathematical
functions - used functions should always provide the same results for the
same input
• At very high level, it's a programming style that emphasizes functions
while avoiding state mutation.
• Functional programming is a style that treads computation as the
evaluation of mathematical functions and avoids changing-state and
mutable data
Separation between functions and arguments
(data)
• In Object Oriented Programming, state (data) and methods
(functions) are bounded in objects
Separation between functions and arguments
(data)
• In Object Oriented Programming, state (data) and methods
(functions) are bounded in objects
• In functional programming, logic is encoded in functions and data is
captured with data objects, which are the input and output of
functions
Separation between functions and arguments
(data)
• In Object Oriented Programming, state (data) and methods
(functions) are bounded in objects
• In functional programming, logic is encoded in functions and data is
captured with data objects, which are the input and output of
functions
• Math functions are not class method. Math functions does not leave
any mark of it's exsistsence in outside world, while class methods may
change the state of an object.
Functions
Methods
Functional programming in practice
Aggregation of functions
Benefits of Functional Programming
• Tamed Side Effects
• Simple concurrency (no shared variables)
• Straightforward unit testing
• Different point of view for looking at problems
Benefits of Functional Programming
Benefits of Functional Programming
Functional programming in
C#
Making code more
functional
Use more specyfic
arguments and results
Data Objects instead of Primitive Types
Why use more specyfic data types?
• Primitive types are often not specific enough - for example, if you take
age, int can be -1000 as well as 1000.
Why use more specyfic data types?
• Primitive types are often not specific enough - for example, if you take
age, int can be -1000 as well as 1000.
• You’ll have to write additional unit tests for the cases in which
validation fails.
Why use more specyfic data types?
• Primitive types are often not specific enough - for example, if you take
age, int can be -1000 as well as 1000.
• You’ll have to write additional unit tests for the cases in which
validation fails.
• There are a few other areas of the application where an age is
expected, so you’re probably going to need the same validation in
those places. This will cause duplication.
Data Objects
Data Objects – interaction with primitive
types
Data Objects – interaction with primitive
types
Data Objects – implicit/explicit operators
Data Objects – implicite/explicit operators
Honest functions
Honest functions
• Honest function - it always honors signature. There is no other
possible outcome than defined (also no error throw). It just maps
each element of domain to an element of the codomain. Function is
honest if ts behavior can be predicted by its signature. No throwing
exceptions, and no null return values.
Honest functions
• Honest function - it always honors signature. There is no other
possible outcome than defined (also no error throw). It just maps
each element of domain to an element of the codomain. Function is
honest if ts behavior can be predicted by its signature. No throwing
exceptions, and no null return values.
• Dishonest function - give ma an int, and I may return a Risk.
Honest functions
Dishonest functions
Honest functions
Honest functions
Honest functions
Honest functions
DISHONEST SIGNATURE HONEST SIGNATURE
Composing values
Composing values with tuples
Tuple
TupleValue
Avoiding nulls
Avoiding null bomb – Option<T>
Avoiding null bomb – Option<T>
Avoiding null bomb – Option<T>
Avoiding null bomb – Option<T>
LINQ
LINQ
Summary
• Data Objects instead of Primitive Types
• Honest functions to have output for every possible input
• ValueTuple to aggregate Data Objects
• Option<T> to avoid nulls
• LINQ instead of foreach
Bibliography
• https://github.com/
louthy/language-
ext/wiki
Bibliography
• Functional Programming in C#: How to
write better C# code (2017)
Bibliography (Pluralsight)
• Functional Programming with C# (Dave Fencher) (2015)
• Applying Functional Principles in C# (Vladimir Khorikov)
(2016)
• Making Your C# Code More Functional (Zoran Horvat)
(2018)
Bibliography (Presentations)
• Railway oriented programming: Error handling in functional languages
by Scott Wlaschin (link) (2014)
• Functional Programming in C# (link) (2018)
Questions?
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015devCAT Studio, NEXON
 
20190621_RDBMSのVIEWを使ってRailsのデータアクセスをいい感じにする【銀座Rails#10】
20190621_RDBMSのVIEWを使ってRailsのデータアクセスをいい感じにする【銀座Rails#10】20190621_RDBMSのVIEWを使ってRailsのデータアクセスをいい感じにする【銀座Rails#10】
20190621_RDBMSのVIEWを使ってRailsのデータアクセスをいい感じにする【銀座Rails#10】Masato Mori
 
모바일 게임기획 따라하며 배우기
모바일 게임기획 따라하며 배우기모바일 게임기획 따라하며 배우기
모바일 게임기획 따라하며 배우기Sunnyrider
 
Architectural modeling chapter 5 of omd
Architectural modeling chapter 5 of omdArchitectural modeling chapter 5 of omd
Architectural modeling chapter 5 of omdjayashri kolekar
 
Introduction to arm virtualization
Introduction to arm virtualizationIntroduction to arm virtualization
Introduction to arm virtualizationTakaya Saeki
 
액션 게임 디자인
액션 게임 디자인액션 게임 디자인
액션 게임 디자인ByungChun2
 
グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?Insight Technology, Inc.
 
홍성우, 게임 프로그래머는 어떻게 가르치나요?, NDC2018
홍성우, 게임 프로그래머는 어떻게 가르치나요?, NDC2018홍성우, 게임 프로그래머는 어떻게 가르치나요?, NDC2018
홍성우, 게임 프로그래머는 어떻게 가르치나요?, NDC2018devCAT Studio, NEXON
 
20090107 Postgre Sqlチューニング(Sql編)
20090107 Postgre Sqlチューニング(Sql編)20090107 Postgre Sqlチューニング(Sql編)
20090107 Postgre Sqlチューニング(Sql編)Hiromu Shioya
 
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~Unity Technologies Japan K.K.
 
ビッグデータ処理データベースの全体像と使い分け
2018年version
ビッグデータ処理データベースの全体像と使い分け
2018年versionビッグデータ処理データベースの全体像と使い分け
2018年version
ビッグデータ処理データベースの全体像と使い分け
2018年versionTetsutaro Watanabe
 
게임제작개론 : #5 플레이어에 대한 이해
게임제작개론 : #5 플레이어에 대한 이해게임제작개론 : #5 플레이어에 대한 이해
게임제작개론 : #5 플레이어에 대한 이해Seungmo Koo
 
Building the Game Server both API and Realtime via c#
Building the Game Server both API and Realtime via c#Building the Game Server both API and Realtime via c#
Building the Game Server both API and Realtime via c#Yoshifumi Kawai
 
Profiling - 실시간 대화식 프로파일러
Profiling - 실시간 대화식 프로파일러Profiling - 실시간 대화식 프로파일러
Profiling - 실시간 대화식 프로파일러Heungsub Lee
 
김동건, 할머니가 들려주신 마비노기 개발 전설, NDC2019
김동건, 할머니가 들려주신 마비노기 개발 전설, NDC2019김동건, 할머니가 들려주신 마비노기 개발 전설, NDC2019
김동건, 할머니가 들려주신 마비노기 개발 전설, NDC2019devCAT Studio, NEXON
 

Was ist angesagt? (20)

이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
 
20190621_RDBMSのVIEWを使ってRailsのデータアクセスをいい感じにする【銀座Rails#10】
20190621_RDBMSのVIEWを使ってRailsのデータアクセスをいい感じにする【銀座Rails#10】20190621_RDBMSのVIEWを使ってRailsのデータアクセスをいい感じにする【銀座Rails#10】
20190621_RDBMSのVIEWを使ってRailsのデータアクセスをいい感じにする【銀座Rails#10】
 
スキルチェックリスト 2017年版
スキルチェックリスト 2017年版スキルチェックリスト 2017年版
スキルチェックリスト 2017年版
 
Use case Modeling
Use case ModelingUse case Modeling
Use case Modeling
 
모바일 게임기획 따라하며 배우기
모바일 게임기획 따라하며 배우기모바일 게임기획 따라하며 배우기
모바일 게임기획 따라하며 배우기
 
Architectural modeling chapter 5 of omd
Architectural modeling chapter 5 of omdArchitectural modeling chapter 5 of omd
Architectural modeling chapter 5 of omd
 
Introduction to arm virtualization
Introduction to arm virtualizationIntroduction to arm virtualization
Introduction to arm virtualization
 
액션 게임 디자인
액션 게임 디자인액션 게임 디자인
액션 게임 디자인
 
Data Flow Diagram or DFD
Data Flow Diagram  or DFDData Flow Diagram  or DFD
Data Flow Diagram or DFD
 
グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?
 
홍성우, 게임 프로그래머는 어떻게 가르치나요?, NDC2018
홍성우, 게임 프로그래머는 어떻게 가르치나요?, NDC2018홍성우, 게임 프로그래머는 어떻게 가르치나요?, NDC2018
홍성우, 게임 프로그래머는 어떻게 가르치나요?, NDC2018
 
20090107 Postgre Sqlチューニング(Sql編)
20090107 Postgre Sqlチューニング(Sql編)20090107 Postgre Sqlチューニング(Sql編)
20090107 Postgre Sqlチューニング(Sql編)
 
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
 
Azure DataLake 大全
Azure DataLake 大全Azure DataLake 大全
Azure DataLake 大全
 
ビッグデータ処理データベースの全体像と使い分け
2018年version
ビッグデータ処理データベースの全体像と使い分け
2018年versionビッグデータ処理データベースの全体像と使い分け
2018年version
ビッグデータ処理データベースの全体像と使い分け
2018年version
 
Map
MapMap
Map
 
게임제작개론 : #5 플레이어에 대한 이해
게임제작개론 : #5 플레이어에 대한 이해게임제작개론 : #5 플레이어에 대한 이해
게임제작개론 : #5 플레이어에 대한 이해
 
Building the Game Server both API and Realtime via c#
Building the Game Server both API and Realtime via c#Building the Game Server both API and Realtime via c#
Building the Game Server both API and Realtime via c#
 
Profiling - 실시간 대화식 프로파일러
Profiling - 실시간 대화식 프로파일러Profiling - 실시간 대화식 프로파일러
Profiling - 실시간 대화식 프로파일러
 
김동건, 할머니가 들려주신 마비노기 개발 전설, NDC2019
김동건, 할머니가 들려주신 마비노기 개발 전설, NDC2019김동건, 할머니가 들려주신 마비노기 개발 전설, NDC2019
김동건, 할머니가 들려주신 마비노기 개발 전설, NDC2019
 

Ähnlich wie Functional Programming in C#

Functional Programming - Worth the Effort
Functional Programming - Worth the EffortFunctional Programming - Worth the Effort
Functional Programming - Worth the EffortBoldRadius Solutions
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in RubyAlex Teut
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
Functional Swift
Functional SwiftFunctional Swift
Functional SwiftGeison Goes
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptxKarthickT28
 
XII Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-FunctionXII  Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-FunctionPrem Joel
 
Intro to Functional Programming @ Scala Montreal
Intro to Functional Programming @ Scala MontrealIntro to Functional Programming @ Scala Montreal
Intro to Functional Programming @ Scala Montrealfelixtrepanier
 
Functional solid
Functional solidFunctional solid
Functional solidMatt Stine
 
Math with .NET for you and Azure
Math with .NET for you and AzureMath with .NET for you and Azure
Math with .NET for you and AzureMarco Parenzan
 
A Theory of Functional Programming LambdUp
A Theory of Functional Programming LambdUpA Theory of Functional Programming LambdUp
A Theory of Functional Programming LambdUpEric Normand
 
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...vitalikaush1
 
Python functional programming
Python functional programmingPython functional programming
Python functional programmingGeison Goes
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsRajendran
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]Rome468
 

Ähnlich wie Functional Programming in C# (20)

RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
 
Functional Programming - Worth the Effort
Functional Programming - Worth the EffortFunctional Programming - Worth the Effort
Functional Programming - Worth the Effort
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in Ruby
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Basics of cpp
Basics of cppBasics of cpp
Basics of cpp
 
Functional Swift
Functional SwiftFunctional Swift
Functional Swift
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
XII Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-FunctionXII  Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-Function
 
Intro to Functional Programming @ Scala Montreal
Intro to Functional Programming @ Scala MontrealIntro to Functional Programming @ Scala Montreal
Intro to Functional Programming @ Scala Montreal
 
Functional Go
Functional GoFunctional Go
Functional Go
 
Functional solid
Functional solidFunctional solid
Functional solid
 
Math with .NET for you and Azure
Math with .NET for you and AzureMath with .NET for you and Azure
Math with .NET for you and Azure
 
A Theory of Functional Programming LambdUp
A Theory of Functional Programming LambdUpA Theory of Functional Programming LambdUp
A Theory of Functional Programming LambdUp
 
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 

Kürzlich hochgeladen

SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion Clinic
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...rajkumar669520
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageGlobus
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisNeo4j
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowPeter Caitens
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEJelle | Nordend
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILNatan Silnitsky
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownloadvrstrong314
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Krakówbim.edu.pl
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxwottaspaceseo
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
 

Kürzlich hochgeladen (20)

SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 

Functional Programming in C#

  • 3. DISCLAIMER I’M NOT AN EXPERT IN THIS TOPIC!
  • 4. DISCLAIMER I’M NOT AN EXPERT IN THIS TOPIC! But I will try to show you what I have learnt 
  • 5. Agenda 1. Introduction a) What is functional programming? b) Separation between functions and arguments (data) c) Benefits of Functional Programming 2. Functional programming in C# a) Data Objects b) Honest functions c) Tuple and ValueTuple d) Option<T> e) LINQ
  • 6. What is Functional Programming?
  • 7. What is Functional Programming? • Functional programming is a paradigm which concentrates on computing results rather than on performing actions.
  • 8. What is Functional Programming? • Functional programming is a paradigm which concentrates on computing results rather than on performing actions. • Functional programming is programming with mathematical functions - used functions should always provide the same results for the same input.
  • 9. What is Functional Programming? • Functional programming is a paradigm which concentrates on computing results rather than on performing actions. • Functional programming is programming with mathematical functions - used functions should always provide the same results for the same input. • At very high level, it's a programming style that emphasizes functions while avoiding state mutation.
  • 10. What is Functional Programming? • Functional programming is a paradigm which concentrates on computing results rather than on performing actions. • Functional programming is programming with mathematical functions - used functions should always provide the same results for the same input • At very high level, it's a programming style that emphasizes functions while avoiding state mutation. • Functional programming is a style that treads computation as the evaluation of mathematical functions and avoids changing-state and mutable data
  • 11. Separation between functions and arguments (data) • In Object Oriented Programming, state (data) and methods (functions) are bounded in objects
  • 12. Separation between functions and arguments (data) • In Object Oriented Programming, state (data) and methods (functions) are bounded in objects • In functional programming, logic is encoded in functions and data is captured with data objects, which are the input and output of functions
  • 13. Separation between functions and arguments (data) • In Object Oriented Programming, state (data) and methods (functions) are bounded in objects • In functional programming, logic is encoded in functions and data is captured with data objects, which are the input and output of functions • Math functions are not class method. Math functions does not leave any mark of it's exsistsence in outside world, while class methods may change the state of an object.
  • 18. Benefits of Functional Programming • Tamed Side Effects • Simple concurrency (no shared variables) • Straightforward unit testing • Different point of view for looking at problems
  • 19. Benefits of Functional Programming
  • 20. Benefits of Functional Programming
  • 22.
  • 24.
  • 25. Use more specyfic arguments and results Data Objects instead of Primitive Types
  • 26. Why use more specyfic data types? • Primitive types are often not specific enough - for example, if you take age, int can be -1000 as well as 1000.
  • 27. Why use more specyfic data types? • Primitive types are often not specific enough - for example, if you take age, int can be -1000 as well as 1000. • You’ll have to write additional unit tests for the cases in which validation fails.
  • 28. Why use more specyfic data types? • Primitive types are often not specific enough - for example, if you take age, int can be -1000 as well as 1000. • You’ll have to write additional unit tests for the cases in which validation fails. • There are a few other areas of the application where an age is expected, so you’re probably going to need the same validation in those places. This will cause duplication.
  • 30.
  • 31.
  • 32. Data Objects – interaction with primitive types
  • 33. Data Objects – interaction with primitive types
  • 34. Data Objects – implicit/explicit operators
  • 35. Data Objects – implicite/explicit operators
  • 37. Honest functions • Honest function - it always honors signature. There is no other possible outcome than defined (also no error throw). It just maps each element of domain to an element of the codomain. Function is honest if ts behavior can be predicted by its signature. No throwing exceptions, and no null return values.
  • 38. Honest functions • Honest function - it always honors signature. There is no other possible outcome than defined (also no error throw). It just maps each element of domain to an element of the codomain. Function is honest if ts behavior can be predicted by its signature. No throwing exceptions, and no null return values. • Dishonest function - give ma an int, and I may return a Risk.
  • 47. Tuple
  • 50.
  • 51. Avoiding null bomb – Option<T>
  • 52. Avoiding null bomb – Option<T>
  • 53.
  • 54. Avoiding null bomb – Option<T>
  • 55. Avoiding null bomb – Option<T>
  • 56. LINQ
  • 57.
  • 58.
  • 59. LINQ
  • 60.
  • 61.
  • 62.
  • 63. Summary • Data Objects instead of Primitive Types • Honest functions to have output for every possible input • ValueTuple to aggregate Data Objects • Option<T> to avoid nulls • LINQ instead of foreach
  • 65. Bibliography • Functional Programming in C#: How to write better C# code (2017)
  • 66. Bibliography (Pluralsight) • Functional Programming with C# (Dave Fencher) (2015) • Applying Functional Principles in C# (Vladimir Khorikov) (2016) • Making Your C# Code More Functional (Zoran Horvat) (2018)
  • 67. Bibliography (Presentations) • Railway oriented programming: Error handling in functional languages by Scott Wlaschin (link) (2014) • Functional Programming in C# (link) (2018)