Live manual

Debian Live

<< previous toc next >>

Debian Live Manual

Coding Style

15. Coding Style

This chapter documents the coding style used in live systems.

15.1 Compatibility

15.2 Indenting

Good:

case "${1}" in
         foo)
                 foobar
                 ;;

         bar)
                 foobar
                 ;;
esac

15.3 Wrapping

Preferred:

if foo; then
         bar
fi

for FOO in $ITEMS; do
         bar
done

if [ "${MY_LOCATION_VARIABLE}" = "something" ] && [ -e "${MY_OUTPUT_FILE}" ]
then
         MY_OTHER_VARIABLE="$(some_bin ${FOOBAR} | awk -F_ '{ print $1 }')"
fi

if [ "${MY_FOO}" = "something" ] && [ -e "path/${FILE_1}" ] ||
   [ "${MY_BAR}" = "something_else" ] && [ ${ALLOW} = "true" ]
then
         foobar
fi

Less ideal:

if [ "${MY_LOCATION_VARIABLE}" = "something" ] && [ -e "${MY_OUTPUT_FILE}" ]; then
         MY_OTHER_VARIABLE="$(some_bin ${FOOBAR} | awk -F_ '{ print $1 }')"
fi

Horrible:

if [ "${MY_LOCATION_VARIABLE}" = "something" ] && [ -e "${MY_OUTPUT_FILE}" ] || [ "${MY_LOCATION_VARIABLE}" = "something-else" ] && [ -e "${MY_OUTPUT_FILE_2}" ]; then
         MY_OTHER_VARIABLE="$(some_bin ${FOOBAR} | awk -F_ '{ print $1 }')"
fi

Good:

Foo ()
{
         bar
}

Bad (inconsistent with existing style):

Foo () {
         bar
}

Awful:

Foo ()
         {
         bar
         }

15.4 Variables

Bad:

FOO=bar

Good:

FOO="bar"

Typically bad:

if [ -f "${FOO}"/foo/"${BAR}"/bar ]; then
         foobar
fi

Good:

if [ -f "${FOO}/foo/${BAR}/bar" ]; then
         foobar
fi

15.5 Miscellaneous


<< previous toc next >>