Checklist of Best Practices

This checklist provides best practices for maintaining backward compatibility and for reverse engineering on functions or code that needs modification.

Maintaining Backward Compatibility

    • When adding new parameters, place them at the end of the function's parameter list.
    • Ensure these parameters have default values or are optional (null).
    • Use if-else statements to separate new cases from existing ones.
    • Document new branches of code for clarity.
    • If creating a new version of a function, name it with a suffix, e.g., FunctionV2, FunctionV3.
    • Maintain old functions to avoid breaking existing code.
    • In the long term, you can rename the old function to _Function and the new one to Function.
    • If a function is completely replaced, comment it out or mark it as deprecated.
    • Use annotations or comments to indicate that the function should not be used in new code.
    • Write automated tests to verify that existing functionalities still work after changes.
    • Run these tests regularly to detect any issues.
    • Maintain a changelog or documentation file noting all changes made to functions.
    • Specify which changes might affect compatibility.
    • Create interfaces or APIs for key functionalities so that internal implementation can be changed without affecting users.
    • Announce the deprecation of old functions and provide a transition period before removing them.
    • Use warnings in code (e.g., @deprecated) to inform developers.
    • Use a version control system (e.g., Git) to track changes.
    • Create branches for development so that changes can be integrated and tested before merging into the main branch.
    • Seek feedback from peers through code reviews to identify potential compatibility issues.

Procedures for Reverse Engineering

    • Identify where and how the function or code to be modified is used.
    • Use code search tools or dependency analyzers.
    • Spend time reading old code to understand how it works.
    • Add comments or notes to clarify complex logic.
    • Draw diagrams to visualize the execution flow of complex functions.
    • This can help identify key points where changes need to be made.
    • Write unit tests for existing functions to understand expected behavior.
    • Tests can also serve as live documentation of functionality.
    • Run the code in debug mode to observe how it works in practice.
    • Check variable values and execution flow.
    • If you have questions, discuss them with more experienced colleagues.
    • Refer to project documentation or library documentation.
    • Use specialized tools (e.g., decompilers, code analyzers) if working with compiled or third-party code.
    • If a function is very complex, try splitting it into smaller, more understandable functions.
    • Refactor code where possible to improve readability.
    • Before making major changes, ensure you have a backup of the original code.
    • This allows you to revert to the initial state in case of issues.
    • Adhere to the team's or project's coding standards and conventions.
    • This facilitates collaboration and code maintenance.

By following this checklist, you can make changes to the code in a way that minimizes the risk of breaking other functionalities and facilitates understanding and maintenance of the code in the long term.