DEV Community

Cover image for 3 Foolproof Strategies for Staying Organized in Code
Sergio Holgado
Sergio Holgado

Posted on

3 Foolproof Strategies for Staying Organized in Code

I'm not the most organized programmer, for instance my first projects used to be a complete mess, no folders, no project log, no README file. Being disorganize doesn't just make it harder for others to read your code but for you too, and it's slowing you down.
In this Post I'll talk about 5 good strategies to keep your code organized and clean.

Log files

A markdown log file is a file where you write down what you've done, what to fix and what to do, this lets you track your productivity, solve bugs more easily, don't forget any unfixed bugs or vulnerabilities, and avoid that feeling of not knowing where to start at the beginning of every code session.

Programming Log
[Date]
Project Update
Added new feature XYZ.
Refactored code in module ABC.
Fixed bug in function DEF.
Tested and verified compatibility with Python 3.9.
Code Changes
Updated main.py to improve performance.
Added new helper functions in utils.py.
Removed unused imports in module.py.
Bug Fixes
Resolved issue #123: Null pointer exception in process_data() function.
Fixed memory leak in calculate() method.
Next Steps
Implement error handling for user inputs.
Write unit tests for critical functions.
Improve documentation for module interfaces.

Folders

When working with several documents, specially in frameworks separate images(assets), screens, databases, config files... in different folders.

Image description

Comment code as though another person were to read it

Proper commenting is essential in programming as it improves code readability, maintainability, and collaboration among developers. Here are some guidelines on how to comment properly:

Commenting Individual Code Lines: Inline comments should be used to clarify complex logic, explain the reasoning behind specific code decisions, or highlight important details. Place them on the same line or a line above the code they refer to. Inline comments should be concise and provide valuable insights, avoiding unnecessary redundancy with the code itself.

Documentation comments: Some languages, such as Python, support specific comment formats for generating documentation. For example, Python uses triple quotes (''' ''') for docstrings that can be automatically extracted to create documentation.

Commenting Blocks of Code: When commenting a block of code, such as a function or a complex algorithm, use a multi-line comment to provide an overview of its purpose, inputs, outputs, and any other relevant information. This helps other developers understand the functionality without delving into the implementation details immediately.

Update and Maintain Comments: Regularly review and update comments as the code evolves. Outdated comments can mislead other developers and introduce confusion. When making changes to the code, ensure that corresponding comments are also modified or removed if they become irrelevant.

Comment for Future Maintenance: Consider the future maintenance of your codebase when commenting. Explain any potential pitfalls, assumptions, or edge cases that might arise and how to handle them. This can save time and effort for developers who work on the code later.

Avoid Redundant Comments: Ensure that your comments add value and don't merely repeat what the code already expresses. Avoid excessive commenting on obvious or self-explanatory code. Focus on explaining the intent, rationale, or non-obvious aspects of the code.

Top comments (0)