如何在手机上编写c语言代码_如何在C ++中编写简洁的代码

本文介绍了C++编程的一些关键准则,如使用清晰的变量名和注释,避免全局变量,尽量不使用goto语句,以及在for循环中避免修改控制变量。提倡在顶部声明常量和类型,只在最后使用一个返回语句,并始终使用大括号。遵循这些指南能帮助编写更易读、更整洁的代码。
摘要由CSDN通过智能技术生成

如何在手机上编写c语言代码

清洁守则准则 (Clean Code Guidelines)

When coding, the coding style you follow can be really important. Especially when you are working with a team or you plan on sharing your code.

编码时,遵循的编码样式可能非常重要。 特别是在与团队合作或计划共享代码时。

Most of these guidelines are standard and can be applied to most programming languages. However, here you have applications and snippets with C++ code, so you can get familiar with it more easily.

这些准则中的大多数是标准的,可以应用于大多数编程语言。 但是,这里有带有C ++代码的应用程序和代码片段,因此您可以更轻松地熟悉它。

Remember that these are only recommendations for achieving clarity, which can be a personal preference. So take these pieces of advice into account but don’t take them to the letter. Sometimes breaking some of these rules can lead to cleaner code.

请记住,这些仅是实现清晰度的建议,可以个人喜好。 因此,请考虑这些建议,但不要将其付诸实践。 有时违反其中一些规则可能会导致代码更简洁。

使用好的变量名并进行注释 (Use good variable names and make comments)

Make sure you create good variable names. For example, if you are creating a game, avoid using the variable “a” and instead use something like “p1” when referring to player 1.

确保创建良好的变量名。 例如,如果要创建游戏,则在引用玩家1时,避免使用变量“ a”,而应使用类似“ p1”的名称。

The hungarian notation i

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值