C++ Coding 指南

基于llama.cpp的极简Coding Agent构建指南 在本地运行大模型时,llama.cpp凭借其稳定的推理性能和跨硬件支持,成为部署GGUF模型的首选运行时。通过llama-server暴露的HTTP接口,开发者无需依赖厚重的Agent框架,仅用HTTP请求、JSON解析和子进程调用就能构建一个透明可控的coding agent。这种极简设计让每一步行为都显式暴露在代码中,便于调试和二次开发,尤其适合需要隐私保护、断网环境或希望深入理解Agent机制的工程实践。从模型选型、服务启动到最小动作循环的实现,再到温度、上下文长度等关键参数调优,本文提供了一套可落地 阅读详情

This document is a companion to theC++ Coding Standard. It collects various informalhints on aspects to consider when designing and implementing code in the FOO software stack.

Available C++11 features

In code compiled for all STB toolchains (i.e., most code), we have support forthe subset of C++11 features implemented by the oldest GCC version in ourtoolchains. The lower bar is currentlyGCC 4.4:

  
  
  
  
  
  
  

In code only compiled with newer toolchains, it is allowed to use newerfeatures, but please refrain from using newer features in code that in thefuture might be useful for toolchains with older GCC versions. One notable caseis unit tests where there are no restrictions since such code is built only bythe host compiler.

See also C++0x/C++11 Support in GCC.

C++11 hints

Here is a summary of things to consider when writing new code.

Watch out for user-defined literals

Before C++11:

printf("x is %"PRIu64", y is %"PRIu64"\n", x, y);

Now:

printf("x is %" PRIu64 ", y is %" PRIu64 "\n", x, y);

Spaces must be added around macros as shown above since the code otherwise willfail to compile. This is because the code is interpreted as referring to auser-defined literal.

No need to add space between “>” characters in template argument lists

Before C++11:

std::map<int, std::vector<int> >

Now:

std::map<int, std::vector<int>>

auto specifier

Before C++11:

TContainer::const_iterator iter = Container.find(x);

Now:

auto iter = Container.find(x);

See also auto specifier.

Scoped (strongly-typed) enum

Before C++11:

enum TStatus {
  STATUS_READY,
  STATUS_SET,
  STATUS_GO
};

Now:

enum class TStatus {
  READY,
  SET,
  GO
};

See also scopedenumerations.

Container literals (list initialization)

Before C++11:

std::vector<int> x;
x.push_back(1);
x.push_back(2);
x.push_back(3);

Now:

std::vector<int> x = {1, 2, 3};
// Or:
std::vector<int> x({1, 2, 3});
// Or:
std::vector<int> x{1, 2, 3};

Before C++11:

std::map<std::string, int> x;
x["a"] = 1;
x.insert(std::make_pair("b", 2));
x.insert(std::map<std::string, int>::value_type("c", 3));

Now:

std::map<std::string, int> x = {{"a", 1}, {"b", 2}, {"c", 3}};
// Or:
std::map<std::string, int> x({{"a", 1}, {"b", 2}, {"c", 3}});
// Or:
std::map<std::string, int> x{{"a", 1}, {"b", 2}, {"c", 3}};

See also listinitialization.

static_assert

Before C++11:

#include <boost/static_assert.hpp>

BOOST_STATIC_ASSERT(x);

Now:

static_assert(x, "message");

std::shared_ptr andstd::weak_ptr

Before C++11:

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

boost::shared_ptr<TExample> s;
boost::weak_ptr<TExample> w;

Now:

#include <memory>

std::shared_ptr<TExample> s;
std::weak_ptr<TExample> w;

See alsostd::shared_ptr andstd::weak_ptr.

std::unique_ptr

Before C++11:

#include <boost/scoped_ptr.hpp>

boost::scoped_ptr<TExample> x;

Now:

#include <memory>

const std::unique_ptr<TExample> x; // If no call to the reset method is needed.
std::unique_ptr<TExample> x;       // If a call to the reset method is needed.

Before C++11:

#include <memory>

std::auto_ptr<TExample> x;

Now:

#include <memory>

std::unique_ptr<TExample> x;

Note: Use std::move tomove value out of an std::unique_ptr.

See alsostd::unique_ptr.

std::bind,std::function and std::ref

Before C++11:

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/ref.hpp>

typedef boost::function<void ()> TFunction;

boost::bind(&TClass::Method, boost::ref(x), _1);

Now:

#include <functional>

using std::placeholders::_1;

typedef std::function<void ()> TFunction;

std::bind(&TClass::Method, std::ref(x), _1);

See alsostd::bind,std::functionandstd::ref.

Logging

Log levels

LevelExplanationExample
FatalA fatal error has occurred that can not be handled and prevents further execution. This log line should always be followed by a program termination – never use one without the other (tip: useKABORT). Fatals should never be reached in production code and always indicate a bug somewhere in the system.“Could not connect to name service”, “Caught an unknown exception”
ErrorAn error has occurred that affects some core functionality but can be handled and does not prevent further execution. Errors may be the symptoms of bugs, but may also be the result of problems in the environment/configuration/input.“VoD server not found”, “Child process exited unexpectedly”
WarningSomething out of the ordinary has happened but does not have any direct impact on the current task. It may be caused by input that is missing or out of bounds. It can be the symptom of bugs in the calling code.“Missing configuration, using default”, “Resource already open”
NoteThe code has reached a point where it is informative to put a message in the log. It could be triggered by a state change, an event or user input that provides useful information to a working system.“HDMI connected”, “Entering standby”
DebugUsed to provide information that can be used in debugging without requiring specific knowledge about the code internals. It could be minor state changes or extra information in addition to another log message. No pure development debugging messages should be enabled in production code.“IP address renewed”, “Initialization done, entering event loop”

How to log

All FOO code must, when possible, use theKDebug macros for logging:

KNOTE("log message");

Do not use TTracker or fprintf(stderr, ...) explicitly (unless necessary):

TTracker::GetProcessTracker()->Note("log message");
Tracker->Note("log message");
fprintf(stderr, "<N>log message\n");

Note: Producing output from commandline programs, e.g. toish, is not“logging”.

Debug log messages

Log messages on the debug level (“debug log messages”) can be used duringdevelopment but should normally not exist in production code. This is to avoidspamming the log, since too much logging causes performance problems and canconceal other log messages that indicate a real problem. In short: only logreal problems or points of general interest in production code.

During development, it may be useful to have debug log messages to tracefunction entry/exit (tip: useKTRACE_FUNCTION,variable values or other points of interest. Before the code is submitted tothe revision control system, debug log messages should be removed or protectedby a define (that is undefined by default). Alternatively, let the debug logmessages beenabled at runtime.Note that runtime-enabled debug log messages still have a performance penalty,so use them sparingly.

How to write good log messages

Some general tips on how to write good log messages:

  • Be concise. Logs should be informative and easy to understand. Prefer short expressive statements to longer, grammatically flawless sentences. Avoid capital letters and special characters just to get attention.
  • Avoid spamming. Do not repeat yourself unless there is something new to report. It is often worth a few extra lines of code to avoid log spamming. Think one extra time before adding log lines to heavily shared code.
  • Use the correct levels. Understand what level is appropriate for each log line. Remember that the failure of some functionality may be the result of an explicit configuration and thus could be expected. Keep in mind that traces often are filtered out and no warnings/errors/fatals should be shown when the box operates as expected.
Google与LLVM C++代码风格规范对比:命名、格式与现代特性实战指南 代码风格规范是软件工程中保障代码可读性、可维护性和团队协作效率的基础实践。其核心原理在于通过统一的命名、格式和语言特性使用约定,减少认知负荷,提升代码审查与长期维护的效率。在C++开发领域,遵循成熟的风格指南能显著提升代码质量,尤其在现代C++特性广泛应用的背景下,规范的代码风格有助于更好地利用智能指针、Lambda表达式等特性,确保内存安全与性能优化。Google和LLVM的C++风格指南是工业界广泛采纳的两大体系,它们分别体现了大规模软件协作与系统级软件开发的不同工程哲学。本文通过对比分析这两大指南在命 阅读详情

相关推荐

Vibe Coding + MCP:用Trae AI重塑UE5开发工作流

Vibe Coding是一种以自然语言描述需求、由AI生成代码的编程范式,正逐步改变游戏开发者的工作方式。其核心在于通过标准化协议让大模型与工程环境深度交互,而MCP(模型上下文协议)正是实现这一能力的关键桥梁,它定义了AI客户端与外部工具之间的通信标准,使AI可以读取工程结构、操作工具链,从而生成更贴合实际项目的代码。在Unreal Engine开发中,结合UE 5.8与Trae AI,开发者可以构建一套高效的AI辅助开发工作流:AI不仅生成代码,还能感知工程上下文,完成从需求描述到编译验证的闭环。这种模

weixin_32570803的博客 257

C Coding Standard (C 编程规范)

C Coding Standard (C 编程规范)

程永强 1712

【cpp】【faiss】一文搞定 faiss C++ Coding

faiss 简介 faiss是为稠密向量提供高效相似度搜索和聚类的框架。由Facebook AI Research研发。 具有以下特性。 1、提供多种检索方法 2、速度快 3、可存在内存和磁盘中 4、C++实现,提供Python封装调用。 5、大部分算法支持GPU实现 github地址: https://github.com/facebookresearch/faiss ...

杰克十里温 3849

阿里云效devstudio,coding编译运行调试C/C++

云效devstudio可以选择 或者 项目,coding必须选择 项目才行。 创建项目之后,配置好 和 就可以跑了。: : 注意这里阿里云效devstudio跟正常的vscode好像不一样, 会报错,要改成 到这里就可以调试了。阿里的使用 好像出不来结果。coding的没有问题,但是得去掉断点才能跑,不然还是会卡断点。......

JamesCurtis的博客 946

去框架化实践:基于llama.cpp与GGUF的最小coding agent实现

大模型本地部署正在成为开发者绕不开的课题,而llama.cpp作为轻量级推理引擎,配合GGUF量化模型格式,让CPU或消费级GPU也能高效运行开源模型。然而,当开发者试图在此基础上构建coding agent时,往往陷入LangChain等重型框架的依赖泥潭:抽象层次多、调试困难、迁移成本高。DLLM项目提供了一种极简思路——直接基于llama-server暴露的OpenAI兼容API编排agent循环,彻底删除框架中间层。这种去框架化的架构让工具调用、上下文管理和计划执行都保持透明可控,尤其适合本地化与私

weixin_34279246的博客 415

C++ coding standard

C++ coding standard

极智Coding | C 和 C++ 读存 bin 文件方法

本文介绍一下 C 和 C++ 读取和保存 bin 文件的方法。

极智视界 4423

arithmeticcoding.c

算术编码程序要求可以输入信源符号,可以自定义信号流,输出编码并解码。

C++ 代码--coding

目录 一、求最大公约数和最小公倍数 二、N的阶乘得到的数字末尾有多少个0 三、 编程题:求一个整数开根号 求x的平方根,精度0.01(扩展) 一、求最大公约数和最小公倍数 辗转相除法,求出最大公约数,然后最小公倍数 = 两数乘积/最小公倍数 void fun(int a, int b) { int small; int temp; //最大公约数 ...

ytusdc的博客 486

CERT编码规范中文版

cert编程规范中文版,囊括了所有的有关于cert编码规范的内容

C++ Coding Standards,101 Rules,Guidelines and Best Practices

C++ Coding Standards,101 Rules,Guidelines and Best Practices(Herb Sutter)

Effective Modern C++ 条款38:线程句柄析构行为与Vibe Coding优化指南

本文深入探讨了C++中std::thread和std::future的析构行为差异,揭示了关键编程陷阱:std::thread析构可能导致程序崩溃,而std::future析构可能隐式阻塞。文章通过代码示例和机制分析,提出了显式管理线程生命周期、谨慎使用std::async等最佳实践,并创新性地结合Vibe Coding(AI辅助编程),展示了如何优化提示词让AI生成更安全的并发代码。最后总结了不同工具的使用场景和优化方法,为开发者提供了规避并发陷阱的实用指南。

软件科学-郝学胜 916

sei-cert-cpp-coding-standard-2016-v01.pdf

最新版的SEI CERT C++ Coding Standard C++安全编码标准

【用 Vibe Coding 实现的 C++17 在线判题系统】OpenCode 入门指南:从环境搭建到上下文管理

本文重点讲解了OpenCode的安装与使用:需先安装Node.js(Linux通过apt源安装,Windows直接下载安装包),再通过npm全局安装OpenCode。文章详细说明了OpenCode的基础操作命令,包括启动/退出、主题配置、模型切换、命令面板调用、上下文压缩以及会话管理等功能,为开发者提供了AI辅助编程的实用指南。

无限进步!!! 235

计算机网络实验六 RIP 配置实验

Man! What can I say?

AClerk的博客 1592

C#报表,使用微软rdlc模板,生成Excel, PDF, Word, Image文件,使用自定义对象做数据集不连接数据库

我项目是用vs2017 建的,.NET farmwork 4.7.2 这种报表可以用于任何模式的应用,web,桌面,因为这只是生成一个文件或者文件流 步骤比较详细啰嗦,其中有讲到rdlc怎么新建设计,如果已经会设计rdlc了的可以直接跳到底部看代码的执行结果, 底部还有源码下载链接,百度盘 首先控制台安装报表包 新建rdlc 报表 建立rdlc里要用的数据模型 模型建完,或者修改都要重新...

qq_35955916的博客 5202

Coding Elegance-深度解析C/C++项目目录结构的黄金法则与实践指南

本文深度解析了构建清晰、可维护的C/C++项目目录结构的黄金法则与实践指南。针对项目结构混乱、编译效率低下等痛点,提出了以‘黄金八边形’为核心,涵盖src、include、tests等关键目录的标准化方案,并强调遵循项目结构规范是提升团队协作效率与代码质量的基础。

t1u2v的博客 397

AIDL HAL服务从零到一:构建现代Android硬件抽象层

本文详细介绍了从零开始构建现代Android AIDL HAL服务的完整流程。通过定义接口、实现服务逻辑、配置构建与VINTF清单,并最终集成到系统镜像,开发者可以掌握利用AIDL替代传统HIDL来开发硬件抽象层的核心方法。文章重点解析了AIDL HAL的创建流程,并对比了其与HIDL在语法、工具链和集成方式上的优势,帮助开发者高效构建稳定的硬件接口。

weixin_29174141的博客 145

个人总结的一些C/C++编码规范

转自 http://blog.youkuaiyun.com/liyuefeilong/article/details/50560564 对于不同的编程语言来说,具体的编码规范可以有很大的不同,但是其宗旨都是一致的,就是保证代码在高质量完成需求的同时具备良好的可读性、可维护性。例如我们可以规定某个项目的C语言程序要遵循这样的规定:变量的命名,头文件的书写和#include 等等。

skykingf的专栏 825

如何在NVIDIA CX6 网卡和华为CE交换机上为RDMA协议使能DCQCN和PFC

【代码】如何在NVIDIA CX6 网卡和华为CE交换机上使能DCQCN和PFC。

Markchen7788的博客 5090

RAG优化知识库检索(4):混合检索技术

混合检索技术在RAG(检索增强生成)系统中的应用显著提升了检索效果。本文探讨了语义检索与关键词检索的优缺点,指出两者在语义理解和精确匹配方面的互补性。通过结合BM25与向量检索,混合检索系统能够更全面地捕捉文档的相关性。文章详细介绍了并行检索、级联检索、稀疏-密集混合表示等多种结合方式,并探讨了权重调整策略,如线性组合、动态权重调整和排序融合算法。此外,稀疏-密集混合检索架构的设计和实现方案也被深入分析,展示了如何通过结合不同检索方法的优势,提升RAG系统的检索质量和效率。

分享一些感兴趣的技术方面 2073

开源项目Competitive_Coding常见问题解决方案

开源项目Competitive_Coding常见问题解决方案 项目基础介绍 Competitive_Coding 是一个专注于算法和数据结构的开源项目,旨在为参与编程竞赛的开发者提供有用的代码模板、技巧、算法和问题解决方案。该项目主要使用C++编程语言,但也包含其他语言的实现。 新手使用注意事项及解决方案 1. 代码格式不一致 问题描述:新手在贡献代码时,可能会遇到代码格式不一致的问题,导致代码难...

gitblog_01069的博客 679

Ardupilot姿态控制详解(完结篇)

本文主要是对过去写的一些APM中姿态控制流程及函数博文的汇总。 按照之前写的博文以及个人认为的学习顺序,给出APM姿态控制器的学习顺序如下: APM姿态旋转理论基础 Ardupilot姿态控制器 PID控制流程(整定后的P控制器) 详解APM的开方控制器sqrt_controller Ardupilot前馈及平滑函数input_euler_angle_roll_pitch_yaw解析 Ardupilot倾转分离函数thrust_heading_rotation_angles Ardupilot四元数姿态控制

moumde的博客 7023
上一篇: My linux install fedora 2
下一篇: 如何度量项目的进度与进展
bamboolsu
博客等级 码龄22年 200粉丝 394原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值