Home   Info   DevZone   Wiki  
UsersWeb  |  MainWeb  |  InfoWeb  |  DevZoneWeb  |  SupportWeb
CodingConventionsColoring ] [ not logged in ] [ Web: Imported ] goto:  options
[ get info on or edit ] login or new user ] [ list of topics, hubs & nodes, or recent changes ]

In our modern day and age, with everyone using these nice Java editors, and high color monitors, some developers chose to use color to highlight different elements of the code. These range from simple keywords to elaborate parenthesis and quotes, and pieces of expressions. For example, take a look at OrgJosExampleJava. Here is the same file with the colors my editor assigns to it. --MichaelFried


Hey Michael; don't you think it might be better to assign stronger colors to different parts? I usually use color in my source code so that I can quickly find different things. For example, I will code method names as blue, and author and version information in red, so that I can quickly find those. <br>
<b>Proposed color scheme by BradNeuberg, Nov 30, 1997:</b>
method names - <font color=blue>blue</font>
	ex. <font color=blue>public void printHelloWorld()</font>
javadoc comments (author comments, version comments, class & method comments) - <font color=red>red</font>
	ex. <font color=red>/** This class prints Hello World
								 * @author John Doe
								 * @version 1.0
								 */</font> 
class name - <font color=green>green</font>
	ex. <font color=green>public class FirstProgram extends Applet</font>

Feel free to add more or submit your own ideas. - BradNeuberg, Nov 30, 1997
<font color="#008800">/*
 * @(#)Example.java 1.1 1997.11.30
 *
 * This software forms part of the distribution of the JOS
 * operating system (see http://www.jos.org/) and is
 * subject to the license conditions currently in force.
 *
 * Briefly, these will permit you to:
 * 1. Use the software without any (including implied) warranty,
 * 2. Redistribute the software with the same license,
 * 3. Modify the software including the existing author list,
 * 4. Sell the software with the same license.
 */</font>

<font color="#008888">package</font> org.jos;

<font color="#008800">/**
 * This class exists to give an example of good style for source code.
 *
 * @version	  1.1
 * @author		Michael Fried
 * @author		Tony Austin
 */</font>

<font color="#008800">// Real tabs work in Wiki/html.</font>

<font color="#008888">public class</font> Example
{
	<font color="#008888">public static</font> main(<font color="#000088">String</font> args[])
	{
		<font color="#000088">System</font>.out.println(<font color="#880000">"This is an example class."</font>);
		<font color="#008800">// Analogous to the "hello world" which we all wrote years ago</font>
	}

	<font color="#008888">public</font> Example()
	{
	}
}

I personally find this easier to read than plain black on white. However, people have personal preferences, and if we are all to post code, we should be posting it in a color coordinated fashion that is consistent.
Not to whine, but...it's hard enough to post code without having to juggle html color tags...can we just let the (imaginary) PrettyPrinter handle this, after we decide on coding standards and someone writes such a beast...Yes, editors that are useful do this for you, but they don't drop the html tags in do they?


Nice. I would rather not distinguish between built-in classes (String and System) and other classes though. Too many colors can be distracting. I like the constants (my editor uses dark blue) and keywords in different collors. Another thing which I really like: My editor uses about 3 shades of blue, red, and green for matching brackets and parenthiesis... it really helps readability.

- ClarkEvans


It would be nice if all the user had to do was upload their source code to the Wiki server, at which time a PrettyPrinter servlet would run which would transparently add the correct HTML color tags to the source code and instantly show the changes, just as when we edit these pages we can instantly see the changes.

-- BradNeuberg




Content of these pages are owned and copyrighted by the poster.
Hosted by: