29,99 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 258
Veröffentlichungsjahr: 2024
Functional Programming with C#
Unlock coding brilliance with the power of functional magic
Alex Yagur
Copyright © 2024 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Kunal Sawant
Assistant Publishing Product Manager: Debadrita Chatterjee
Book Project Manager: Manisha Singh
Senior Editor: Kinnari Chohan
Technical Editor: Vidhisha Patidar
Copy Editor: Safis Editing
Proofreader: Kinnari Chohan
Indexer: Pratik Shirodkar
Production Designer: Prashant Ghare
DevRel Marketing Coordinator: Sonia Chauhan
First published: July 2024
Production reference: 1110724
Published by Packt Publishing Ltd.
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1RB, UK
ISBN 978-1-80512-268-5
www.packtpub.com
To Julia, my beloved wife and steadfast companion on this journey.
To my parents, whose unwavering support and guidance have shaped me into who I am today.
To my daughters, Irina, Lisa, and Emily - you are my inspiration and my greatest joy. May this work inspire you to pursue your dreams with passion and perseverance.
Alex Yagur has been working in software development since 2000, specializing in C#. He holds Master’s degrees in Software Development and Organizational Management. Alex has created multiple online courses for software developers and is the founder of “Hands-On Dev Academy,” an educational platform that uses practice-focused approaches, AI, and gamification to enhance the online learning experience. His interests include computer games, mountaineering, running, and diving. Alex is dedicated to improving software education and making complex concepts accessible to learners worldwide.
I would like to express my heartfelt gratitude to:
Logan Ferris for keeping me fit and energized throughout this project.Konstantin Rochev and Andrew Pasenchuk for their meticulous review of this book.Kinnari Chohan and Manisha Singh for their guidance throughout the writing process.My students, who have taught me so much while I’ve been teaching them.Your help and support made this book possible.
Thank you.
Lucas Venturella started programming because it was the most amazing thing he discovered while growing up. Over the years, he has experienced many changes. Initially driven by passion, his primary motivation today is his daughter and family. The desire to positively impact the world for future generations, especially his child’s, is what truly drives him now. He believes that being completely dedicated to something to the point where one can influence the world is a crucial skill, and he hopes to impart this to his child. Lucas’s main skills today include .NET, DevOps, and some frontend development.
Andrey Pasenchuk is a software architect with expertise in designing high-loaded systems. With a strong background in computer science and mathematics, along with more than a decade of experience, he has successfully developed scalable and efficient solutions. His primary focus is on crafting architectures that align perfectly with the product, ensuring ease of maintenance and cost-effective scalability. Andrei is committed to continuously improving his skills and exploring new technologies to remain at the forefront of system architecture.
Welcome to Functional Programming with C#!
This book is designed to introduce you to the powerful paradigm of functional programming within the context of C#. As C# continues to evolve, it increasingly embraces functional programming concepts, allowing developers to write more concise, maintainable, and robust code. This book will guide you through the journey of understanding and applying functional programming principles in C#, from basic concepts to advanced techniques.
This book is aimed at C# developers who want to expand their programming toolkit by learning functional programming techniques. It’s suitable for intermediate to advanced programmers familiar with object-oriented programming and looking to enhance their skills. While prior knowledge of functional programming is not required, a solid understanding of C# fundamentals is necessary to get the most out of this book.
Chapter 1, Getting Started with Functional Programming, introduces the core concepts of functional programming and how they apply to C#.
Chapter 2, Expressions and Statements, delves into the differences between expressions and statements, and how to write more expressive code.
Chapter 3, Pure Functions and Side Effects, explores the concept of pure functions and how to minimize side effects in your code.
Chapter 4, Honest Functions, Null, and Option, discusses the importance of honest functions and how to handle null values effectively.
Chapter 5, Error Handling, introduces functional approaches to error handling, moving beyond traditional try-catch blocks.
Chapter 6, Higher-Order Functions and Delegates, covers the power of functions as first-class citizens in C#.
Chapter 7, Functors and Monads, explores these advanced functional programming concepts and their implementation in C#.
Chapter 8, Recursion and Tail Calls, dives into recursive programming techniques and optimization.
Chapter 9, Currying and Partial Application, teaches how to create more flexible and reusable functions.
Chapter 10, Pipelines and Composition, shows how to combine functions to create powerful data processing pipelines.
Chapter 11, Reflecting and Looking Ahead, summarizes the key concepts learned throughout the book and provides guidance on further advancing your functional programming skills in C#.
To fully benefit from this book, readers should have a good grasp of C# basics, including object-oriented programming concepts. Familiarity with LINQ is helpful but not required. Each chapter builds upon the previous ones, so it’s recommended to read the book sequentially. Practice exercises are provided to reinforce the concepts learned.
Software/hardware covered in the book
Operating system requirements
C# 12
Windows, macOS, or Linux
.NET 8
To follow along with the examples in this book, you’ll need to have the .NET 8 SDK installed on your machine. Visual Studio 2022 or Visual Studio Code with the C# extension are recommended for the best development experience. All code samples in the book are compatible with C# 12 and .NET 8, but most will work with earlier versions as well.
There are a number of text conventions used throughout this book.
Codeintext: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Let’s dive a bit deeper and see what a general implementation of the Result type looks like.”
A block of code is set as follows:
bool IsBookPopular(Book book) { if (book.AverageRating > 4.5 && book.NumberOfReviews > 1000) { return true; } return false; }Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Refactor it using Railway-Oriented Programming (ROP) to improve the error-handling flow.”
Tips or important notes
Appear like this.
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Once you’ve read Functional Programming with C#, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
Thanks for purchasing this book!
Do you like to read on the go but are unable to carry your print books everywhere?
Is your eBook purchase not compatible with the device of your choice?
Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.
Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.
The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily
Follow these simple steps to get the benefits:
Scan the QR code or visit the link belowhttps://packt.link/free-ebook/978-1-80512-268-5
Submit your proof of purchaseThat’s it! We’ll send your free PDF and other benefits to your email directlyIn this first part, we lay the groundwork for understanding functional programming. We’ll start by introducing the core concepts of functional programming and how they apply to C#. You’ll learn about the crucial distinction between expressions and statements, and how to write more expressive code. We’ll then explore pure functions and how to minimize side effects, which are fundamental to functional programming. Finally, we’ll discuss honest functions and effective ways to handle null values, setting the stage for more robust code design.
This part has the following chapters:
Chapter 1, Getting Started with Functional ProgrammingChapter 2, Expressions and StatementsChapter 3, Pure Functions and Side EffectsChapter 4, Honest Functions, Null, and Option