Skip to content
Samsagax edited this page Aug 3, 2011 · 8 revisions

This article is WIP, please discuss at issue #554

  • Indentation cluster: four spaces (not tabs, you can change the tab behavior on most editors to produce spaces when hitting TAB key)

  • Keep it readable, use proper indentation, do not use excessive CAPS or question and exclamation marks.

  • Watch your language, be nice for others.

  • Try to stay within the 80 columns limit (especially comments).

  • function definitions

      # note: no space before `()`, one space after it (no newline)
      func() {
          local a="Use locals where possible"
          local b="do not use local a=x b=y"
          code
      }
    
  • control flows:

      # small commands are allowed
      if single; then cmd; fi
      
      if condition; then
          one
      elif cond; then
          two
      else
          three
      fi
      while cond; do
          stuff
      done
      for ((i=0; i<$length; i++)); do
          echo "$i something"
      done
      case "$1" in
        1)# note: two spaces indentation
          anything
          ;;
        2)
          whatever
          ;;
        *)
          ;;
      esac
    
  • Comments: try to explain a code block if it needs to (examples of useless comments). Try to separate code blocks with a newline. Regular comments should have a space after the #, disabled code should have no extra space after it.

      # turns on the graphical card and loads the driver if necessary
      bumblebee-enablecard
    
      # check if optirun is already running
      if pidof -x /usr/bin/optirun >/dev/null ; then
          echo "Already running"
      fi
    
      # the below code was a bad idea, perhaps it needs to be removed?
      #if is_coding_at_night; then
      #    rm -rf /usr
      #fi
    

Clone this wiki locally