1 option
Refactoring with C++ : Explore Modern Ways of Developing Maintainable and Efficient Applications / Dmitry Danilov.
- Format:
- Book
- Author/Creator:
- Danilov, Dmitriĭ, author.
- Language:
- English
- Subjects (All):
- C++ (Computer program language).
- Object-oriented programming (Computer science).
- Software refactoring.
- Physical Description:
- 1 online resource (369 pages)
- Edition:
- First edition.
- Place of Publication:
- Birmingham, England : Packt Publishing, [2024]
- Biography/History:
- Danilov Dmitry: Dmitry Danilov is an engineer and team manager with over 15 years of experience in C++. Throughout his career, he has developed network sniffers and analyzers, audio/video streaming solutions, low-level embedded applications in telecommunications, and distributed systems. Originally from Odesa, Ukraine, Dmitry graduated with a Master's degree in Computer Engineering from Odesa National Polytechnic University. He currently resides in Tel Aviv, Israel, where he continues to advance his career in technology. In addition to his professional career, Dmitry demonstrates his passion for knowledge sharing and engaging with the tech community through his blog and by actively speaking at various events, including Core C++ Conference and Core C++ Group Meetup Israel.
- Summary:
- Improve readability and understandability of code using C++ best practices Key Features Enrich your coding skills using features from the modern C++ standard and industry approved libraries Implement refactoring techniques and SOLID principles in C++ Apply automated tools to improve your code quality Purchase of the print or Kindle book includes a free PDF eBook Book Description Despite the prevalence of higher-level languages, C++ is still running the world, from bare-metal embedded systems to distributed cloud-native systems. C++ is on the frontline whenever there is a need for a performance-sensitive tool supporting complex data structures. The language has been actively evolving for the last two decades. This book is a comprehensive guide that shows you how to implement SOLID principles and refactor legacy code using the modern features and approaches of C++, the standard library, Boost library collection, and Guidelines Support Library by Microsoft. The book begins by describing the essential elements of writing clean code and discussing object-oriented programming in C++. You'll explore the design principles of software testing with examples of using popular unit testing frameworks such as Google Test. The book also guides you through applying automated tools for static and dynamic code analysis using Clang Tools. By the end of this book, you'll be proficient in applying industry-approved coding practices to design clean, sustainable, and readable real-world C++ code. What you will learn Leverage the rich type system of C++ to write safe and elegant code Create advanced object-oriented designs using the unique features of C++ Minimize code duplication by using metaprogramming Refactor code safely with the help of unit tests Ensure code conventions and format with clang-format Facilitate the usage of modern features automatically with clang-tidy Catch complex bugs such as memory leakage and data races with Clang AddressSanitizer and ThreadSanitizer Who this book is for This book will benefit experienced C++ programmers the most, but is also suitable for technical leaders, software architects, and senior software engineers who want to save on costs and improve software development process efficiency by using modern C++ features and automated tools.
- Contents:
- Cover
- Title Page
- Copyright and Credits
- Dedication
- Contributors
- Table of Contents
- Preface
- Chapter 1: Coding Standards in C++
- The difference between good code and bad code
- Why coding standards are important
- Code convention
- Language features limitations
- General guidelines
- Readability, efficiency, maintainability, and usability
- Readability
- Efficiency
- Maintainability
- Usability
- Summary
- Chapter 2: Main Software Development Principles
- SOLID
- The Single Responsibility Principle
- The Open-Closed Principle
- The Liskov Substitution Principle
- The Dependency inversion principle
- The KISS principle
- The KISS and SOLID Principles together
- Side effects and immutability
- Con.1 - by default, make objects immutable
- Con.2 - by default, make member functions const
- Con.3 - by default, pass pointers and references to const
- Con.4 - use const to define objects with values that do not change after construction
- Con.5 - use constexpr for values that can be computed at compile time
- Constness and data races
- Chapter 3: Causes of Bad Code
- The need to deliver the product
- The developer's personal taste
- Multiple ways of solving the same problem in C++
- Revisiting Bob and Alice's example
- Raw pointers and C functions versus Standard Library functions
- Inheritance versus templates
- Example - handling errors
- Projects using different approaches
- Lack of knowledge in C++
- Using raw pointers and manual memory management
- Incorrect use of smart pointers
- Efficient use of move semantics
- Misusing const correctness
- Inefficient string handling
- Undefined behavior with lambdas
- Misunderstanding undefined behavior
- Misuse of C-style arrays
- Insufficient pointer usage
- Building std::shared_ptr
- Copying std::shared_ptr by value.
- Cyclic dependencies with std::shared_ptr
- Checking the std::weak_ptr status
- Chapter 4: Identifying Ideal Candidates for Rewriting - Patterns and Anti-Patterns
- What kind of code is worth rewriting?
- Smelly code and its basic characteristics
- Anti-patterns
- The pitfalls of magic numbers - a case study on data chunking
- Legacy code
- Chapter 5: The Significance of Naming
- General naming principles
- Descriptiveness
- Consistency
- Unambiguity
- Pronounceability
- Scope and lifetimes
- Avoid encoding type or scope information
- Class and method naming
- Naming variables
- Utilize namespaces
- The use of domain-specific language
- Balancing long names and comments in code
- Exploring popular C++ coding conventions - Google, LLVM, and Mozilla
- Chapter 6: Utilizing a Rich Static Type System in C++
- Utilizing Chrono for time duration
- Improving Pointer Safety with not_null and std::optional
- The pitfalls of raw pointers
- Using not_null from the Guidelines Support Library
- Utilizing std::optional for optional values
- A comparison between raw pointers and nullptr
- Leveraging std::expected for expected results and errors
- Strong typing with enum class and scoped enumerations
- A review of enum class
- The benefits over traditional enums
- Real-world scenarios
- Leveraging the standard library's type utilities
- std::variant - a type-safe union
- std::any - type-safe containers for any type
- Advanced type techniques
- Avoiding common pitfalls in advanced type usage
- Writing robust code with type checks
- Implicit conversions and type coercion
- Chapter 7: Classes, Objects, and OOP in C++
- Good candidates for classes
- Cohesion
- Encapsulation
- Reusability
- Abstraction
- Real-world entities
- Manage complexity.
- Minimizing class responsibilities through encapsulation
- Usage of structs and classes in C++
- Common method types in classes - getters and setters
- Inheritance in C++
- Evolution of inheritance in C++
- Implementation of inheritance at the binary level
- Pros and cons of inheritance
- Base class - Discount
- Derived class - SeasonalDiscount
- Derived class - ClearanceDiscount
- Tight coupling problems
- Solution - decouple with the strategy pattern
- Templates and generic programming
- What are templates good for?
- Generic algorithms
- Container classes
- How templates work
- How templates are instantiated
- A real-world example of template usage in C++
- Defining currencies
- Defining assets
- Using the financial system
- Disadvantages of using templates in system design
- Chapter 8: Designing and Developing APIs in C++
- Principles of minimalistic API design
- Techniques for achieving minimalism
- Real-world examples of minimalistic API design
- Common pitfalls and how to avoid them
- Important caveats of developing shared libraries in C++
- Shared libraries within a single project
- Shared libraries for wider distribution
- Example - MessageSender class
- Chapter 9: Code Formatting and Naming Conventions
- Why is code formatting important?
- Overview of existing tools that facilitate compliance with coding conventions
- cpplint
- Artistic Style
- Uncrustify
- Editor plugins
- Clang-Format
- Clang-Format configuration - a deep dive into customizing your formatting rules
- Leveraging existing presets
- Extending and overriding presets
- Ignoring specific lines with Clang-Format
- Endless options for configuration
- Version control and sharing
- Integrating Clang-Format into the build system
- Clang-Format report examples
- Extending for code format checks for CI.
- Clang-Format support across various editors
- Checking name styling
- Integrating Clang-Tidy into the build system
- Checking source code name styling with Clang-Tidy
- Fixing naming issues automatically
- Important caveats
- Example project
- Clang-Tidy support across various editors
- Chapter 10: Introduction to Static Analysis in C++
- The essence of static analysis
- Leveraging newer compiler versions for enhanced static analysis
- Compiler settings to harden C++ code
- GCC
- Clang
- MSVC
- Static analysis via multiple compilers
- Highlighting compiler differences - unused private members in GCC versus Clang
- Highlighting compiler differences - compiler checks for uninitialized variables
- Exploring static analysis with Clang-Tidy
- Categories of checks in Clang-Tidy
- Expanding Clang-Tidy's capabilities with custom checks
- Fine-tuning Clang-Tidy for customized static analysis
- Overview of static analysis tools - comparing PVS-Studio, SonarQube, and others to Clang-Tidy
- PVS-Studio
- SonarQube
- Other notable tools
- Comparison with Clang-Tidy
- Chapter 11: Dynamic Analysis
- Compiler-based dynamic code analysis
- ASan
- LeakSanitizer (LSan)
- MemorySanitizer (MSan)
- TSan
- UBSan
- Dynamic code analysis with Valgrind
- Setting up Valgrind
- Memcheck - the comprehensive memory debugger
- Helgrind - threading error detector
- Performance impact, fine-tuning, and limitations
- Other notable tools in the Valgrind suite
- Data Race Detector (DRD) - a thread error detector
- Cachegrind
- Callgrind
- Massif
- Dynamic heap analysis tool (DHAT)
- Chapter 12: Testing
- Test-driven development
- Unit testing in C++
- C++ unit testing frameworks
- Google Test and Google Mock
- Integrating Google Test into a C++ project
- Usage of Google Test in C++ projects.
- Writing a simple test
- Using a test fixture
- The main function
- Running Google Test tests
- Advanced features of Google Test
- Using gMock in C++ projects
- Example of using gMock
- Mocking non-virtual methods via dependency injection
- Mocking with templates
- The Nice, the Strict, and the Naggy
- Other notable C++ unit testing frameworks
- Catch2
- Boost.Test
- Doctest
- Google Test versus Catch2 versus Boost.Test versus Doctest
- Good candidates for unit tests
- E2E testing in software development
- E2E testing frameworks
- When to use E2E testing
- Situations favoring E2E testing
- Complex interactions
- Real-world environment testing
- Automatic test coverage tracking tools
- Automatic test coverage tracking tools with examples
- Utilizing hit maps for enhanced test coverage analysis
- Recommendations for code coverage
- Chapter 13: Modern Approach to Managing Third Parties
- Overview of linking and shared V threads::ThreadsS static libraries
- Managing third-party libraries in C++
- Installing libraries with OS package managers
- Using Git as a third-party manager via submodules
- Using CMake FetchContent to download libraries
- Conan - advanced dependency management
- Conan configuration and features
- Library locations and Conan Center
- Configuring static or dynamic linking
- Extending Conan with custom packages
- CMake integration
- Other build system integration
- Custom integration
- Conclusion
- vcpkg
- Key differences from Conan
- Operating system support
- Example of configuring a project with vcpkg
- Utilizing Docker for C++ builds
- Chapter 14: Version Control
- What is a good commit?
- The principle of singular focus
- The art of communication
- The art of refinement
- Conventional Commits specification
- Linking code to context
- Overview and intent.
- Options and usage.
- 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: Danilov, Dmitry Refactoring with C++
- ISBN:
- 9781837639410
- OCLC:
- 1443718258
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.