1 option
Functional Programming with C# : Unlock Coding Brilliance with the Power of Functional Magic / Alex Yagur.
- Format:
- Book
- Author/Creator:
- Yagur, Alex, author.
- Language:
- English
- Subjects (All):
- C# (Computer program language).
- Functional programming (Computer science).
- Physical Description:
- 1 online resource (258 pages)
- Edition:
- First edition.
- Place of Publication:
- Birmingham, England : Packt Publishing Ltd., [2024]
- Summary:
- Explore functional programming in C# with the help of clear explanations, practical examples, and hands-on exercises and write efficient, modular, and readable code Key Features Master functional programming in C# for expressive, modular code Apply advanced concepts such as error handling and asynchronous programming to overcome real-world challenges Gain practical coding skills through practical application and self-assessment questions Purchase of the print or Kindle book includes a free PDF eBook Book Description In an era where software complexity is increasing by the day, functional programming offers a paradigm that simplifies code maintenance and enhances reliability. Functional Programming with C# takes you on an exhaustive journey into functional programming within C#. The book familiarizes you with the core principles and benefits of functional programming, juxtaposing it with imperative and object-oriented paradigms. You'll get to grips with the functional features of C# and learn to write expressive, modular code through expressions, pure functions, and higher-order functions. As you advance, you'll explore advanced concepts such as error handling and asynchronous programming, which will equip you with the practical skills that you need to tackle real-world challenges. By comparing functional programming in C# with other languages and providing additional resources, this book ensures that you're well-equipped to continue your journey toward mastery in functional programming. By the end of this book, you'll have gained a thorough understanding of functional programming techniques, such as recursion, memoization, and composition, empowering you to write robust, maintainable code. What you will learn Understand the core principles of functional programming Differentiate functional, imperative, and OOP paradigms Write expressive code with higher-order functions Handle errors effectively using functional techniques Utilize asynchronous programming for concurrent tasks Grasp advanced concepts, such as recursion and memoization Who this book is for This book is for intermediate-to-advanced C# developers looking to expand their programming paradigm horizons. Software engineers, developers, and programmers familiar with C# and object-oriented programming who want to delve deeper into functional programming concepts will find this book very useful. This book is ideal for professionals aiming to enhance code modularity, readability, and scalability. While prior knowledge of C# is necessary, beginners with a strong grasp of programming fundamentals can also benefit from the clear explanations and practical exercises provided.
- Contents:
- Cover
- Title Page
- Copyright and Credits
- Dedication
- Contributors
- Table of Contents
- Preface
- Part 1: Foundations of Functional Programming in C#
- Chapter 1: Getting Started with Functional Programming
- Functional versus imperative versus object-oriented programming
- Imperative programming
- Object-oriented programming
- Functional programming
- Blending paradigms
- How functional programming is supported in C#
- How to write functional code in C#
- A practical example - a book publishing system
- How to combine functional and object-oriented paradigms
- Meet Steve and Julia
- Summary
- Chapter 2: Expressions and Statements
- Task 1 - Name and count all expressions and all statements
- Task 2 - Use expressions instead of statements
- Task 3 - Create an expression tree
- Understanding the difference between expressions and statements
- Example of expressions
- Example of statements
- Key differences between expressions and statements
- Guided exercise - finding expressions and statements in sample code
- How to use expressions for clear and simple code
- The power of expressions - improving readability and maintainability
- Techniques to convert statements to expressions
- Guided exercise - refactoring code using expressions
- Lambda expressions, expression-bodied members, and anonymous methods
- What are lambda expressions?
- Multiple parameters in lambda expressions
- Lambda expressions evolution
- Understanding anonymous methods
- How do anonymous methods work?
- When to use anonymous methods
- Practical examples - applying these features in real code
- Expression-bodied members
- Exercise - implementing lambda expressions and anonymous methods
- Expression trees and how to use them to manipulate expressions at runtime
- Building and manipulating expression trees.
- Creating and manipulating complex expression trees
- Querying data with expression trees - LINQ and beyond
- Guided exercise - constructing and manipulating expression trees
- Problem sets and exercises
- Exercises
- Exercise 1
- Exercise 2
- Exercise 3
- Solutions
- Chapter 3: Pure Functions and Side Effects
- Task 1 - Refactoring to a pure function
- Task 2 - Isolating side effects
- Task 3 - Using a Pure attribute
- Understanding pure functions
- Examples of pure functions
- The benefits of pure functions
- Comparisons of pure functions and non-pure functions
- Side effects
- Common sources of side effects
- Consequences of side effects
- Strategies to minimize side effects
- Favor immutability
- Use readonly and const
- Use functional programming principles
- Encapsulate side effects
- Marking pure functions with the Pure attribute
- Understanding the Pure attribute in C#
- The benefits of marking functions as pure
- Caveats and considerations when using the Pure attribute
- Chapter 4: Honest Functions, Null, and Option
- Task 1 - Refactor for honest return types
- Task 2 - Guard against null inputs
- Task 3 - Pattern matching with nullable types
- Honest functions - definition and understanding
- The problems with hidden nulls
- A quick look back - C# and null
- Common mistakes and the troubling NullReferenceException
- Not all bad - the value of null
- Embracing honesty with nullable reference types
- What are nullable reference types?
- Transitioning to NRTs
- Enabling nullable reference types
- Disabling nullable reference types
- Warnings and annotations options
- The bigger picture - project-wide settings.
- Returning with intention
- The distinction between UserProfile and UserProfile?
- Honoring a function's contract
- Demanding honesty from function inputs
- Nullable reference types to the rescue
- Using preconditions and contracts
- Using built-in checks
- The power of explicit non-null inputs
- Pattern matching and nullable types
- Pattern matching with nullable types
- Switch expressions with property patterns
- Ensuring clarity with nullable types
- The null object pattern
- The problem with null checks
- The null object solution
- Advantages
- Limitations and considerations
- Beyond null - using Option
- A brief introduction to Option
- Advantages of the Option type over nullable types
- The interplay of Option and nullable types
- Practical scenarios - handling nulls effectively
- Case study - managing YouTube videos
- Case study - managing different video types
- Case study - working with non-existing objects
- The impact of handling nulls in real-world scenarios
- The reality of honesty in C# - why there will never be truly honest functions
- The compromises of the C# language design
- Practical tips and best practices
- Strategies for migrating existing code bases to adopt nullable reference types and Option
- Common pitfalls and how to navigate them
- Testing strategies for null and Option handling
- Part 2: Advanced Functional Techniques
- Chapter 5: Error Handling
- Task 1 - Custom error types and result usage
- Task 2 - Utilizing ROP for validation and processing
- Task 3 - Implementing a Retry mechanism using functional techniques
- Traditional error handling in C#
- try-catch blocks
- Exceptions
- The Result type
- Implementing the Result type
- Using the Result type.
- Railway-Oriented Programming (ROP)
- The essence of Bind
- Chaining operations with Bind
- Composable error handling with ROP
- Handling diverse error types
- Benefits of isolation
- Extending ROP for asynchronous operations
- Designing your own error-handling mechanisms
- Use factory methods for creation
- Extend with Bind
- Customize error types
- Leverage extension methods
- Integration with existing code
- Always iterate and refine
- Practical tips for functional error handling
- Avoid null with options
- Logging errors
- Two strategies To replace exceptions
- Anticipate errors - make it predictable
- Embrace composition
- Educate your team
- Traditional versus functional error handling comparison
- The traditional way
- The functional way
- Comparative analysis
- Making the shift
- Patterns and anti-patterns in functional error handling
- Chapter 6: Higher-Order Functions and Delegates
- Task 1 - Sorting function
- Task 2 - Customized calculations
- Task 3 - Comparison
- Understanding higher-order functions
- The power of higher-order functions in functional programming
- Creating versatile code with fewer errors
- Supporting a more declarative coding style
- Delegates, actions, funcs, and predicates
- Delegates
- Actions
- Funcs
- Predicates
- Callbacks, events, and anonymous methods
- The role of delegates in events
- Delegates and anonymous methods
- Harnessing LINQ methods as higher-order functions
- Filtering
- Data transformation
- Data aggregation
- Case study - putting it all together
- Step-by-step walk-through and analysis of the code
- Best practices and common pitfalls
- Exercise 2.
- Exercise 3
- Chapter 7: Functors and Monads
- Task 1 - Functor usage
- Task 2 - Applicative functor
- Task 3 - Monad usage
- What's a functor?
- Identity law
- Composition law
- Creating our own functor
- Functor benefits
- Applicative functors
- The Apply method implementation
- Applicative functor laws
- Monads
- The Bind method
- Monad laws
- Utilizing monads
- Key takeaways
- Part 3: Practical Functional Programming
- Chapter 8: Recursion and Tail Calls
- Task 1 - Recursive enemy count
- Task 2 - Wave generation
- Task 3 - Asynchronously updating enemy stats
- Introducing recursion
- Recursive thinking
- Types of recursion
- Simple recursion
- Tail recursion
- Challenges of recursion
- Stack overflow risk
- Default stack size and limitations
- Performance considerations
- Leveraging C# features for recursion
- Local functions
- Pattern matching
- Advanced recursive patterns
- Mutual recursion
- Memoization
- Comparison with iterative solutions
- Readability
- Performance
- Recursion in asynchronous programming
- Explaining asynchronous recursion under the hood
- Synchronous versus asynchronous recursion
- Scenarios for asynchronous recursion
- Chapter 9: Currying and Partial Application
- Task 1 - Currying tower attack functions
- Task 2 - Partial application for game settings
- Task 3 - Currying permission checks for game features
- Understanding currying
- Standard approach
- Curried approach
- Step-by-step implementation of currying
- Use cases
- Configuration settings
- Event handling
- Partial application
- Asynchronous programming.
- Partial application.
- Notes:
- Includes bibliographical references and index.
- Description based on publisher supplied metadata and other sources.
- Description based on print version record.
- Other Format:
- Print version: Yagur, Alex Functional Programming with C#
- ISBN:
- 9781805128939
The Penn Libraries is committed to describing library materials using current, accurate, and responsible language. If you discover outdated or inaccurate language, please fill out this feedback form to report it and suggest alternative language.