Skip to main content

programming-cpp-naming-rules

C++ file and class naming conventions - folder structure matches namespaces, no redundant prefixes

설치로 이동

소스 정보

저장소
ROCm/rocprofiler-systems-skills
최근 소스 활동
2026년 2월 9일 09:12
감지된 SKILL.md 언어
영어
스타
4
포크
0

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
programming-cpp-naming-rules
description
C++ file and class naming conventions - folder structure matches namespaces, no redundant prefixes
# C++ Naming Rules Use this skill when creating new C++ files or refactoring file structure. ## Folder Structure = Namespace Folder structure should correspond to namespaces. Don't repeat namespace prefixes in filenames. ```cpp // ❌ BAD: amd_smi/amd_smi_driver.hpp namespace amd_smi { class amd_smi_driver {}; // Redundant prefix } // ✅ GOOD: amd_smi/driver.hpp namespace amd_smi { class driver {}; // Clean, folder provides context } ``` ## Rules 1. **No redundant prefixes**: If file is in `amd_smi/`, don't name it `amd_smi_driver.hpp` - use `driver.hpp` 2. **Namespace = folder path**: `foo/bar/baz.hpp` → `namespace foo::bar { class baz {} }` 3. **Class name = file name**: `driver.hpp` contains `class driver` or `struct driver` 4. **One class per file** (when practical): Easier to find and maintain ## Examples | Folder Path | File Name | Namespace | Class/Struct | |-------------|-----------|-----------|--------------| | `amd_smi/` | `driver.hpp` | `amd_smi` | `driver` | | `amd_smi/gpu/` | `metrics.hpp` | `amd_smi::gpu` | `metrics` | | `core/utils/` | `string_helper.hpp` | `core::utils` | `string_helper` | | `network/http/` | `client.hpp` | `network::http` | `client` | ## Nested Namespaces (C++17) Use nested namespace syntax when declaring: ```cpp // ✅ GOOD: C++17 nested namespace namespace network::http { class client { // ... }; } // namespace network::http // ❌ AVOID: Old style (more verbose) namespace network { namespace http { class client { // ... }; } // namespace http } // namespace network ``` ## Include Guards / #pragma once Match the full path in include guards: ```cpp // File: amd_smi/gpu/metrics.hpp #pragma once // Preferred // OR traditional include guard matching full path: #ifndef AMD_SMI_GPU_METRICS_HPP #define AMD_SMI_GPU_METRICS_HPP // ... #endif // AMD_SMI_GPU_METRICS_HPP ``` ## Summary - **Folder = namespace context** - don't repeat it in filenames - **Filename = class name** - easy to find - **Path tells the full story**: `project/module/submodule/class.hpp`
GitHub에서 보기