source: trunk/adm/guides/coding_rules.rst @ 31

Last change on this file since 31 was 2, checked in by pinsard, 14 years ago

first commit with original work of Francoise Pinsard

File size: 2.2 KB

Coding rules

Files extension

Shell scripts : :file:`.sh`

?

IDL scripts : :file:`.pro`

?

Files contents

No multiple statement

example:

a=1;b=2
a=1
b=2

No comment after a statement

example:

yyyy=2010 # default yyyy value
# default yyyy value
yyyy=2010

Lines length

Lines length should be shorter than 79 caracters.

Exception : long URL

++ see continuation lines in ++

Comments

Comments should describe functionalities and implementation choices.

A good way to see if there are enougth comments is to read files without instructions (:samp:`sed -e "/^#/d" file.sh`) : do you understand ?

?

+todo+ see also headers

Tabs, blanks

No trailing blank
justification : for example, when a trailing blank is after (continuation lin) in a shell script, it won't work anymore

No trailing empty line

No tab

No multiple blanks except leading ones.

Indentation at least 3 in block IF, WHILE, etc.

Indentation at least 3 when multiple lines statement

Shell scripts

First line

#! /bin/sh

IDL scripts

Unabbriviated keywords

justification : avoiding confusion, either to find help

Continuation lines

bad example:

+todo+ first part , $
+toto+ second part

good example:

+todo+ first part $
, second part

Explicit IF ... ENDIF block

same for loop (while, until, etc.)

IF (yyyy LT 1999) THEN PRINT, 'too soon'
IF (yyyy LT 1999) THEN BEGIN
   PRINT, 'too soon'
ENDIF

Interaction with system

No :command:`spawn`

?
justification : error handling, portability (unix, windows)

Test with NaN

bad

myvar EQ !VALUES.F_NAN

good

finite(myvar) EQ 0

cf. dave fanning +todo link

Test with float

bad

myvar1 EQ myvar2

good+todo+

+- espilon machin
Note: See TracBrowser for help on using the repository browser.