Styleguide: Difference between revisions

From BlueM
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Allgemein==
==General==
[[Bild:Fortran_tabstops.jpg|thumb|Visual Studio 2005 Optionen für Tabstopp-Einstellungen für Fortran]]
* '''Line-endings:''' all line-endings should be Windows line-endings (CR-LF), git needs to be set to not change this: <code>git config --global core.autocrlf true</code><ref>https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration</ref>
* Die Tab-Größe sollte auf 3 Leerzeichen gesetzt sein (siehe [[:Bild:Fortran_tabstops.jpg|Screenshot]]).
* '''Encoding:''' for historical reasons, all source files should be encoded in ISO-8859-1
* Schlüsselwörter (z.B. <code>IF</code>, <code>FUNCTION</code>, <code>INTEGER</code> etc.) sollten in Großbuchstaben geschrieben werden.
 
* Die Schlüsselwörter <code>END IF</code>, <code>END DO</code> etc. sollten wie hier angegeben mit einem Leerzeichen geschrieben werden.
==Fortran==
[[Bild:Fortran_tabstops.jpg|thumb|Visual Studio 2005 Fortran tabstop settings]]
* Indenting: three-character indents, tabs saved as spaces
* Keywords (e.g. <code>IF</code>, <code>FUNCTION</code>, <code>INTEGER</code> etc.) should be capitalized.
* The keywords <code>END IF</code>, <code>END DO</code> etc. should be written with a space as shown here.
<br clear="all"/>
<br clear="all"/>


==Formatierung==
===Operators===
The modern form of operator syntax should be preferred (e.g. <code>>=</code> rather than <code>.GE.</code>). A lot of code currently still uses the old format, though.
 
{| class="wikitable"
! Description !! Old syntax !! New syntax
|-
| Less than || <code>.LT.</code> || <code><</code>
|-
| Less than or equal to || <code>.LE.</code> || <code><=</code>
|-
| Equal to || <code>.EQ.</code> || <code>==</code>
|-
| Not equal to || <code>.NE.</code> || <code>/=</code>
|-
| Greater than || <code>.GT.</code> || <code>></code>
|-
| Greater than or equal to || <code>.GE.</code> || <code>>=</code>
|}
 
===General formatting===
'''NOTE:''' There is still some debate about how code should be formatted. We might look into using an autoformatter such as [https://github.com/pseewald/fprettify fprettify] in the future.


Funktionen sollten folgendermaßen formatiert werden:
Funktionen sollten folgendermaßen formatiert werden:


* Vorschlag A
* Vorschlag A
<fortran>
<source lang="fortran">


CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Line 41: Line 64:
cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


</fortran>
</source>


* Vorschlag B
* Vorschlag B
<fortran>
<source lang="fortran">


C----------------------------------------------------------------------
C----------------------------------------------------------------------
Line 89: Line 112:
       end module MOD_Beispiel
       end module MOD_Beispiel


</fortran>
</source>
 
 
== Operatoren in Fortran ==
 
in Fortran gibt es zwei Syntaxen für Operatoren
<pre>
Operator    Relationship 
.LT. or  <  Less than 
.LE. or  <=  Less than or equal to 
.EQ. or  ==  Equal to 
.NE. or  /=  Not equal to 
.GT. or  >  Greater than 
.GE. or  >=  Greater than or equal to 
</pre>
 
Für Weiterentwicklungen sollten die gebräuchlichen Symbole benutzt werden:
<pre>
<  Less than 
<=  Less than or equal to 
==  Equal to 
/=  Not equal to 
>  Greater than 
>=  Greater than or equal to 
</pre>
 
 
 


==References==
<references/>


[[Kategorie:Code Styleguide]]
[[Kategorie:BlueM.Sim Development]]
[[Kategorie:BlueM Code]]

Latest revision as of 02:21, 25 August 2022

General

  • Line-endings: all line-endings should be Windows line-endings (CR-LF), git needs to be set to not change this: git config --global core.autocrlf true[1]
  • Encoding: for historical reasons, all source files should be encoded in ISO-8859-1

Fortran

Visual Studio 2005 Fortran tabstop settings
  • Indenting: three-character indents, tabs saved as spaces
  • Keywords (e.g. IF, FUNCTION, INTEGER etc.) should be capitalized.
  • The keywords END IF, END DO etc. should be written with a space as shown here.


Operators

The modern form of operator syntax should be preferred (e.g. >= rather than .GE.). A lot of code currently still uses the old format, though.

Description Old syntax New syntax
Less than .LT. <
Less than or equal to .LE. <=
Equal to .EQ. ==
Not equal to .NE. /=
Greater than .GT. >
Greater than or equal to .GE. >=

General formatting

NOTE: There is still some debate about how code should be formatted. We might look into using an autoformatter such as fprettify in the future.

Funktionen sollten folgendermaßen formatiert werden:

  • Vorschlag A

CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
c     Funktionsbeschreibung
      FUNCTION FOO (BAR) RESULT (LOK)
c     .................................................................
      USE MODULE
      INTEGER  i
      LOGICAL  LOK
      character(*) str
c     .................................................................
      LOK = .FALSE.

c     Kommentar
      DO i = 1, 10
         CALL FOOBAR()
         IF (.NOT. LOK) GOTO 9999
      END DO
      LOK = .TRUE.
      GOTO 10000
c     .................................................................
c     Fehlerbehandlung
9999  IF (.NOT. LOK) ERROR = FEHLER(50, '    ', '    ', 0)
      GOTO 10000
c     .................................................................
10000 RETURN
      END FUNCTION FOO
cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  • Vorschlag B

C----------------------------------------------------------------------
C MOD_Beispiel: Ein Modul !
c Anmerkung: blabla
C----------------------------------------------------------------------
      module MOD_Beispiel
      use MODULE_BLABLAblabla
      implicit none
      
      integer MemberInt

      contains      

C----------------------------------------------------------------------
C funktion FOO : Eine unsinnige zu Demonstrationszwecken erstellte virtuelle Fkt
c Anmerkung: gibt false zurück wenn Fehler !
C----------------------------------------------------------------------
      logical function FOO (BAR)
      use MODULE_BLABLA

         integer  i
         logical  LOK
         character(*) str
      
         FOO = .FALSE.

         !---------------------------------------------
         !Abschnitt A
         !---------------------------------------------
         do i = 1, 10
            CALL FOOBAR()
            !Wenn fehler dann raus !
            IF (.NOT. LOK)
               ERROR = FEHLER(50, '    ', '    ', 0)
               return
            end if
         end do

         FOO = .TRUE.
         return
      end function FOO

      end module MOD_Beispiel

References