Naming conventions: Difference between revisions

m
Reformatting text which was overflowing the page width.
m (Reformatting text which was overflowing the page width.)
 
(3 intermediate revisions by 2 users not shown)
Line 527:
// a module name is the name of the app or library, followed by the domain name of the organization;
// alternatively, a "throw-away" module can have a simple name, like "TestApp"
module shop.acme.com {
{
// other than modules, all type and class names (including enum values) use upper CamelCase;
const Point(Int x, Int y);
enum Color {Red, Green, Blue}
interface Callback {
{
// variables, properties, methods, and functions using lower camelCase
Boolean active;
void onEvent(String event);
void onError(Exception e);
}
 
// constants use upper CamelCase, or in some cases, UPPER_SNAKE_CASE
Line 546 ⟶ 544:
// type variables are named for their meanings, and use upper CamelCase
interface Bag<Element>
extends Iterable<Element> {
{
void add(Element e);
}
}
}
</syntaxhighlight>
 
Line 801 ⟶ 798:
 
Other conventions are also in use.
 
=={{header|Java}}==
According to Java's naming conventions, all names should be in mixed case:
 
classes and interfaces should be nouns beginning with a capital letter,
 
methods should be verbs beginning with a lower case letter,
 
variables should begin with a lower case letter.
Names should be descriptive, and single character names should be avoided except for short lived temporary variables.
Class variables which are static and final should be all upper case with words separated by underscores.
It is standard practice for an enum to be named in the same way as a class with its constants in all upper case.
The following program illustrates these naming conventions.
<syntaxhighlight lang="java">
import java.util.ArrayList;
import java.util.List;
 
public class NamingConventions {
 
public static void main(String[] arguments) {
SolarSystem solarSystem = new SolarSystem();
solarSystem.showSunDiameter();
System.out.println("The planetary system comprises of:");
solarSystem.listPlanets();
}
 
}
 
enum Planet { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO }
 
class SolarSystem {
public SolarSystem() {
for ( Planet planet : Planet.values() ) {
planets.add(planet);
}
}
public void showSunDiameter() {
System.out.println("The diameter of the sun is approximately " + SOLAR_DIAMETER + " km");
}
public void listPlanets() {
System.out.println(planets);
}
private List<Planet> planets = new ArrayList<Planet>();
{
private static final int SOLAR_DIAMETER = 1_390_000;
}
</syntaxhighlight>
{{ out }}
<pre>
The diameter of the sun is approximately 1390000 km
The planetary system comprises of:
[MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO]
</pre>
 
=={{header|jq}}==
908

edits