C++ تمیز: الگوها و بهترین شیوههای توسعه نرمافزار پایدار با C++ 17
Clean C++ : Sustainable Software Development Patterns and Best Practices with C++ 17
معرفی کتاب «C++ تمیز: الگوها و بهترین شیوههای توسعه نرمافزار پایدار با C++ 17» (با عنوان لاتین Clean C++ : Sustainable Software Development Patterns and Best Practices with C++ 17) نوشتهٔ Stephan Roth (auth.)، منتشرشده توسط نشر Apress در سال 2017. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.
Write maintainable, extensible, and durable software with modern C++. This book is a must for every developer, software architect, or team leader who is interested in good C++ code, and thus also wants to save development costs. If you want to teach yourself about writing clean C++, __Clean C++__ is exactly what you need. It is written to help C++ developers of all skill levels and shows by example how to write understandable, flexible, maintainable, and efficient C++ code. Even if you are a seasoned C++ developer, there are nuggets and data points in this book that you will find useful in your work.If you don't take care with your code, you can produce a large, messy, and unmaintainable beast in any programming language. However, C++ projects in particular are prone to be messy and tend to slip into bad habits. Lots of C++ code that is written today looks as if it was written in the 1980s.It seems that C++ developers have been forgotten by those who preach Software Craftsmanship and Clean Code principles. The Web is full of bad, but apparently very fast and highly optimized C++ code examples, with cruel syntax that completely ignores elementary principles of good design and well-written code. This book will explain how to avoid this scenario and how to get the most out of your C++ code. You'll find your coding becomes more efficient and, importantly, more fun.**What You'll Learn** * Gain sound principles and rules for clean coding in C++ * Carry out test driven development (TDD) * Discover C++ design patterns and idioms * Apply these design patterns **Who This Book Is For**Any C++ developer and software engineer with an interest in producing better code. Contents at a Glance 5 Contents 6 About the Author 12 About the Technical Reviewer 13 Acknowledgments 14 Chapter 1: Introduction 15 Software Entropy 16 Clean Code 17 Why C++? 18 C++11 – The Beginning of a New Era 18 Who This Book Is For 19 Conventions Used in This Book 19 Sidebars 19 Notes, Tips, and Warnings 20 Code Samples 20 Coding Style 20 Companion Website and Source Code Repository 21 UML Diagrams 21 Chapter 2: Build a Safety Net 22 The Need for Testing 22 Introduction into Testing 24 Unit Tests 26 What about QA? 27 Rules for Good Unit Tests 28 Test Code Quality 28 Unit Test Naming 28 Unit Test Independence 29 One Assertion per Test 30 Independent Initialization of Unit Test Environments 31 Exclude Getters and Setters 31 Exclude Third-Party Code 31 Exclude External Systems 32 And What Do We Do with the Database? 32 Don’t Mix Test Code with Production Code 32 Tests Must Run Fast 35 Test Doubles (Fake Objects) 35 Chapter 3: Be Principled 39 What Is a Principle? 39 KISS 40 YAGNI 40 DRY 41 Information Hiding 41 Strong Cohesion 44 Loose Coupling 47 Be Careful with Optimizations 51 Principle of Least Astonishment (PLA) 51 The Boy Scout Rule 51 Chapter 4: Basics of Clean C++ 53 Good Names 53 Names Should Be Self-Explanatory 55 Use Names from the Domain 56 Choose Names at an Appropriate Level of Abstraction 57 Avoid Redundancy When Choosing a Name 58 Avoid Cryptic Abbreviations 58 Avoid Hungarian Notation and Prefixes 59 Avoid Using the Same Name for Different Purposes 60 Comments 60 Let the Code Tell a Story 61 Do Not Comment Obvious Things 61 Don’t Disable Code with Comments 62 Don’t Write Block Comments 62 Don’t Use Comments to Substitute Version Control 64 The Rare Cases Where Comments Are Useful 65 Documentation Generation from Source Code 66 Functions 68 One Thing, No More! 70 Let Them Be Small 71 “But the Call Time Overhead!” 71 Function Naming 72 Use Intention-Revealing Names 73 Arguments and Return Values 73 Number of Arguments 74 Avoid Flag Arguments 75 Avoid Output Arguments 77 Don’t Pass or Return 0 (NULL, nullptr) 79 Strategies to Avoid Regular Pointers 80 Prefer simple object construction on the stack instead of on the heap 80 In a function’s argument list, use (const) references instead of pointers 82 If it is inevitable to deal with a pointer to a resource, use a smart one 82 If an API returns a raw pointer... 82 The Power of const correctness 82 About Old C-style in C++ Projects 84 Prefer C++ Strings and Streams over Old C-Style char* 84 Avoid Using printf(), sprintf(), gets(), etc. 86 Prefer Standard Library Containers over Simple C-style Arrays 89 Use C++ casts Instead of Old C-Style Casts 92 Avoid Macros 94 Chapter 5: Advanced Concepts of Modern C++ 96 Managing Resources 96 Resource Acquisition Is Initialization (RAII) 98 Smart Pointers 98 Unique Ownership with std::unique_ptr 99 Shared Ownership with std::shared_ptr 100 No Ownership, but Secure Access with std::weak_ptr 101 Avoid Explicit New and Delete 104 Managing Proprietary Resources 104 We Like to Move It 105 What Are Move Semantics? 106 The Matter with Those lvalues and rvalues 107 rvalue References 108 Don’t Enforce Move Everywhere 109 The Rule of Zero 110 The Compiler Is Your Colleague 113 Automatic Type Deduction 114 Computations during Compile Time 117 Variable Templates 119 Don’t Allow Undefined Behavior 120 Type-Rich Programming 121 Know Your Libraries 127 Take Advantage of 128 Easier Parallelization of Algorithms Since C++17 129 Sorting and Output of a Container 131 Comparing Two Sequences 132 Take Advantage of Boost 133 More Libraries That You Should Know About 134 Proper Exception and Error Handling 134 Prevention Is Better Than Aftercare 135 No Exception-Safety 136 Basic Exception-Safety 136 Strong Exception-Safety 136 The No-Throw Guarantee 137 An Exception Is an Exception – Literally! 139 If You Can’t Recover, Get Out Quickly 140 Define User-Specific Exception Types 140 Throw by Value, Catch by const Reference 142 Pay Attention to the Correct Order of Catch-Clauses 142 Chapter 6: Object Orientation 144 Object-Oriented Thinking 144 Abstraction – the Key to Master Complexity 146 Principles for Good Class Design 146 Keep Classes Small 147 Single Responsibility Principle (SRP) 148 Open-Closed Principle (OCP) 148 Liskov Substitution Principle (LSP) 149 The Square-Rectangle Dilemma 149 Favor Composition over Inheritance 158 Interface Segregation Principle (ISP) 160 Acyclic Dependency Principle 161 Dependency Inversion Principle (DIP) 164 Don’t Talk to Strangers (Law of Demeter) 169 Avoid Anemic Classes 174 Tell, Don’t Ask! 174 Avoid Static Class Members 176 Chapter 7: Functional Programming 178 What Is Functional Programming? 179 What Is a Function? 180 Pure vs. Impure Functions 181 Functional Programming in Modern C++ 182 Functional Programming with C++ Templates 182 Function-Like Objects (Functors) 184 Generator 184 Unary Function 187 Predicates 187 Binary Functors 190 Binders and Function Wrappers 190 Lambda Expressions 192 Generic Lambda Expressions (C++14) 194 Higher-Order Functions 195 Map, Filter, and Reduce 196 Map 197 Filter 197 Reduce (Fold) 198 Fold Expressions in C++17 199 Clean Code in Functional Programming 200 Chapter 8: Test-Driven Development 202 The Drawbacks of Plain Old Unit Testing (POUT) 203 Test-Driven Development as a Game Changer 204 The Workflow of TDD 204 TDD by Example: The Roman Numerals Code Kata 207 Preparations 208 The First Test 210 The Second Test 212 The Third Test and the Tidying Afterwards 212 More Sophisticated Tests with a Custom Assertion 216 It’s Time to Clean Up Again 218 Approaching the Finish Line 221 Done! 222 The Advantages of TDD 224 When We Should Not Use TDD 226 Chapter 9: Design Patterns and Idioms 227 Design Principles vs. Design Patterns 227 Some Patterns, and When to Use Them 228 Dependency Injection (DI) 228 The Singleton Anti-Pattern 229 Dependency Injection to the Rescue 232 Adapter 240 Strategy 241 Command 245 Command Processor 249 Composite 252 Observer 255 Factories 260 Simple Factory 260 Facade 263 Money Class 264 Special Case Object (Null Object) 267 What Is an Idiom? 270 Some Useful C++ Idioms 271 The Power of Immutability 271 Substitution Failure Is Not an Error (SFINAE) 272 The Copy-and-Swap Idiom 275 Pointer to Implementation (PIMPL) 278 Appendix A: Small UML Guide 282 Class Diagrams 282 Class 282 Interface 284 Association 287 Generalization 289 Dependency 290 Components 291 Stereotypes 292 Bibliography 293 Index 295 Write maintainable, extensible, and durable software with modern C++. This book is a must for every developer, software architect, or team leader who is interested in good C++ code, and thus also wants to save development costs. If you want to teach yourself about writing clean C++, Clean C++ is exactly what you need. It is written to help C++ developers of all skill levels and shows by example how to write understandable, flexible, maintainable, and efficient C++ code. Even if you are a seasoned C++ developer, there are nuggets and data points in this book that you will find useful in your work. If you don't take care with your code, you can produce a large, messy, and unmaintainable beast in any programming language. However, C++ projects in particular are prone to be messy and tend to slip into bad habits. Lots of C++ code that is written today looks as if it was written in the 1980s. It seems that C++ developers have been forgotten by those who preach Software Craftsmanship and Clean Code principles. The Web is full of bad, but apparently very fast and highly optimized C++ code examples, with cruel syntax that completely ignores elementary principles of good design and well-written code. This book will explain how to avoid this scenario and how to get the most out of your C++ code. You'll find your coding becomes more efficient and, importantly, more fun. What You'll Learn Gain sound principles and rules for clean coding in C++ Carry out test driven development (TDD) Discover C++ design patterns and idioms Apply these design patterns Who This Book Is For Any C++ developer and software engineer with an interest in producing better code. Write maintainable, extensible, and durable software with modern C++. This book is a must for every developer, software architect, or team leader who is interested in good C++ code, and thus also wants to save development costs. If you want to teach yourself about writing clean C++, Clean C++ is exactly what you need. It is written to help C++ developers of all skill levels and shows by example how to write understandable, flexible, maintainable, and efficient C++ code. Even if you are a seasoned C++ developer, there are nuggets and data points in this book that you will find useful in your work. If you don't take care with your code, you can produce a large, messy, and unmaintainable beast in any programming language. However, C++ projects in particular are prone to be messy and tend to slip into bad habits. Lots of C++ code that is written today looks as if it was written in the 1980s. It seems that C++ developers have been forgotten by those who preach Software Craftsmanship and Clean Code principles. The Web is full of bad, but apparently very fast and highly optimized C++ code examples, with cruel syntax that completely ignores elementary principles of good design and well-written code. This book will explain how to avoid this scenario and how to get the most out of your C++ code. You'll find your coding becomes more efficient and, importantly, more fun. You will: Gain sound principles and rules for clean coding in C++ Carry out test driven development (TDD) Discover C++ design patterns and idioms Apply these design patterns. -- Provided by publisher Front Matter ....Pages i-xvii Introduction (Stephan Roth)....Pages 1-7 Build a Safety Net (Stephan Roth)....Pages 9-25 Be Principled (Stephan Roth)....Pages 27-40 Basics of Clean C++ (Stephan Roth)....Pages 41-83 Advanced Concepts of Modern C++ (Stephan Roth)....Pages 85-132 Object Orientation (Stephan Roth)....Pages 133-166 Functional Programming (Stephan Roth)....Pages 167-190 Test-Driven Development (Stephan Roth)....Pages 191-215 Design Patterns and Idioms (Stephan Roth)....Pages 217-271 Back Matter ....Pages 273-291
دانلود کتاب C++ تمیز: الگوها و بهترین شیوههای توسعه نرمافزار پایدار با C++ 17