Naming conventions: Difference between revisions

m
Reformatting text which was overflowing the page width.
(Undo revision 329105 by Razetime (talk))
Tag: Undo
m (Reformatting text which was overflowing the page width.)
 
(7 intermediate revisions by 5 users not shown)
Line 282:
 
If the first line of the program is a comment line of the form <tt>REM >myprog</tt>, the <tt>SAVE</tt> command can be used with no filename and the program will be saved as (in this case) <tt>myprog</tt>. Otherwise, it would be necessary to use <tt>SAVE "myprog"</tt>.
 
=={{header|BQN}}==
BQN uses a context-free grammar, a result of which it has explicit naming conventions defined in its interpreter. The basic types of values can be distinguished by their first and last characters as follows:
<syntaxhighlight lang="bqn"># Subjects (arrays, numbers, characters, etc) start with a lowercase letter:
var←3
arr←⟨1,2⟩
# Functions start with an uppercase letter:
Fun←{𝕨+𝕩}
Avg←+´÷≠
# 1-modifiers start with an underscore and do not end with an underscore:
_mod←{𝔽𝕩}
# 2-modifiers must start and end with an underscore:
_mod2_←{𝔾𝕨𝔽𝕩}</syntaxhighlight>
 
=={{header|C}}==
Line 509 ⟶ 522:
type Maybe = Some(x) or None()
var x = Maybe.Some(42)</syntaxhighlight>
 
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
// 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
String DefaultLogin = "guest";
Int MAX_QUANTITY = 100;
 
// type variables are named for their meanings, and use upper CamelCase
interface Bag<Element>
extends Iterable<Element> {
void add(Element e);
}
}
</syntaxhighlight>
 
=={{header|Factor}}==
Line 758 ⟶ 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}}==
Line 1,094 ⟶ 1,196:
.eu - linux-only include<br>
.exw - historically this implied windows-only, but is now also used for any cross-platform gui applications.<br>
 
=={{header|Phixmonti}}==
No naming conventions. All is only words, numbers, lists or strings (delimited by double quotation marks) separated by blanks. Caution! redefine words is not reversible.
<syntaxhighlight lang="Phixmonti">def *'#-? "Hello world" print enddef
 
*'#-? nl
 
10 var +{&
 
+{& print
 
5 var + /# redefine + to variable with value 5. Aritchmetic word is missing #/
+ print</syntaxhighlight>
{{out}}
<pre>Hello world
10
5
=== Press any key to exit ===</pre>
 
=={{header|PicoLisp}}==
897

edits