Slash'EM coding conventions

Back to the Slash'EM homepage


Slash'EM has evolved over many years and has been developed by a huge range of people. One of the consequences of this process is that different parts of the code follow slightly different coding conventions. This makes coding in the Slash'EM environment particularly challenging, but the following pointers may prove helpful:

Module layout

When writing a new module, you should use the following ordering:

  1. An RCS ident
  2. A copyright section. You may choose to donate the copyright to the Slash'EM dev-team, or if you prefer you may keep it for yourself. In either case, the copyright statement must include the years which apply and must end with the following license statement: "NetHack may be freely redistributed. See license for details."
  3. Any include statements. You should use angle brackets for system include files and quotation marks for include files provided by Slash'EM.
  4. A prologue detailing the purpose of the file and an overview of what it does.
  5. Any pre-processor defines, structure definitions and typedefs that should remain local to the module.
  6. Definitions of any global data.
  7. Functions. Try to order these so that functions of a similar abstraction level are grouped together and so that higher level functions come earlier in the module.

Data structures



Non-trivial functions should start with a block comment that gives the name, a short description of what the function does, a discussion of any non-trivial design decisions and a discussion of the return value (if needed). It is normally better not to describe the implementation (which should be clear from the code anyway) since this normally just creates work for future maintainers.

Local variables


	if (expr) {
	} else
	switch (expr) {
	case 1:
	    /* Fall through */
	case 2:
	case 3:


    if ((k = arm_displacement()))
	return factories[next_factory].robots[this_robot]->type == ROBOT_ARM ? 
		180 * sin(alpha * ++k * eccentricities[i+j]) / PI : 0;


    #define ADVANCE_PTR(io, ptr, inc)					\
	    do {							\
		(ptr) += (inc);						\
		if ((ptr) >= (io)->buffer + sizeof((io)->buffer))	\
		    (ptr) -= sizeof((io)->buffer);			\
	    } while (0)

Naming conventions


Slash'EM Dev-team.