Formatting 有哪些好的代码格式?

Formatting 有哪些好的代码格式?,formatting,comments,code-formatting,coding-style,comment-conventions,Formatting,Comments,Code Formatting,Coding Style,Comment Conventions,首先,我知道这个问题: 但它没有回答我的问题。每当我编写代码时,我总是试图养成一种习惯,确保注释都是一致的,但这就是我有时对代码格式约定犹豫不决的地方。特别是因为我希望我的代码是80行左右宽 不用说,代码格式约定应该是: 易读 易于修改 在代码的不同部分可能有不同的注释格式,因此确保它们保持一致性和可读性很重要 以下是一些例子: 单行 // simple comment in lowercase do_something(); // longer comment in lowercase

首先,我知道这个问题:

但它没有回答我的问题。每当我编写代码时,我总是试图养成一种习惯,确保注释都是一致的,但这就是我有时对代码格式约定犹豫不决的地方。特别是因为我希望我的代码是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?
*/
多行

// 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?
*/

答案1-不要,任何浪费时间争论牙套都是浪费时间

答案2-如果你必须,就选一个