planetary-social / nos

nos.social social media for all of us, using nostr
https://nos.social
Mozilla Public License 2.0
120 stars 14 forks source link

Improving code readability through centralized Color definitions #733

Closed vigotskij closed 1 month ago

vigotskij commented 9 months ago

Description:

Currently, color declarations in the codebase are scattered throughout, utilizing plain text to represent hex color codes. This practice, while functional, tends to compromise code readability and maintainability. I propose a more structured and comprehensible approach by introducing a dedicated file that contains a Color class extension.

Proposed Solution:

1. Centralized Color Definitions:

Create a centralized file, perhaps named Colors.swift, to house a Color class extension. This extension will define colors using meaningful names, such as "primaryText," "primaryButton," "secondaryButton," etc. This approach not only imparts semantic meaning to color usage but also consolidates color declarations in a single location.

2. Improved Readability:

Utilizing a centralized color definition file enhances code readability by providing developers with a clear and concise reference for color choices. This becomes especially advantageous when maintaining a consistent color scheme across the entire application.

3. Ease of Maintenance:

Centralized color definitions simplify maintenance tasks. If a color scheme update is required or if there's a need to ensure color consistency, developers can conveniently refer to and modify the Colors.swift file instead of scouring the entire codebase for individual color declarations.

4. Consistent Naming Conventions:

Establishing a naming convention for colors, as achieved through the Color class extension, fosters consistency. Developers can quickly understand the purpose of each color, reducing ambiguity and the likelihood of color-related errors.

Objective:

The goal is to enhance code readability, maintainability, and consistency by transitioning from scattered hex color code declarations to a centralized Colors.swift file containing a Color class extension with semantically meaningful color names.

joshuatbrown commented 4 months ago

@vigotskij thanks for this suggestion -- we've done some of this with SwiftGen but there are still places we have hex codes. I'm moving this into our Backlog so we can prioritize it.

joshuatbrown commented 1 month ago

This is done now -- thanks again for the suggestion, @vigotskij!

vigotskij commented 1 month ago

This is done now -- thanks again for the suggestion, @vigotskij!

No problem! Glad to be of help đŸ˜„