Place code in the most specific and appropriate location to improve findability and maintainability. Follow these principles: 1. Avoid generic utility modules - place code in specific, relevant modules
Place code in the most specific and appropriate location to improve findability and maintainability. Follow these principles:
Example - Instead of:
# generic util.py
def sanitize(key): ...
class CustomCollector:
def _translate_to_prometheus(self, metric_record):
# using global sanitize function
label_keys.append(sanitize(label_key))
Better approach:
# prometheus_translator.py
class CustomCollector:
def _translate_to_prometheus(self, metric_record):
def sanitize(key): # Function in most specific scope
# sanitization logic
pass
label_keys.append(sanitize(label_key))
This organization improves code findability, reduces coupling, and makes the codebase more maintainable.
Enter the URL of a public GitHub repository