首先,我知道这个问题:Are there standard formats for comments within code?
但它没有回答我的问题。每当我编写代码时,我总是试图养成一种习惯,即确保所有注释都是一致的,但这正是我有时对代码格式约定犹豫不决的地方。特别是因为我希望我的代码宽80行左右。
不用说,代码格式约定应该是:
代码的不同部分可能有不同的注释格式,因此确保它们保持一致和可读性是很重要的。
下面是一些示例:
单线
// simple comment in lowercase
do_something();
// longer comment in lowercase. but now it doesn't seem like a proper sentence.
do_something();
// Longer comment in sentence case. But should we use sentence case for short comments too?
do_something();
// Like this one?
do_something_else(); // Or even this one.多线
// This code is very detailed and so I must continue further.
// Every time you start a new line you need to ensure you add //.
// If you finish your comment and forget to add something, you're screwed.
// You'll have to add your something and then make sure all the lines are 80 characters or less,
// and if they aren't you need to restructure all the lines below it.
/* This is better but you need to make sure it's properly indented each line.
Although you have to worry about those comment delimiters getting in the way.
At least it's compact. */
/* This comment seems better.
No need to worry about that last delimiter being inside your comment block.
*/
/*
Or maybe this is better?
At least it looks clean.
*/
/* GOOD FOR FUNCTION DEFINITIONS
Or maybe this is even better?
Who knows?
*/发布于 2011-01-22 02:31:15
答案1--不要,任何浪费在支撑上的时间都是浪费时间。
回答2--如果你必须的话,就选一个。http://www.possibility.com/Cpp/CppCodingStandard.html
https://stackoverflow.com/questions/4765775
复制相似问题