AI Briefing
KO

Improving Code Quality - Session 58: The Things Words Can't Fully Express

·2025.12.19 11:00

Key point

Implicit dependency relationships within code should be isolated at the function or class level to prevent runtime errors.

Details

When a regular expression and the parsing logic that uses it are separated, modifying the regex can cause the parsing function to remain unaware of the change, leading to runtime errors. This problem arises because the implicit expectation between pieces of code is not made explicit.

To solve this problem, implicit relationships need to be isolated inside a class or function. For example, rather than splitting the regex and the parsing logic into separate objects, it is preferable to bundle them together inside a single dedicated Parser class.

Implicit relationships appear in a variety of situations, such as the following.

  • Paired logic: serialization and deserialization, await and notify, etc.
  • Function call order: setup → execution → teardown, etc.
  • Placeholders: the number and type of items in UI text or SQL queries
  • Data state: encrypted strings versus plain text, whether escaping has been applied, etc.

The most ideal approach is to make the relationship explicit through Types, but if that is difficult, the relationship should be confined to the function, class, or module level, or supplemented through unit tests and documentation.

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.