{{Header}} {{title|title= {{project_name_long}} Coding Style }} {{#seo: |description=Simplicity, Brevity, Sparingly Forking Upstream Projects, Feature Removability }}
/run
with more secure mount options is required, the implementation should do this, if possible, either entirely in initramfs
/ dracut
or entirely using systemd
. It should not duplicate the same functionality in both.
There are numerous things that users might potentially do, which may not align with {{project_name_short}} developers' perspectives. For instance, there is the [https://packages.debian.org/search?keywords=hello hello] package, which most users are unaware of and unlikely to install. This is merely an example, and no criticism is intended toward the contributor of that Debian package.
Why allow the installation of that package? What if that contributor turned malicious and included a backdoor in the hello
package? To prevent such a backdoor from causing harm, an apt wrapper could be implemented to prevent the installation of such unnecessary packages. However, introducing such a wrapper would likely be worse than the hypothetical risk itself.
= Feature Removability =
If a feature becomes unmaintainable, there must be a way to remove it for users who upgrade their system using apt
.
= No Trailing Whitespaces =
Use a proper editor and ensure no trailing whitespace is left at the end of lines.
= Indentation =
Avoid excessive levels of if
conditions and similar constructs.
**Bad example:**
machine_id() { if ! test -f /etc/machine-id ; then existing_machine_id="$(cat /etc/machine-id)" ## ... fi }In the above example, there is no need to nest everything inside the
if
block. This is especially important when dealing with multiple levels of conditionals.
**Good example:**
machine_id() { if ! test -f /etc/machine-id ; then return 0 fi existing_machine_id="$(cat /etc/machine-id)" ## .... }= Shell Scripts = == Avoid
sed
and awk
whenever possible ==
There may be older code (from before the introduction of str_replace
) that uses sed
or awk
. Patches are welcome to migrate such cases to str_replace
.
== Use str_replace
whenever possible ==
[https://github.com/{{project_name_short}}/helper-scripts/blob/master/usr/bin/str_replace str_replace] is installed by default in {{project_name_short}} ([https://github.com/{{project_name_short}}/helper-scripts/blob/master/man/str_replace.1.ronn man page]).
https://github.com/Samer-Al-iraqi/Linux-str_replace/
== Use type -P
instead of which
==
Do not use which
. Instead, use type -P
.
https://mywiki.wooledge.org/BashFAQ/081
== Proper Whitespace Handling ==
See [[Dev/bash]].
= See Also =
* [[Dev/Source Code Intro|Source Code Introduction]]
[[Category:Design]]
{{Footer}}