Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Refactoring with C++

You're reading from   Refactoring with C++ Explore modern ways of developing maintainable and efficient applications

Arrow left icon
Product type Paperback
Published in Jul 2024
Publisher Packt
ISBN-13 9781837633777
Length 368 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mr. Dmitry Danilov Mr. Dmitry Danilov
Author Profile Icon Mr. Dmitry Danilov
Mr. Dmitry Danilov
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Chapter 1: Coding Standards in C++ 2. Chapter 2: Main Software Development Principles FREE CHAPTER 3. Chapter 3: Causes of Bad Code 4. Chapter 4: Identifying Ideal Candidates for Rewriting – Patterns and Anti-Patterns 5. Chapter 5: The Significance of Naming 6. Chapter 6: Utilizing a Rich Static Type System in C++ 7. Chapter 7: Classes, Objects, and OOP in C++ 8. Chapter 8: Designing and Developing APIs in C++ 9. Chapter 9: Code Formatting and Naming Conventions 10. Chapter 10: Introduction to Static Analysis in C++ 11. Chapter 11: Dynamic Analysis 12. Chapter 12: Testing 13. Chapter 13: Modern Approach to Managing Third Parties 14. Chapter 14: Version Control 15. Chapter 15: Code Review 16. Index 17. Other Books You May Enjoy

What this book covers

Chapter 1, Coding Standards in C++, explores the world of clean code and its crucial role in successful software projects. We discuss technical debt and how poor-quality code contributes to its accumulation. The chapter also covers the importance of code formatting and documentation, emphasizing their role in maintaining a manageable and effective codebase. We introduce common conventions and best practices used in the C++ community, highlighting the necessity of clean code and proper documentation for any project.

Chapter 2, Main Software Development Principles, covers key software design principles for creating well-structured and maintainable code. We discuss the SOLID principles—Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion—which help developers write code that is easy to understand, test, and modify. We also highlight the importance of levels of abstraction, the concepts of side effects and mutability, and their impact on software quality. By applying these principles, developers can create more robust, reliable, and scalable software.

Chapter 3, Causes of Bad Code, identifies the key factors leading to subpar code in C++. These include the pressure to deliver quickly, the flexibility of C++ allowing multiple solutions to the same problem, personal coding styles, and a lack of knowledge of modern C++ features. Understanding these causes helps developers avoid common pitfalls and improve existing codebases effectively.

Chapter 4, Identifying Ideal Candidates for Rewriting - Patterns and Anti-Patterns, focuses on identifying ideal candidates for refactoring in C++ projects. We will explore factors that make code segments suitable for refactoring, such as technical debt, complexity, and poor readability. We will also discuss common patterns and anti-patterns, providing guidelines and techniques for improving code structure, readability, and maintainability without altering its behavior. This chapter aims to equip developers with the knowledge to enhance the quality and robustness of their C++ codebases effectively.

Chapter 5, The Significance of Naming, highlights the crucial role of naming conventions in C++ programming. Proper names for variables, functions, and classes enhance code readability and maintainability. We discuss best practices for naming, the impact of poor naming on code efficiency, and the importance of consistent coding conventions. By understanding and applying these principles, you will write clearer and more effective code.

Chapter 6, Utilizing a Rich Static Type System in C++, explores the powerful static type system in C++, emphasizing its role in writing robust, efficient, and maintainable code. We discuss advanced techniques like using the <chrono> library for time durations, not_null wrappers, and std::optional for safer pointer handling. Additionally, we look at external libraries like Boost for enhancing type safety. Through real-world examples, we demonstrate how to leverage these tools to harness the full potential of C++’s type system, resulting in more expressive and error-resistant code.

Chapter 7, Classes, Objects, and OOP in C++, focuses on advanced topics in classes, objects, and object-oriented programming (OOP) in C++. We cover class design, method implementation, inheritance, and template usage. Key topics include optimizing class encapsulation, advanced method practices, evaluating inheritance versus composition, and sophisticated template techniques. Practical examples illustrate these concepts, helping you create robust and scalable software architectures.

Chapter 8, Designing and Developing APIs in C++, explores the principles and practices for designing maintainable APIs in C++. We discuss the importance of clarity, consistency, and extensibility in API design. Through concrete examples, we illustrate best practices that help create intuitive, easy-to-use, and robust APIs. By applying these principles, you will develop APIs that meet user needs and remain adaptable over time, ensuring the longevity and success of your software libraries.

Chapter 9, Code Formatting and Naming Conventions, explore the critical role of code formatting and naming conventions in creating robust and maintainable software. While these topics may seem minor, they greatly enhance code readability, simplify maintenance, and foster effective team collaboration, especially in complex languages like C++. We delve into the importance of code formatting and provide practical knowledge on using tools like Clang-Format and editor-specific plugins to implement consistent formatting. By the end of this chapter, you’ll understand the significance of these practices and how to apply them effectively in your C++ projects.

Chapter 10, Introduction to Static Analysis in C++, discusses the crucial role of static analysis in ensuring code quality and reliability in C++ development. We discuss how static analysis identifies bugs quickly and cost-effectively, making it a key component of software quality assurance. We delve into popular tools like Clang-Tidy, PVS-Studio, and SonarQube, and guide integrating static analysis into your development workflow.

Chapter 11, Dynamic Analysis, explores dynamic code analysis in C++, focusing on tools that scrutinize program behavior during execution to detect issues like memory leaks, race conditions, and runtime errors. We cover compiler-based sanitizers such as Address Sanitizer (ASan), Thread Sanitizer (TSan), and Undefined Behavior Sanitizer (UBSan), along with Valgrind for thorough memory debugging. By understanding and integrating these tools into your development workflow, you can ensure cleaner, more efficient, and reliable C++ code.

Chapter 12, Testing, emphasizes the crucial role of software testing in ensuring quality, reliability, and maintainability. We cover various testing methodologies, starting with unit testing to validate individual components, followed by integration testing to examine the interaction between integrated units. We then move to system testing for a comprehensive assessment of the entire software system and conclude with acceptance testing to ensure the software meets end-user requirements. By understanding these methodologies, you will grasp how testing underpins the development of robust and user-centric software.

Chapter 13, Modern Approach to Managing Third Parties, addresses the critical role of third-party libraries in C++ development. We explore the basics of third-party library management, including the impact of static versus dynamic compilation on deployment. Given C++’s lack of a standardized library ecosystem, we examine tools like vcpkg and Conan to understand their advantages in integrating and managing libraries. Additionally, we discuss the use of Docker for creating consistent and reproducible development environments. By the end of this chapter, you’ll be equipped to choose and manage third-party libraries effectively, enhancing your development workflow and software quality.

Chapter 14, Version Control, highlights the importance of maintaining a clean commit history in software development. We discuss best practices for clear and purposeful commit messages and introduce tools like Git, Conventional Commit Specification, and commit linting. By following these principles, developers can enhance communication, collaboration, and project maintainability.

Chapter 15, Code Review, explores the critical role of code review in ensuring robust and maintainable C++ code. While automated tools and methodologies provide significant benefits, they are not foolproof. Code reviews, conducted by human reviewers, help catch errors that automated processes may miss and ensure adherence to standards. We discuss strategies and practical guidelines for effective code reviews, emphasizing their role in preventing bugs, enhancing code quality, and fostering a collaborative culture of learning and accountability.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image