google-cpp-style

작성자: clickhouse

Google C++ Style Guide rules for writing clean, maintainable C++ code. Use when writing C++, reviewing code, discussing naming conventions, formatting, class…

npx skills add https://github.com/clickhouse/pg_stat_ch --skill google-cpp-style

Google C++ Style Guide

This skill provides the complete Google C++ Style Guide for C++20. Apply these rules when writing or reviewing C++ code.

Quick Reference

TopicKey Rules
NamingTypes: PascalCase, functions: PascalCase, variables: snake_case, constants: kPascalCase, macros: UPPER_CASE
Formatting80 char lines, 2-space indent, spaces (not tabs), { on same line
HeadersSelf-contained, #define guards, include what you use
ClassesPrefer composition over inheritance, explicit constructors, private data members

Core Principles

  1. Optimize for the reader - Code is read more than written
  2. Be consistent - Follow existing patterns in the codebase
  3. Avoid surprising constructs - Prefer clear over clever

Target Version

Code should target C++20. Do not use C++23 features or non-standard extensions.

Detailed References

For complete rules on specific topics:

  • Header Files - Include guards, ordering, forward declarations
  • Scoping - Namespaces, linkage, static/global variables
  • Classes - Constructors, inheritance, operator overloading
  • Functions - Parameters, overloading, default arguments
  • C++ Features - Smart pointers, exceptions, RTTI, lambdas
  • Naming - All naming conventions with examples
  • Comments - Documentation style and requirements
  • Formatting - Whitespace, braces, line length

Common Patterns

Header File Template

#ifndef PROJECT_PATH_FILE_H_
#define PROJECT_PATH_FILE_H_

#include "project/public/header.h"

#include <sys/types.h>

#include <string>
#include <vector>

#include "other/library.h"
#include "project/internal.h"

namespace project {

class MyClass {
 public:
  MyClass();
  explicit MyClass(int value);

  void DoSomething();
  int count() const { return count_; }
  void set_count(int count) { count_ = count; }

 private:
  int count_;
};

}  // namespace project

#endif  // PROJECT_PATH_FILE_H_

Class Declaration Order

class MyClass {
 public:
  // Types and type aliases
  using ValueType = int;

  // Static constants
  static constexpr int kMaxSize = 100;

  // Constructors and assignment
  MyClass();
  MyClass(const MyClass&) = default;
  MyClass& operator=(const MyClass&) = default;

  // Destructor
  ~MyClass();

  // All other methods
  void Process();

 protected:
  // Protected members (if needed)

 private:
  // Private methods
  void InternalHelper();

  // Data members
  int value_;
};

Function Comments

// Returns an iterator positioned at the first entry >= `start_word`.
// Returns nullptr if no such entry exists.
// The client must not use the iterator after the table is destroyed.
std::unique_ptr<Iterator> GetIterator(absl::string_view start_word) const;

Critical Rules Summary

Always Do

  • Use #define guards in all headers
  • Make single-argument constructors explicit
  • Use nullptr (not NULL or 0) for pointers
  • Use override or final for virtual function overrides
  • Declare data members private
  • Initialize variables at declaration

Never Do

  • Use using namespace directives
  • Use C-style casts (use static_cast, etc.)
  • Use exceptions (in Google code)
  • Use non-standard extensions
  • Define macros in headers (when possible)
  • Use std::auto_ptr (use std::unique_ptr)

clickhouse의 다른 스킬

clickhouse-best-practices
clickhouse
28개의 ClickHouse 모범 사례 규칙으로, 스키마 설계, 쿼리 최적화, 데이터 수집 전략별로 구성되어 있습니다. 기본 키 및 데이터 유형 선택(변경 불가능한 설계 결정), JOIN 및 쿼리 최적화, 삽입 배치 및 변형 회피 등 세 가지 핵심 영역을 다룹니다. 영향도에 따라 우선순위가 매겨진 28개의 규칙을 포함하며, ClickHouse의 컬럼 기반 스토리지 및 희소 인덱스 메커니즘으로 인해 스키마 설계 및 쿼리 최적화 규칙은 CRITICAL로 표시됩니다. 구조화된 검토 절차를 제공합니다...
official
clickhouse-js-node-coding
clickhouse
Write idiomatic application code with the ClickHouse Node.js client (`@clickhouse/client`). Use this skill whenever a user is *building* against the Node.js…
official
clickhousectl-cloud-deploy
clickhouse
사용자가 ClickHouse를 클라우드에 배포하거나, 프로덕션 환경으로 전환하거나, ClickHouse Cloud를 사용하거나, 관리형 ClickHouse 서비스를 호스팅하거나, 로컬에서 마이그레이션하려는 경우 사용합니다.
official
clickstack-otel-collector
clickhouse
Use when a user wants to wire an OpenTelemetry collector into a Managed ClickStack service on ClickHouse Cloud, either by deploying a new local collector…
official
infra-clickhouse
clickhouse
Sets up and manages ClickHouse using the clickhousectl CLI — installs and runs a local ClickHouse server for development, and creates managed ClickHouse Cloud…
official
infra-postgres
clickhouse
Sets up and manages Postgres using the clickhousectl CLI — runs a local Docker-backed Postgres for development, and creates and operates managed ClickHouse…
official
clickhouse-best-practices
clickhouse
ClickHouse 스키마, 쿼리 또는 구성을 검토할 때 반드시 사용해야 합니다. 권장 사항을 제공하기 전에 반드시 확인해야 하는 31개의 규칙이 포함되어 있습니다. 항상 읽어보세요…
official
setup
clickhouse
이 플러그인에 포함된 ClickHouse MCP 서버 연결 설정을 사용자에게 안내합니다. 사용자가 플러그인을 처음 설치하거나 문제가 있을 때 사용합니다.
official