دسترسی نامحدود
برای کاربرانی که ثبت نام کرده اند
برای ارتباط با ما می توانید از طریق شماره موبایل زیر از طریق تماس و پیامک با ما در ارتباط باشید
در صورت عدم پاسخ گویی از طریق پیامک با پشتیبان در ارتباط باشید
برای کاربرانی که ثبت نام کرده اند
درصورت عدم همخوانی توضیحات با کتاب
از ساعت 7 صبح تا 10 شب
ویرایش:
نویسندگان: Dmitry Danilov
سری:
ISBN (شابک) : 9781837633777, 9781804611555
ناشر: Packt Publishing Pvt Ltd
سال نشر: 2024
تعداد صفحات: 0
زبان: English
فرمت فایل : EPUB (درصورت درخواست کاربر به PDF، EPUB یا AZW3 تبدیل می شود)
حجم فایل: 5 مگابایت
در صورت تبدیل فایل کتاب Refactoring with C++: Explore modern ways of developing maintainable and efficient applications به فرمت های PDF، EPUB، AZW3، MOBI و یا DJVU می توانید به پشتیبان اطلاع دهید تا فایل مورد نظر را تبدیل نمایند.
توجه داشته باشید کتاب Refactoring با C: روش های مدرن توسعه برنامه های کاربردی قابل نگهداری و کارآمد را کاوش کنید نسخه زبان اصلی می باشد و کتاب ترجمه شده به فارسی نمی باشد. وبسایت اینترنشنال لایبرری ارائه دهنده کتاب های زبان اصلی می باشد و هیچ گونه کتاب ترجمه شده یا نوشته شده به فارسی را ارائه نمی دهد.
Refactoring with C++
Contributors
About the author
About the reviewer
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Share Your Thoughts
Download a free PDF copy of this book
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
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
Summary
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
Summary
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
Summary
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
Summary
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
Summary
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
Summary
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
Summary
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
Summary
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
Summary
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)
Summary
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
Summary
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
Summary
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
Origins and adoption
Advantages of Conventional Commits
Commitlint – enforcing commit message standards
Installation
Configuration
Local usage
Customizing rules
Basic configuration
Custom rule configuration
Scope and subject configuration
Customizing and sharing configurations
Integration with CI
Generating changelogs
Installation
GitCliff usage
Utilizing git-bisect in bug hunting
Summary
15
Code Review
What is a code review and why is it needed?
Benefits of code reviews
Preparing for code reviews
Clear guidelines
Self-review
How to pass a code review
Discuss big features with reviewers and code owners before writing code
Go over your code before publishing it
Make sure the code is compliant with the code convention
Code review is a conversation, not an order
Remember – your code is not you
How to efficiently dispute during a code review
Clear justification for changes
Reciprocal explanation from reviewees
Direct communication
Involving additional perspectives
How to be a good reviewer
Initiate the conversation
Maintain politeness and respect
Review manageable chunks
Avoid personal bias
Focus on understandability
Summary
Index
Why subscribe?
Other Books You May Enjoy
Packt is searching for authors like you
Share Your Thoughts
Download a free PDF copy of this book