Code standard

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

I'm quite sure I already wrote an article like this - Merge these articles when found!

Some ideas concerning consistent coding. Currently (2023.10), I program in Bash, SQL and PHP. Let's keep HTML out of the scope of this article

Various

  • Line length: Max. 80 characters, with obvious exceptions, e.g., when assigning long strings where it really isn't relevant to see everything
  • Comment character: Use #, in Bash, SQL & PHP. Don't use alternative comment characters, including for PHP
  • Prologue: Usually include a prologue somewhere after a shebang or similar identifier & some basic comments, include a prologue: Echo something to the terminal and include some very basic general-purpose comments, if needed.

Sections & comments - Example

################################################################################
# Main section
################################################################################
#
# * "Main sections" are indicated by a line before and after consisting of "#"
# * Number of "#" characters: 80 - indentation of the section - So that lines
#   never get longer than 80 characters
# * I usually include two newlines (or whatever it's called) under a commenting
#   section like this
#
#
# Subsection
########################################
#
# * A subsection is indicated by 40 "#" characters
# * No ":" after the title of the subsection: That's what the "#"s are for
# * Again, I usually include two newlines after a commenting section like this.
#
#
# Subsubsection:
#
# * I usually get worried when I start using subsubsections: Is the code getting
#   too complex or too much like spaghetti code? Or am I putting too much debug
#   and/or commenting sections in a script?
# * Include ":" after the name of the subsecton
# * Usually only one newline after a commenting section like this, that is part of
#   a subsubsection (otherwise, it really starts to take up too much space)
#
echo "Hello, world!"