Kicksecure Coding Style

From Kicksecure
< Dev
Revision as of 05:18, 2 March 2025 by Patrick (talk | contribs) (Text replacement - "About#Based_on_Debian" to "Based_on_Debian")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Simplicity, Brevity, Sparingly Forking Upstream Projects, Feature Removability

stub[edit]

Documentation for this is incomplete. Contributions are happily considered! See this for potential alternatives.

Simplicity[edit]

For lack of a better term, Kicksecure is simple. It does not fork or recompile software packages from upstream projects.

Examples of software where it is often assumed that it is being modified by Kicksecure, or questions arise about whether that is the case:

  • No good examples yet.

This has the advantage that questions and issues caused by upstream projects can be redirected upstream, as per the Self Support First Policy. This reduces the maintenance load on the Kicksecure project.

Issues that cannot be caused by a Linux distribution are sometimes mistakenly attributed to that distribution. Examples:

Related: Relationship With Upstream

Brevity[edit]

In most cases, goals should be achieved using a single implementation. For example, if remounting /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 Kicksecure developers' perspectives. For instance, there is the helloarchive.org iconarchive.today icon 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[edit]

If a feature becomes unmaintainable, there must be a way to remove it for users who upgrade their system using apt.

No Trailing Whitespaces[edit]

Use a proper editor and ensure no trailing whitespace is left at the end of lines.

Indentation[edit]

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[edit]

Avoid sed and awk whenever possible[edit]

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[edit]

str_replacearchive.org iconarchive.today icon is installed by default in Kicksecure (man pagearchive.org iconarchive.today icon). [1]

Use type -P instead of which[edit]

Do not use which. Instead, use type -P.

https://mywiki.wooledge.org/BashFAQ/081archive.org iconarchive.today icon

Proper Whitespace Handling[edit]

See Dev/bash.

See Also[edit]

We believe security software like Kicksecure needs to remain Open Source and independent. Would you help sustain and grow the project? Learn more about our 12 year success story and maybe DONATE!