Difference between revisions of "Clean platform coding style"

From Clean
Jump to: navigation, search
m
Line 2: Line 2:
  
  
== Naming types ==
+
== Type names ==
 
The names of types should be clear and informative, and should always start with a capital. If the name of a type consists of multiple words, each new word should start with a capital. The constructors of a type should also start with a capital.
 
The names of types should be clear and informative, and should always start with a capital. If the name of a type consists of multiple words, each new word should start with a capital. The constructors of a type should also start with a capital.
  
== Naming functions ==
+
== Function names ==
 
Function names should *not* start with a capital, but when a function consists of multiple words, each new word, except the first one should start with a capital. By starting types and constructors with a capital and, functions without one, the difference between a constructor and a function is immediately clear for the reader of a program.
 
Function names should *not* start with a capital, but when a function consists of multiple words, each new word, except the first one should start with a capital. By starting types and constructors with a capital and, functions without one, the difference between a constructor and a function is immediately clear for the reader of a program.
  
== Naming modules ==
+
== Module names ==
 
For modules, the same guidelines apply as for naming types. Names should be informative and preferably short. When a library module is not meant for direct imports by end users, but should only used by experts in modules that for example provide a more friendly interface, you should prefix the name of that module with an underscore character.
 
For modules, the same guidelines apply as for naming types. Names should be informative and preferably short. When a library module is not meant for direct imports by end users, but should only used by experts in modules that for example provide a more friendly interface, you should prefix the name of that module with an underscore character.
  
Line 15: Line 15:
 
* State representing arguments such as the common *World type argument, should be at the end of the argument list.
 
* State representing arguments such as the common *World type argument, should be at the end of the argument list.
 
* Arguments which are used as "options" in some way should be at the beginning of the arguments. This makes it easy to pass in options by currying.
 
* Arguments which are used as "options" in some way should be at the beginning of the arguments. This makes it easy to pass in options by currying.
 +
 +
== Formatting and whitespace ==
 +
TODO:)

Revision as of 15:16, 24 May 2008

While a certain degree of freedom in writing style is a good thing, the readability of programs improves a lot when a consistent coding style is used. We therefore define the following guidelines which strongly encourage everyone to use when developing libraries for Clean and are even mandatory for libraries which are part of the Clean platform.


Type names

The names of types should be clear and informative, and should always start with a capital. If the name of a type consists of multiple words, each new word should start with a capital. The constructors of a type should also start with a capital.

Function names

Function names should *not* start with a capital, but when a function consists of multiple words, each new word, except the first one should start with a capital. By starting types and constructors with a capital and, functions without one, the difference between a constructor and a function is immediately clear for the reader of a program.

Module names

For modules, the same guidelines apply as for naming types. Names should be informative and preferably short. When a library module is not meant for direct imports by end users, but should only used by experts in modules that for example provide a more friendly interface, you should prefix the name of that module with an underscore character.

Argument order

While there are no hard demands on the order in which you specify the arguments of functions, there are two rules which make your functions easier to use and somewhat more clear:

  • State representing arguments such as the common *World type argument, should be at the end of the argument list.
  • Arguments which are used as "options" in some way should be at the beginning of the arguments. This makes it easy to pass in options by currying.

Formatting and whitespace

TODO:)