Skip to main content

Code Style Guide

This guide covers coding standards for contributing to DNS-MNS.

General Principles

  1. Keep it simple - DNS-MNS should be easy to understand and modify
  2. Be consistent - Follow existing patterns in the codebase
  3. Comment wisely - Explain the why, not the what
  4. Test thoroughly - Verify changes work on multiple platforms

Bash Script Standards

Indentation

Use 4 spaces for indentation (not tabs):

Variable Naming

Use descriptive, lowercase names with underscores:

Quoting

Always quote variables to prevent word splitting:

Function Definitions

Use descriptive function names with lowercase and underscores:

Local Variables

Use local for function variables:

Conditionals

Use [[ ]] for bash conditionals (more features, safer):

Error Handling

Check command results and handle errors:

Comments

When to Comment

Comment on:
  • Complex algorithms
  • Non-obvious logic
  • Platform-specific workarounds
  • Important decisions

Function Documentation

Document complex functions:

File Organization

Script Structure

Organize scripts in this order:
  1. Shebang and header
  2. Constants and configuration
  3. Utility functions
  4. Core functions
  5. Main menu functions
  6. Main execution

Platform Compatibility

Portable Commands

Use portable options when possible:

Check Command Availability

Testing Checklist

Before submitting changes to shell scripts (e.g., test scripts, install scripts):

Tools

ShellCheck

Use ShellCheck to catch common issues:

Syntax Check

Verify syntax without executing:

Example: Good vs Bad

Bad Code

Good Code