The Most Important Design Guideline is Testability
12The Most Important Design Guideline is Testability CppCon 2024 3 Jody Hagins jhagins@dev.nullThe Most Important Design Guideline is Testability CppCon 2024 4 Jody Hagins jhagins@dev.nullThe nullThe Most Important Design Guideline is Testability CppCon 2024 5 Jody Hagins jhagins@maystreet.com coachhagins@gmail.com6 Grad School and Winning the LotteryRemember This? 7 https://www.youtube com/watch?v=a76Z__kQJdo&t=83s8 The Most Important Design Guideline https://www.youtube.com/watch?v=a76Z__kQJdo&t=83s9 The Most Important API Design Guideline? TESTABILITY https://www.youtube.com/watch?v=a76Z__kQJdo&t=83sWhy0 码力 | 126 页 | 9.11 MB | 5 月前3Back to Basics: Move Semantics
lvalue45 David Olsen — Back to Basics: Move Semantics — CppCon 2020 #includeRvalue References Guideline: No rvalue reference to const type Use a non-const rvalue reference instead Most uses of rvalue Basics: Move Semantics — CppCon 2020 #include Rvalue References Guideline: No rvalue reference as function return type Core Guideline F.45: Don’t return a T&& Return by value instead Rvalue references Basics: Move Semantics — CppCon 2020 #include Rvalue References Guideline: No rvalue reference as function return type Core Guideline F.45: Don’t return a T&& Return by value instead Rvalue references 0 码力 | 142 页 | 1.02 MB | 5 月前3Back to Basics: Designing Classes (part 1 of 2)
scales.” (Kent Beck, TDD by Example)The Challenge of Class Design 10 Guideline: Design classes for easy change. Guideline: Design classes for easy extensions.Design Guidelines 11 Back to Basics: Readability 13 Guideline: Spent time to find good names for all entities. template< class T, std::size_t N > struct array; What does 'N' represent?Design for Readability 14 Guideline: Spent time class T, std::size_t Size > struct array; Now it’s clear!Design for Readability 15 Guideline: Spent time to find good names for all entities. template< class T, class Allocator =0 码力 | 87 页 | 5.64 MB | 5 月前3Back to Basics: Designing Classes (part 2 of 2)
// Value initialization: No default // ctor -> zero+default initData Member Initialization 10 Guideline: Prefer to create default objects by means of an empty set of braces (value initialization).Data // Value initialization: Declared // default ctor -> calls ctorData Member Initialization 13 Guideline: Avoid writing an empty default constructor.Data Member Initialization 14 Via the default constructor std::string s; int* pi; };Data Member Initialization 19 Core Guideline C.49: Prefer initialization to assignment in constructors. Core Guideline C.47: Define and initialise member variables in the order0 码力 | 76 页 | 2.60 MB | 5 月前3Design Patterns: Facts and Misconceptions
safety; … fulfills the Single-Responsibility Principle (SRP); … is a factory function.28 Core Guideline C.50: Use a factory function if you need “virtual behavior” during initialization. std::unique_ptrvolatile) Inversion of dependencies39 Guideline: The purpose of a design pattern is to introduce a fitting abstraction for a well known problem. Guideline: std::make_unique() is an implementation implementation pattern, not a design pattern. Guideline: The name of a design pattern conveys the intent of the abstraction.40 std::make_unique() … … improves exception safety; … fulfills the Single-Responsibility 0 码力 | 88 页 | 17.31 MB | 5 月前3Design Patterns
should be called “Mixin”Guidelines 48 Guideline: Prefer to use the term “Static Interface” to express the intent to create a static family of types. Guideline: Prefer to use the term “Mixin” to express implementation details from a base class. Guideline: “Static Interface” is a design pattern. Explicit object parameters (an implementation detail) cannot replace CRTP. Guideline: “Mixins” are an implementation be present by coincident.Guidelines 53 Guideline: Prefer to use the term “Static Interface” to express the intent to create a static family of types. Guideline: Prefer to use the term “Mixin” to express0 码力 | 136 页 | 7.95 MB | 5 月前3The Roles of Symmetry And Orthogonality In Design
Inviolate principle or behavior Always true Rule • Highly regarded principle Exceptions may apply Guideline • General pattern Violations not uncommon • Examples: • C++ Language Specification (Is all about Inviolate principle or behavior Always true Rule • Highly regarded principle Exceptions may apply Guideline • General pattern Violations not uncommon Guess • Bias projection You don’t know • Examples: Inviolate principle or behavior Always true Rule • Highly regarded principle Exceptions may apply Guideline • General pattern Violations not uncommon Guess • Bias projection You don’t knowCharley Bay0 码力 | 151 页 | 3.20 MB | 5 月前3Calling Functions A Tutorial
main() { } // Ambiguous function call between (3) and (4) N1::S s{}; g( s );Guidelines 31 Guideline: Remember that ADL only works for user-defined types.Argument Dependent Lookup 32 namespace N1 S) N1::S s1{}; N1::S s2{}; g( s1, s2 );Guidelines 35 Guideline: Prefer unqualified name lookup to qualified name lookup. Core Guideline C.165: Use using for customisation pointsTwo-Phase Lookup function call R1 R1 R2 R3 R3 R2Guidelines 80 Core Guideline C.163: Overload only for operations that are roughly equivalent Guideline: Prevent complex overloading situations that may result in0 码力 | 111 页 | 5.11 MB | 5 月前3Breaking Dependencies: The SOLID Principles
database updateBalance( amount ); return; }25 The Single-Responsibility Principle (SRP) Guideline: Prefer cohesive software entities. Everything that does not strictly belong together, should be required concepts; … does not have to be modified for new types.54 The Open-Closed Principle (OCP) Guideline: Prefer software design that allows the addition of types or operations without the need to modify Substitution Principle (LSP) Guideline: Make sure that inheritance is about behavior, not about data. Guideline: Make sure that the contract of base types is adhered to. Guideline: Make sure to adhere to0 码力 | 96 页 | 2.14 MB | 5 月前3Back to Basics: Exceptions
swap Operations Can usually be implemented in terms of non-failing (basic) operations Core Guideline C.66: Make move operations noexcept.The Benefits of noexcept 91 noexcept makes the promise to Exception-Safe Code 95 and More CorrectGuidelines 96 Guideline: RAII is the single most important idiom of the C++ programming language. Use it! Guideline: All functions should at least provide the basic basic exception safety guarantee, if possible and reasonable the strong guarantee. Guideline: Consider the no-throw guarantee, but only provide it if you can guarantee it even for possible future changes0 码力 | 111 页 | 4.87 MB | 5 月前3
共 417 条
- 1
- 2
- 3
- 4
- 5
- 6
- 42