App configuration

2024 Software design

Every application operates within a specific environment. To function properly, it is necessary to configure the behavior based on the context. The configuration is defined at various levels, starting from the most general down to the most specific:

  • Environment variable these are variables defined at the application environment level.

  • Arguments passed to a program when it’s executed.

  • Toggle can control whether a feature in the codebase. When the flag is on, the new feature is active for those users. Otherwise if it’s off, this is hidden and not accessible.

App Configuration

Environment variable

  • List all environment variables load in the current context

$ env
HOSTTYPE=x86_64
LANG=en_US.UTF-8
TERM=xterm-256color
XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir
DISPLAY=:0
WAYLAND_DISPLAY=wayland-0
PULSE_SERVER=unix:/mnt/wslg/PulseServer
WSL2_GUI_APPS_ENABLED=1
WSLENV=WT_SESSION:WT_PROFILE_ID:
  • Load environment variables from dotenv file in Bash

export $(cat profile.env | xargs)
Variadic app

Arguments

  • The arguments can be passed via the command line. Example with the command find.

find /etc -type f -name *net*
  • The arguments can be write in the file and used via xargs.

$ cat filter_only_file_net.args
/etc
-type f
-name "*net*"

$ xargs -a filter_only_file_net.args find
/etc/netconfig
/etc/issue.net
/etc/systemd/networkd.conf
/etc/default/networking
/etc/java-17-openjdk/net.properties
/etc/networks
/etc/init.d/networking
/etc/perl/Net/libnet.cfg

Toggle

The toggle allows to activate or desactivate fonctionnality run by a software. The implementation is very simple, it’s a boolean associated with a variable.

Basicaly, it can be check like

toggles.is_activited(name) return true otherwise false.

The implementation depends on:

  • the performance to check if the variable is activated

  • the variable value changes during execution time or only when the program loads

  • the scope of toggles: if there is a global need for singleton