为什么代码中的注释颜色不同?

时间:2023-01-29 03:37:57

Why are comments different colors in different programs? Is it just aesthetic or is there an actual reason?

为什么不同程序中的注释会有不同颜色?它只是审美还是有实际的原因?

13 个解决方案

#1


It depends on the settings in your IDE or editor. Comments don't have a set colour. They are just letters.

这取决于IDE或编辑器中的设置。评论没有固定的颜色。他们只是信件。

#2


I assume it is to make them stand out so people do not easily confuse them with code.

我认为这是为了让它们脱颖而出,这样人们就不会轻易将它们与代码混淆。

#3


To confuse color-blind managers.

混淆色盲经理。

#4


purely aesthetic

#5


Comments are colored differently to make them stand out from the rest of the code (making it easier to read and follow along the comment trail).

评论的颜色不同,使它们与代码的其余部分脱颖而出(使其更容易阅读并遵循评论记录)。

Why they are certain colors is entirely up to the makers of the editor in question (usually based on usability studies), but you can almost always change these using the settings of the IDE.

为什么它们是某些颜色完全取决于相关编辑器的制造商(通常基于可用性研究),但您几乎总是可以使用IDE的设置来更改这些颜色。

#6


As Aiden said, it's really up to whoever is implementing the IDE to choose. I'm familiar with green code comments, as both SQL Server Management Studio and Visual Studio are green by default, but there's no reason why a developer couldn't (for instance) choose fuschia, or lemon yellow, or chartreuse, in their IDE. Loaded into another IDE, the "code comments" would display in that IDE's colour.

正如Aiden所说,这取决于实施IDE的人选择。我熟悉绿色代码注释,因为默认情况下SQL Server Management Studio和Visual Studio都是绿色的,但是开发人员没有理由(例如)在他们的IDE中选择fuschia,柠檬黄或黄绿色。 。加载到另一个IDE中,“代码注释”将以IDE的颜色显示。

#7


It is strictly aesthetic. If you use a good IDE or text editor, you can change the color of the comments to be whatever color you like!

它严格审美。如果您使用好的IDE或文本编辑器,您可以将注释的颜色更改为您喜欢的任何颜色!

I use Visual Studio 2008 at work and I see a lot of the guys changing the colors for reserved words, to class names, to you name it.

我在工作中使用Visual Studio 2008,我看到很多人改变了保留字,类名,你给它命名的颜色。

#8


Most programs allow you to customize color schemes, including the color of comments. Coloring source code, comments and other things, allows the code to be more readable. The choice of particular colors is personal and aesthetic.

大多数程序允许您自定义颜色方案,包括注释的颜色。着色源代码,注释和其他东西,使代码更具可读性。特定颜色的选择是个人和美学。

#9


I am assuming you mean "development environments" when you say "different programs".

当你说“不同的程序”时,我假设你的意思是“开发环境”。

But in general, you are correct. There is an aesthetic, as well as usability, component to it. Development Environment (IDE) makers (e.g., Microsoft's Visual Studio) do usability studies to determine what colors are "best" for development. Like what color to make keywords, comments, etc.

但总的来说,你是对的。它具有美学和可用性的组成部分。开发环境(IDE)制造商(例如,微软的Visual Studio)进行可用性研究,以确定哪种颜色对于开发来说是“最佳”的。喜欢用什么颜色来制作关键词,评论等

But these default color preferences are generally easily changeable by the user.

但是这些默认颜色首选项通常可由用户轻松更改。

#10


Gray or green are used for comments, as the other colours have more desirable properties and so are reserved for more impactful areas of the code.

灰色或绿色用于注释,因为其他颜色具有更理想的属性,因此保留用于代码的更有影响的区域。

For example, tight loops are often in red to make them go faster, and code for children is often blue (for the same reason they learn handwriting in blue), to make it less difficult and more familiar. Blue is often also used for language keywords and APIs to make them easier to understand.

例如,紧密循环通常是红色的,以使它们变得更快,而儿童的代码通常是蓝色的(出于同样的原因,他们学习蓝色的手写),使其更难以更熟悉。 Blue通常也用于语言关键字和API,以使其更易于理解。

Very important code or comments are in green, due to the increased ability of the human eye to discern green.

非常重要的代码或注释是绿色的,因为人眼识别绿色的能力增强。

Black and grey are used for tedious and boring areas of the code, to encourage you to look elsewhere, such as the bright and exciting interfaces and documentation (which are in blue and green as above).

黑色和灰色用于代码的繁琐和枯燥的区域,以鼓励您在其他地方寻找,例如明亮和令人兴奋的界面和文档(如上所述的蓝色和绿色)。

Viruses, *s and the like are always written in white, so they can evade detection by the majority of desktop themes.

病毒,特洛伊木马等总是以白色书写,因此它们可以逃避大多数桌面主题的检测。

#11


It's just for aesthetics and usability, it makes it clear what will and will not be compiled into code, and what's important to read to understand what's going on.

它只是为了美学和可用性,它清楚地表明将会和不会编译成代码,以及阅读以了解正在发生的事情的重要性。

#12


I'm not really sure what you mean, but I'm assuming you are wondering why different IDEs use different colors for comments in their syntax highlighting. It's mostly just aesthetic, but you can usually change the colors if you want.

我不太确定你的意思,但我想你在想为什么不同的IDE在语法高亮中使用不同颜色的注释。它主要是美学,但如果你愿意,你通常可以改变颜色。

#13


back in the day, the screen was black and all of the letters were green! they are various colors to help you determine the usage of each (comment, command, variable, etc.) isn't progress grand!

回到白天,屏幕是黑色的,所有的字母都是绿色的!它们是各种颜色,以帮助您确定每个的使用(评论,命令,变量等)是不是进步隆重!

#1


It depends on the settings in your IDE or editor. Comments don't have a set colour. They are just letters.

这取决于IDE或编辑器中的设置。评论没有固定的颜色。他们只是信件。

#2


I assume it is to make them stand out so people do not easily confuse them with code.

我认为这是为了让它们脱颖而出,这样人们就不会轻易将它们与代码混淆。

#3


To confuse color-blind managers.

混淆色盲经理。

#4


purely aesthetic

#5


Comments are colored differently to make them stand out from the rest of the code (making it easier to read and follow along the comment trail).

评论的颜色不同,使它们与代码的其余部分脱颖而出(使其更容易阅读并遵循评论记录)。

Why they are certain colors is entirely up to the makers of the editor in question (usually based on usability studies), but you can almost always change these using the settings of the IDE.

为什么它们是某些颜色完全取决于相关编辑器的制造商(通常基于可用性研究),但您几乎总是可以使用IDE的设置来更改这些颜色。

#6


As Aiden said, it's really up to whoever is implementing the IDE to choose. I'm familiar with green code comments, as both SQL Server Management Studio and Visual Studio are green by default, but there's no reason why a developer couldn't (for instance) choose fuschia, or lemon yellow, or chartreuse, in their IDE. Loaded into another IDE, the "code comments" would display in that IDE's colour.

正如Aiden所说,这取决于实施IDE的人选择。我熟悉绿色代码注释,因为默认情况下SQL Server Management Studio和Visual Studio都是绿色的,但是开发人员没有理由(例如)在他们的IDE中选择fuschia,柠檬黄或黄绿色。 。加载到另一个IDE中,“代码注释”将以IDE的颜色显示。

#7


It is strictly aesthetic. If you use a good IDE or text editor, you can change the color of the comments to be whatever color you like!

它严格审美。如果您使用好的IDE或文本编辑器,您可以将注释的颜色更改为您喜欢的任何颜色!

I use Visual Studio 2008 at work and I see a lot of the guys changing the colors for reserved words, to class names, to you name it.

我在工作中使用Visual Studio 2008,我看到很多人改变了保留字,类名,你给它命名的颜色。

#8


Most programs allow you to customize color schemes, including the color of comments. Coloring source code, comments and other things, allows the code to be more readable. The choice of particular colors is personal and aesthetic.

大多数程序允许您自定义颜色方案,包括注释的颜色。着色源代码,注释和其他东西,使代码更具可读性。特定颜色的选择是个人和美学。

#9


I am assuming you mean "development environments" when you say "different programs".

当你说“不同的程序”时,我假设你的意思是“开发环境”。

But in general, you are correct. There is an aesthetic, as well as usability, component to it. Development Environment (IDE) makers (e.g., Microsoft's Visual Studio) do usability studies to determine what colors are "best" for development. Like what color to make keywords, comments, etc.

但总的来说,你是对的。它具有美学和可用性的组成部分。开发环境(IDE)制造商(例如,微软的Visual Studio)进行可用性研究,以确定哪种颜色对于开发来说是“最佳”的。喜欢用什么颜色来制作关键词,评论等

But these default color preferences are generally easily changeable by the user.

但是这些默认颜色首选项通常可由用户轻松更改。

#10


Gray or green are used for comments, as the other colours have more desirable properties and so are reserved for more impactful areas of the code.

灰色或绿色用于注释,因为其他颜色具有更理想的属性,因此保留用于代码的更有影响的区域。

For example, tight loops are often in red to make them go faster, and code for children is often blue (for the same reason they learn handwriting in blue), to make it less difficult and more familiar. Blue is often also used for language keywords and APIs to make them easier to understand.

例如,紧密循环通常是红色的,以使它们变得更快,而儿童的代码通常是蓝色的(出于同样的原因,他们学习蓝色的手写),使其更难以更熟悉。 Blue通常也用于语言关键字和API,以使其更易于理解。

Very important code or comments are in green, due to the increased ability of the human eye to discern green.

非常重要的代码或注释是绿色的,因为人眼识别绿色的能力增强。

Black and grey are used for tedious and boring areas of the code, to encourage you to look elsewhere, such as the bright and exciting interfaces and documentation (which are in blue and green as above).

黑色和灰色用于代码的繁琐和枯燥的区域,以鼓励您在其他地方寻找,例如明亮和令人兴奋的界面和文档(如上所述的蓝色和绿色)。

Viruses, *s and the like are always written in white, so they can evade detection by the majority of desktop themes.

病毒,特洛伊木马等总是以白色书写,因此它们可以逃避大多数桌面主题的检测。

#11


It's just for aesthetics and usability, it makes it clear what will and will not be compiled into code, and what's important to read to understand what's going on.

它只是为了美学和可用性,它清楚地表明将会和不会编译成代码,以及阅读以了解正在发生的事情的重要性。

#12


I'm not really sure what you mean, but I'm assuming you are wondering why different IDEs use different colors for comments in their syntax highlighting. It's mostly just aesthetic, but you can usually change the colors if you want.

我不太确定你的意思,但我想你在想为什么不同的IDE在语法高亮中使用不同颜色的注释。它主要是美学,但如果你愿意,你通常可以改变颜色。

#13


back in the day, the screen was black and all of the letters were green! they are various colors to help you determine the usage of each (comment, command, variable, etc.) isn't progress grand!

回到白天,屏幕是黑色的,所有的字母都是绿色的!它们是各种颜色,以帮助您确定每个的使用(评论,命令,变量等)是不是进步隆重!