k9core

Coreutils for *nix operating systems [fork]
git clone git://bvnf.space/k9core.git
Log | Files | Refs | LICENSE

STYLE.org (3468B)


      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
#+TITLE: k9core coding style
#+AUTHOR: the k9core team
* k9core coding style
  :PROPERTIES:
  :CUSTOM_ID: k9core-coding-style
  :END:

  literally k&r

** Functions definition
   :PROPERTIES:
   :CUSTOM_ID: functions-definition
   :END:

   Functions have to begin with return type, breakline, and functionname,
   also brackets will be in a new line:

   #+BEGIN_SRC C
  int
  main(int argc, char *argv[])
   #+END_SRC
** Variables
   Naming style for variables is snake_case.

   In declaration of
   pointers the * is adjacent to the name, not to the type:
   #+BEGIN_SRC c
   int* p /* wrong */
   int *p /* right */
   int* p, q /* Confusing, p is a pointer while y is not */
   int *p, q /* Not confusing, clearly p is a pointer and y is not */
   #+END_SRC
   
** Line length
   :PROPERTIES:
   :CUSTOM_ID: line-length
   :END:

   A line of code must no exced 75 characters. If it exceeds, do a
   breakline:

   #+BEGIN_SRC C

  int
  a_very_long_function(int a_very_long_parameter, int
                       another_very_long_parameter);
   #+END_SRC

** Statements
   :PROPERTIES:
   :CUSTOM_ID: statements
   :END:

   Do not do declarations inside an if block. Declarations inside while
   loop are OK.

   #+BEGIN_SRC C
     int fd;
     if((fd = open("file", O_CREAT)) == -1) /* Don't do this */
     {
      /* Whatever */
     }

     /* Do this instead */

     int fd = open("file", O_CREAT);
     if(fd == -1)
     {
	 /* Whatever */
     }
     /* Or this */
     if(open("file",O_CREAT) == -1)
       {
       /* Whatever */
       

   #+END_SRC

** Do not include .c files
   :PROPERTIES:
   :CUSTOM_ID: do-not-include-.c-files
   :END:

   Just don't.

** Comments
   :PROPERTIES:
   :CUSTOM_ID: comments
   :END:

   Do not use C++ style comments. Comments at beggining of the line should
   explain what the line does. not how it does. Comments at the end of the
   line must be explanations of something:

   #+BEGIN_SRC C
  // This is a wrong comment

  /* This is a correct comment */

  /* Makes a syscall giving a file descriptor... */

  fd = open("whatever",O_RDONLY); /* WRONG */

  /* Creates a file descriptor on the file whatever */

  fd = open("whatever",O_RDONLY); /* Yes */

  /* 420 is 644 in decimal */ <- WRONG
  chmod("whatever",420)

  chmod("whatever",420) /* 420 is 644 in decimal */
   #+END_SRC

** For commiters
   :PROPERTIES:
   :CUSTOM_ID: for-commiters
   :END:

   Commiters may or may not be anonymous. If you want to be anonymous. Set
   whatever you want to git name and git email.

   If you don't want to be anonymous, you should sign your commits using
   gpg. See
   [[this][https://docs.gitlab.com/ee/user/project/repository/gpg_signed_commits/]]

** C Standard
   :PROPERTIES:
   :CUSTOM_ID: c-standard
   :END:
   Development on k9core is to be done in C99 with possible backwards compatiability with ANSI C.
   Using c11 or gnu11 or something like that is to be avoided.

*** Examples
    This is okay to use:
    #+BEGIN_SRC c
  #include <stdio.h>
  /* Valid C99 */

  int
  main
  {
    puts("This will be executed");
    return 0;
  }
    #+END_SRC

    This is not:
    #+BEGIN_SRC c
  #include <stdio.h>
  #include <stdlib.h>
  #include <stdnoreturn.h>

  /* This is not valid c99 */

  noreturn void
  stop(int i)
  {
    if(i > 0) exit(i);
    else      exit(1);
  }

  int
  main()
  {
    puts("This will be executed");
    stop(0);
    puts("This will not be executed");
  }
    #+END_SRC