MEDIUM: Magic Numbers Reduce Maintainability #21

Open
opened 2026-02-16 22:40:46 +02:00 by Koko210 · 0 comments
Owner

Magic numbers (hardcoded values like timeouts, thresholds) are scattered throughout the codebase, making it difficult to understand and maintain behavior.

Where It Occurs

  • bot/utils/autonomous_engine.py - Timeout values, thresholds
  • bot/utils/voice_receiver.py - Audio processing constants
  • bot/config.py - Various hardcoded values
  • bot/bot.py - Timeouts and retry counts

Why This Is a Problem

  1. Maintainability: Hard to understand what numbers mean
  2. Inconsistency: Same value has different numbers in different places
  3. Tuning Difficult: Cannot adjust behavior without code changes
  4. Bugs: Typographical errors in numeric values hard to spot

What Can Go Wrong

Scenario 1: Inconsistent Timeout Values

  1. LLM timeout is 30.0 in one file
  2. LLM timeout is 30 in another file (integer vs float)
  3. One path times out before another
  4. Inconsistent behavior, hard to debug

Scenario 2: Performance Tuning

  1. Team wants to adjust voice processing threshold
  2. Value appears in 5 different files
  3. Developer changes 4 of them
  4. Misses one file, bug introduced
  5. Bot behaves inconsistently

Proposed Fix

Create bot/utils/constants.py with named constants:

# bot/utils/constants.py

# LLM Configuration
LLM_TIMEOUT = 30.0  # seconds
LLM_MAX_RETRIES = 3
LLM_TEMPERATURE = 0.7

# Voice Processing
VOICE_SAMPLE_RATE = 16000
VOICE_CHUNK_SIZE = 1024
VOICE_TIMEOUT = 60.0

# Autonomous Behavior
AUTONOMOUS_CHECK_INTERVAL = 300  # seconds
AUTONOMOUS_INTERJECTION_THRESHOLD = 0.8

# API Configuration
API_TIMEOUT = 10.0
API_RATE_LIMIT = 100  # requests per minute

Load from config.yaml for override capability.

Severity

MEDIUM - Magic numbers reduce maintainability and cause bugs.

Files Affected

bot/utils/autonomous_engine.py, bot/utils/voice_receiver.py, bot/config.py, bot/bot.py, new file: bot/utils/constants.py

Magic numbers (hardcoded values like timeouts, thresholds) are scattered throughout the codebase, making it difficult to understand and maintain behavior. ## Where It Occurs - bot/utils/autonomous_engine.py - Timeout values, thresholds - bot/utils/voice_receiver.py - Audio processing constants - bot/config.py - Various hardcoded values - bot/bot.py - Timeouts and retry counts ## Why This Is a Problem 1. Maintainability: Hard to understand what numbers mean 2. Inconsistency: Same value has different numbers in different places 3. Tuning Difficult: Cannot adjust behavior without code changes 4. Bugs: Typographical errors in numeric values hard to spot ## What Can Go Wrong ### Scenario 1: Inconsistent Timeout Values 1. LLM timeout is 30.0 in one file 2. LLM timeout is 30 in another file (integer vs float) 3. One path times out before another 4. Inconsistent behavior, hard to debug ### Scenario 2: Performance Tuning 1. Team wants to adjust voice processing threshold 2. Value appears in 5 different files 3. Developer changes 4 of them 4. Misses one file, bug introduced 5. Bot behaves inconsistently ## Proposed Fix Create bot/utils/constants.py with named constants: ```python # bot/utils/constants.py # LLM Configuration LLM_TIMEOUT = 30.0 # seconds LLM_MAX_RETRIES = 3 LLM_TEMPERATURE = 0.7 # Voice Processing VOICE_SAMPLE_RATE = 16000 VOICE_CHUNK_SIZE = 1024 VOICE_TIMEOUT = 60.0 # Autonomous Behavior AUTONOMOUS_CHECK_INTERVAL = 300 # seconds AUTONOMOUS_INTERJECTION_THRESHOLD = 0.8 # API Configuration API_TIMEOUT = 10.0 API_RATE_LIMIT = 100 # requests per minute ``` Load from config.yaml for override capability. ## Severity MEDIUM - Magic numbers reduce maintainability and cause bugs. ## Files Affected bot/utils/autonomous_engine.py, bot/utils/voice_receiver.py, bot/config.py, bot/bot.py, new file: bot/utils/constants.py
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Koko210/miku-discord#21