Convert Figma logo to code with AI

cpp-best-practices logocppbestpractices

Collaborative Collection of C++ Best Practices. This online resource is part of Jason Turner's collection of C++ Best Practices resources. See README.md for more information.

8,016
877
8,016
35

Top Related Projects

The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++

Collaborative Collection of C++ Best Practices. This online resource is part of Jason Turner's collection of C++ Best Practices resources. See README.md for more information.

6,118

Guidelines Support Library

Abseil Common Libraries (C++)

Style guides for Google-originated open-source projects

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.

Quick Overview

The cpp-best-practices/cppbestpractices repository is a collaborative effort to create a comprehensive guide for C++ best practices. It aims to provide developers with a curated set of recommendations and guidelines for writing clean, efficient, and maintainable C++ code. The project covers various aspects of C++ programming, from basic syntax to advanced concepts and tools.

Pros

  • Comprehensive coverage of C++ best practices
  • Community-driven and regularly updated
  • Includes practical examples and explanations
  • Addresses both beginner and advanced topics

Cons

  • Some recommendations may be subjective or context-dependent
  • Can be overwhelming for newcomers due to the vast amount of information
  • May not always keep up with the latest C++ standards and features
  • Lacks interactive elements or exercises for practice

Code Examples

This repository is not a code library but a collection of best practices and guidelines. Therefore, there are no specific code examples to showcase. However, the repository does contain code snippets within its documentation to illustrate various concepts and best practices.

Getting Started

As this is not a code library, there's no specific installation or setup process. To get started with the cpp-best-practices/cppbestpractices repository:

  1. Visit the GitHub repository: https://github.com/cpp-best-practices/cppbestpractices
  2. Browse through the table of contents in the README.md file
  3. Click on specific topics of interest to read the detailed guidelines and recommendations
  4. Consider bookmarking the repository for easy reference during your C++ development projects

Competitor Comparisons

The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++

Pros of CppCoreGuidelines

  • More comprehensive and detailed guidelines
  • Backed by the C++ Standards Committee
  • Regular updates and maintenance

Cons of CppCoreGuidelines

  • Can be overwhelming for beginners
  • Less focus on practical implementation examples
  • More formal and academic in tone

Code Comparison

CppCoreGuidelines example:

void f(int* p, int n)   // don't: pointer arithmetic
{
    for (int i = 0; i < n; ++i) p[i] = 7;
}

cppbestpractices example:

void f(span<int> arr)   // do: use span for array views
{
    for (auto& elem : arr) elem = 7;
}

The CppCoreGuidelines example shows what not to do, while cppbestpractices demonstrates a modern, safer approach using span and range-based for loops.

CppCoreGuidelines offers a more extensive set of rules and explanations, making it suitable for in-depth study and reference. However, cppbestpractices provides more concise, practical advice that may be easier for developers to implement in their daily work.

Both repositories are valuable resources for C++ developers, with CppCoreGuidelines being more authoritative and comprehensive, while cppbestpractices offers a more accessible and practical approach to best practices in C++ programming.

Collaborative Collection of C++ Best Practices. This online resource is part of Jason Turner's collection of C++ Best Practices resources. See README.md for more information.

Pros of cppbestpractices

  • Comprehensive guide covering various aspects of C++ development
  • Regularly updated with community contributions
  • Includes sections on modern C++ features and best practices

Cons of cppbestpractices

  • May be overwhelming for beginners due to its extensive content
  • Some sections might lack detailed explanations or examples
  • Occasional inconsistencies in formatting and organization

Code Comparison

Unfortunately, there is no relevant code comparison for this repository as it primarily consists of documentation and guidelines rather than code samples.

Summary

cppbestpractices is a valuable resource for C++ developers, offering a wide range of best practices and guidelines. Its comprehensive nature makes it suitable for both experienced developers and those looking to improve their C++ skills. However, the extensive content may be challenging for beginners to navigate, and some sections could benefit from more detailed explanations or examples.

The repository's strength lies in its community-driven approach, with regular updates and contributions from various developers. This ensures that the content remains relevant and up-to-date with the latest C++ standards and industry practices.

While the lack of code samples might be a drawback for some users, the repository's focus on providing clear guidelines and explanations makes it a useful reference for developers looking to improve their C++ coding practices and project organization.

6,118

Guidelines Support Library

Pros of GSL

  • Provides concrete implementations of guidelines and abstractions
  • Offers a set of well-tested, performance-oriented components
  • Backed by Microsoft, ensuring long-term support and maintenance

Cons of GSL

  • Focuses primarily on low-level abstractions and safety features
  • May require additional learning curve for developers unfamiliar with GSL concepts
  • Less comprehensive in terms of overall C++ best practices coverage

Code Comparison

GSL example:

gsl::span<int> safe_array(int* arr, size_t size) {
    return gsl::span<int>(arr, size);
}

cppbestpractices equivalent:

std::vector<int> safe_array(int* arr, size_t size) {
    return std::vector<int>(arr, arr + size);
}

The GSL example uses gsl::span for safe array access, while cppbestpractices recommends using standard library containers like std::vector for similar safety guarantees.

Summary

GSL provides specific tools and abstractions for C++ development, focusing on safety and performance. cppbestpractices offers a broader set of guidelines covering various aspects of C++ programming. While GSL provides concrete implementations, cppbestpractices offers more general advice and best practices for writing modern C++ code.

Abseil Common Libraries (C++)

Pros of abseil-cpp

  • Comprehensive library of C++ utilities and extensions
  • Actively maintained by Google, ensuring high-quality and up-to-date code
  • Designed for compatibility with various C++ standards and compilers

Cons of abseil-cpp

  • Larger codebase, which may increase compilation times and binary size
  • Steeper learning curve due to its extensive API
  • May introduce dependencies that are not necessary for smaller projects

Code Comparison

abseil-cpp example:

#include "absl/strings/str_cat.h"
#include "absl/time/time.h"

std::string result = absl::StrCat("Time: ", absl::FormatTime("%Y-%m-%d", absl::Now()));

cppbestpractices example (using standard library):

#include <chrono>
#include <iomanip>
#include <sstream>

auto now = std::chrono::system_clock::now();
std::time_t time = std::chrono::system_clock::to_time_t(now);
std::stringstream ss;
ss << "Time: " << std::put_time(std::localtime(&time), "%Y-%m-%d");
std::string result = ss.str();

The abseil-cpp example demonstrates its concise string manipulation and time formatting utilities, while the cppbestpractices approach relies on standard library functions, which may be more verbose but have no external dependencies.

Style guides for Google-originated open-source projects

Pros of styleguide

  • Comprehensive coverage of multiple programming languages
  • Backed by Google's extensive experience and industry reputation
  • Includes detailed explanations and rationale for each guideline

Cons of styleguide

  • Less frequently updated compared to cppbestpractices
  • More rigid and less adaptable to individual project needs
  • Focuses on style rather than broader best practices

Code Comparison

styleguide (C++ example):

class MyClass {
 public:
  void DoSomething();
 private:
  int private_member_;
};

cppbestpractices (C++ example):

class MyClass
{
public:
  auto doSomething() -> void;

private:
  int privateMember{};
};

The styleguide example follows Google's naming conventions and indentation style, while the cppbestpractices example demonstrates modern C++ features like auto return type and in-class member initialization.

Both repositories offer valuable guidance for C++ developers, but they differ in scope and approach. styleguide provides a more structured set of rules across multiple languages, while cppbestpractices focuses specifically on C++ and offers a more flexible, evolving set of recommendations. Developers should consider their project requirements and team preferences when choosing between these resources.

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.

Pros of llvm-project

  • Comprehensive toolchain: Includes compiler, debugger, and other development tools
  • Extensive documentation and community support
  • Actively maintained with frequent updates and improvements

Cons of llvm-project

  • Larger and more complex codebase, potentially harder to navigate
  • Steeper learning curve for contributors
  • Focuses on implementation rather than best practices guidance

Code comparison

cppbestpractices:

// Example of a best practice
void function(const std::string& input) {
    // Use const reference for efficiency
}

llvm-project:

// Example from LLVM codebase
template <typename T>
void llvm::SmallVectorImpl<T>::grow(size_t MinSize) {
  // Complex implementation details
}

Summary

cppbestpractices is a curated collection of C++ best practices, offering guidance and recommendations for writing clean, efficient code. It's more accessible for beginners and focuses on educational content.

llvm-project, on the other hand, is a full-fledged compiler infrastructure project. It provides a complete toolchain for C++ development but requires more in-depth knowledge to contribute or utilize effectively. While it demonstrates best practices through its implementation, it doesn't explicitly teach them like cppbestpractices does.

Choose cppbestpractices for learning and improving coding standards, and llvm-project for working with or contributing to a production-grade compiler and related tools.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

cppbestpractices

Join the chat at https://gitter.im/lefticus/cppbestpractices

Collaborative Collection of C++ Best Practices

For more information please see the Preface.

This online resource is part of Jason Turner's collection of C++ Best Practices resources.