Changes between Version 32 and Version 33 of HowtoGoodProgrammingTechniques


Ignore:
Timestamp:
Feb 14, 2026, 1:19:36 PM (2 weeks ago)
Author:
Thanatermesis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowtoGoodProgrammingTechniques

    v32 v33  
    1111I follow a simple, five-step procedure for every new function I write:
    1212
    13 1. '''Write''': First, I implement the core idea to get it working. The initial goal is just functionality, a clever thing is to keep in mind the core structure it should have in the future.
    14 1. '''Refine''': Next, I improve the code's structure, ensure correct return values, and format it for readability.
     131. '''Write''': First, I implement the core idea to get it working. The initial goal is just functionality; a clever approach is to keep in mind the core structure it should have in the future.
     141. '''Refine''': Next, I improve the code's structure, ensure correct return values, and format the code for readability.
    15151. '''Clarify''': I choose descriptive names for variables and functions. This step can be slow, but it's one of the most valuable programming practices.
    16161. '''Document''': I add comments where necessary to make the code easy to understand.
     
    5353
    5454
    55 == Human factors ==
     55== Human Factors ==
    5656
    5757=== Memory ===
     
    5959You won't remember exactly what a piece of code does or why it's there weeks or months later. While comments help, they can be forgotten or become outdated.
    6060
    61 Always keep your comments updated, now we have tools that automates this task.
     61Always keep your comments updated; we now have tools that automate this task.
    6262
    6363=== Visual Readability ===
     
    7272Similarly, `if` statements and other control structures should be visually distinct so you can immediately see where they start and end.
    7373
    74 Add functions to long parts of the code inside the loops, but only when the loop is not an optimization-required one.
     74Extract long parts of code inside loops into functions, but only when the loop is not performance-critical.
    7575
    7676
     
    8989Variable and function names are very important. A good convention is to make names as short as possible while remaining perfectly understandable. Think of a hierarchical structure, like in object-oriented programming, where names go from general to specific, often ending with an action.
    9090
    91 It is good practice to review the final code, brainstorm their names, and rename variables, functions and global variables once a major part of the application is complete. This helps ensure a consistent and optimal naming structure throughout the codebase.
     91It is good practice to review the final code, brainstorm names, and rename variables, functions, and global variables once a major part of the application is complete. This helps ensure a consistent and optimal naming structure throughout the codebase.
    9292
    9393
     
    104104Often, good function and variable names seem to be in the reverse order of how you would say them. If in doubt, imagine a list of similar names sorted alphabetically. This can help you see which parts of the name should come first.
    105105
    106 It's also helpful to know a variable's type from its name. Some conventions use suffixes for this, such as `_v` for values, `_a` for arrays, `_d` for directories, and `_f` for files (a form of Hungarian notation). Use a `_` prefix for unimporant local variables.
     106It's also helpful to know a variable's type from its name. Some conventions use suffixes for this, such as `_v` for values, `_a` for arrays, `_d` for directories, and `_f` for files (a form of Hungarian notation). Use a `_` prefix for unimportant local variables.
    107107
    108108
     
    110110Large applications are difficult to maintain and debug. The best way to avoid these pains is to:
    1111111. Keep everything modular and independent. Every function, tool, or feature should be callable independently without relying on other parts of the application. Consider using external commands to achieve this.
    112 2. When calling external commands or global tools,  include a debug entry entry of the call with its arguments. This makes it easy to reproduce the call outside the application for debugging.
    113 3. Avoid deleting or renaming old functions that other tools might depend on. Instead, mark them as deprecated, have it to call the new function with the updated parameters, and add a warning message to inform developers of the change.
     1122. When calling external commands or global tools, include a debug entry of the call with its arguments. This makes it easy to reproduce the call outside the application for debugging.
     1133. Avoid deleting or renaming old functions that other tools might depend on. Instead, mark them as deprecated, have them call the new function with the updated parameters, and add a warning message to inform developers of the change.
    1141144. When refactoring a function, do not change the final behavior. This can cause unexpected results in applications that use the function.
    115115
     
    138138* It always takes longer than you expect.
    139139* Existing users become frustrated.
    140 * Refactoring changes your code and behaviour.
     140* Refactoring changes your code and behavior.
    141141* You don't control the rewrite; it controls you.
    142142