Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Functional Programming Deep Dive with C#
Rating: 4.4 out of 5(60 ratings)
546 students

Functional Programming Deep Dive with C#

Take your code to the next level with Functional Programming in C#. Improve your software’s architecture. C# 9.0.
Created byCory West
Last updated 3/2022
English

What you'll learn

  • Why functional programming is useful
  • Improve your code's quality, readability, and stability
  • Design and Implement Immutable Types and Maybes/Options for Nulls
  • Impress your peers with high quality code
  • Improve your code's quality, readability, and stability
  • Improve your own reasoning of software architecture

Course content

12 sections22 lectures3h 29m total length
  • Introduction1:53

    Course Overview

    Hi, Welcome to Functional Programming Deep Dive in C#. My name is Cory. I built this course for two reasons: There are many fewer well-built and curated resources online for learning to improve your craft, compared to resources for beginners or those just starting out. I feel that this course helps plug that gap.

    Also because when I was trying to learn functional programming from a practical perspective, I found few resources that described functional programming in an approachable way with real applications to the code I was working on. I aim to do exactly that with this course.

    Who is this course built for?

    This course is built with the experienced developer in mind. I won’t be going over any functions of the C# language specification in detail, with the exception of C# 9. I will instead focus on the “why you should do this” and practical examples and ideas for using the knowledge contained herein in your current or future projects.

    Some of the lessons will use concepts that a beginner might find advanced or overwhelming. I don’t want to discourage beginners from taking this course, but you should know what you are getting into.

    To effectively understand the concepts and code examples in this course, you need to have knowledge of: delegates, lambda functions, the func- and action classes, the SOLID principles, and declarative vs. imperative programming.

    Throughout this course, we will be building an example order processing system for an eCommerce site using our new functional knowledge. The screenshots you see on screen in the lessons are snippets from this project.

    Please click “Ask me at the end of the course”

    If you are watching this course on Udemy, they will soon ask you to rate this course. Probably in the next video or two. Please consider clicking “Ask me later” or “Ask me at the end” so you can form a better opinion about how valuable this course is to you. Courses live and die on Udemy by their ratings. I would really appreciate it if you did actually rate it. Thank you.

  • What is Functional Programming8:50

    What is Functional Programming?

    Functional programming is a programming paradigm. It is a different way of thinking about how to build programs. The features of the language that we use are just a means to an end.

    In functional programming functions are first-class values. All that means is you can use functions just like variables. You can pass functions to and from other functions, and you can store them in variables or collections. We will discuss the true definition of a function in Functional programming later. It’s not what you think it is.

    Functions in the application do not mutate their parameters or inputs. This means that values never change in-place. Functions in functional programming strictly map an input to output with no side effects.

    Code written in functional programming style focuses on computing results instead of performing actions.

    There is an example of what this means in the first lesson on pure functions.

    So, why not use F#? If you can use F# in a project or you already know F#, then absolutely use it. It is a true functional programming language. But the world isn’t perfect and there will be situations in your career where you will not be able to use F# or another functional language, but you can still reap the benefits from functional programming.

    Not everyone has the time or motivation to learn a new language. Not everyone has a say in what tech they get use for a project, or they are working on an existing system written in C# and want to improve the codebase using functional programming anyway.

    Lastly, at least for me, there is a huge bank of knowledge that one acquires while working inside an ecosystem as the one Microsoft has built around C#. Using that existing knowledge, intuition, tooling, and ecosystem to take advantage of the benefits of functional programming is a more efficient use of time and resources.


    Core Concepts

    Functional programming has a couple of core concepts that define what it is. Those are:

    • Functional Purity.

    • First Class Functions.

    • Immutability.

    • Concurrency.

    • Referential Transparency.

    • Composability.

    Why Use It?

    Object oriented programming and functional programming can be used together. They are not mutually exclusive. The generally accepted rules for structuring complex applications AKA, design patterns transcend object oriented programming and functional programming. The generally accepted rules for structuring complex applications well, transcend object oriented programming and functional programming. The SOLID principles for example can be applied using both.

    Using the concepts of functional programming results in code that is more modular. By definition, all pure functions are tightly encapsulated. They operate only on their inputs and produce no side effects. This allows loose coupling between components by design and requires little extra thought.

    Separation of concerns is a little easier to achieve because writing pure functions guides you toward writing functions that do one thing.

    Referential Transparency makes it easier to understand what a function is supposed to do just by the signature, and so makes it easier for you to separate your concerns without thinking too hard about the implementations of your functions.

    Functional code is easier to understand and predict. It forces a declarative approach instead of an imperative approach. This means that we write functions that declare what is needed and what they will do instead of how they will do it. In imperative style, you declare computations that change the program’s state or commands that the computer must perform.

    A good metaphor is like telling your contractor to build you a shed and letting him fill in the details vs telling your contractor where to put the footings, what studs to use and where they will go, and how to install the roof shingles.

    Predictability also greatly reduces the mental burden of understanding code. If you have a test that confirms a function’s output for certain inputs, then you know you will always get the result you are testing. There will be code examples that describe this in later lessons.

    Functional programming also simplifies the testing and debugging of your code. It is a natural benefit of keeping functions pure and declarative. If the function only maps inputs to outputs and has no side effects, and you control all the inputs as the caller; that makes testing as simple as passing in your test values. There is no need to make stubs or mocks, meaning we can ignore the internals of the function under test.

    Pure functions are by definition thread-safe so concurrency is built in. You never have to worry about deadlocks or race conditions. That said, your entire application is unlikely to be composed of pure functions. There needs to be a state stored somewhere and when you are dealing with any type of I/O there will be impure functions at some point. The goal here is to minimize the surface area that these issues infect. By keeping as much of your program as pure as possible you reduce the surface area that you have to worry about.


    Disadvantages

    Now for some disadvantages. There is a higher learning curve for truly understanding and internalizing the use of functional programming. There aren’t as many learning resources so you have to extrapolate a lot more yourself - one of the reasons I made this course.

    While writing pure functions is easy, composing them together into a complete program is much harder, especially at the beginning of your learning curve.

    Writing functional code in C# will require you to think about programs differently. It is a challenge to change your thinking from imperative, or object oriented programming, to declarative and functional. You need to organize your code differently, process data differently, and write classes differently. It will take some getting used to, but the benefits far outweigh the costs.

    Because we cannot mutate state, variables need to be copied more frequently to achieve immutability. This results in not only extra code, but also extra memory consumption. Any I/O operation will be impure by its nature which means that any pure function that MUST use I/O can no longer be a pure function. The concept of functional code/ imperative shell helps here, which we will discuss later.


    Our Journey

    This is a layout of the lessons in this course. The later lessons build significantly on the core concepts here. It would be beneficial for you to follow the order, but you can still get a lot out of this course if you don’t.

    If you feel you have a very firm grasp on functional purity, immutability, using and building Lambda functions, and recursion then you may be able to skip ahead to the later lessons.

    Each lesson will start with an explanation of the concept, why it is important, and where you can use it.

    Then there will be a code example that we will walk through together that will help solidify the concept in your head. Then I will give you practical advice on where to use your new knowledge.

    Each video will end with a practical refactor challenge for you to complete should you choose to do so. The refactor challenge will use a demo application to approximate a real-life situation.

    The goal of each lesson is to introduce the concepts of functional programming using built-in C# language features.

    Once you learn implementation in vanilla C#, I will introduce libraries and frameworks that make implementing the concept easier, if there are any.

    This approach will allow you to get the maximum utility from this course whether you control your codebase or not - and can introduce new dependencies or not.

    These lessons build on the core concepts and are not strictly functional programming concepts. They are best practices, patterns, shortcuts, or ideas about how to get the most out of functional programming with C#.

    As a bonus, I have included lessons on design patterns and libraries that I found helpful when programming in C# with functional programming concepts.

    If you don’t care who I am or what my background is you can skip the rest of this video.


    Who am I?

    I’ve been building software for 10 years in most levels of the industry. From small custom applications for mom and pop business, to industry-leading enterprise applications used by millions of people.

    I have worked in many industries such as Healthcare, Logistics, e-Commerce, Meal delivery, Tax software, Wireless Carrier services, and Cybersecurity.

    I’m an autodidact, which means I’m self-taught, and I have a compulsion to always be learning. I read constantly and have broad interests across the industry.

    I strive to be a no-nonsense teacher so you will find no fluff in these lessons. Straight to the point so you can get on with your day.

    I hope to pass on my knowledge and love for learning on to my peers and improve their code and expertise.


    That’s all for this lesson, let’s jump to the next one.



Requirements

  • Solid understanding of C#, SOLID Principles , Lambdas, and Delegates.
  • Visual Studio 2019 Community Edition (preferrably version 16.9 or later)
  • Willingness to re-think the way you write software

Description

Take your code to the next level of maintainability, efficiency/concurrency, and ease-of-understanding. Learn the principles of functional programming, how and where to apply it in C#, and why it will make you a better programmer. Improve your software’s architecture and leapfrog your code quality over that of your peers.


What You’ll Learn

  • Why functional programming is useful

  • How to apply functional principles and patterns in C#

  • Design and Implement Immutable Types and Maybes/Options (Null values)

  • Writing Pure Functions (functions without side effects)

  • Using recursion with functional programming paradigms to simplify your code

  • Using LINQ to clean up code and condense logic

  • Handle errors in functional style

  • Utilizing extension methods to write fluent, easy to read code.

  • Make use of new C# 8 and 9 features in functional style


Course Description

Learn how to apply function paradigms and patterns to codebases in C#. If you want to improve the maintainability, understandability, stability, and terseness of your code; this course will help you do that. This is meant for experienced C# developers that already have a solid, moderately deep understanding of the C# language.

Each video will introduce a concept, and lay out an example of implementing that concept.

If you want to improve your code’s quality, make your application faster and easier to understand, and increase your own productivity, then this course will help you tremendously.

Each video in this series can be watched independently. You can get value out of each video by itself if you already know certain concepts or are looking to learn something specific.


Teaching Style

All videos are short, to-the-point, and avoid fluff.


The course covers the following topics:

  • Theoretical Foundations of Functional Programming

  • Core Concepts of Functional Programming

  • Functional Features in C# (C# 9 included)

  • Immutability, Extensibility, and Extendibility in C#

  • Dealing with Errors and Nulls gracefully


Course Keywords:

  • C# Clean Code

  • C# Best Practices

  • Functional Programming in C#

  • C# Functional Programming

  • Clean Code in C#

  • Functional Programming

  • Code Readability

  • Stable Code in C#

Who this course is for:

  • Experienced programmers looking to expand their knowledge further