Code Organization ยท 1 of 3

Code Organization Matters

Good code organization makes software easier to maintain and helps teams work efficiently. When developers need to add or change a feature, the project’s structure should help them find and understand the relevant code.

This becomes more important as a project grows. The team should not have to rely on memory to know what each file does or why it exists. Agree on conventions for directory structure, naming, formatting, and code size so developers can navigate unfamiliar areas with confidence.

Keeping code organized is ongoing work. As you add features and fix bugs, maintain the structure so it remains useful when you need to move quickly.

Keep the Project Shipshape

In sailing and naval culture, keeping a ship organized is part of keeping it safe and ready to operate. Equipment has an assigned place, crew members have defined responsibilities, and routine inspections keep everything in working order. These systems matter because crews must act quickly, often in darkness, rough seas, or emergencies. A misplaced tool or blocked passage can delay a response and put lives at risk. Keeping a ship “shipshape” means maintaining an order that everyone understands and can rely on, even under pressure.

Treat your codebase with the same care. Establish patterns for where code belongs, remove clutter, and make maintaining that order part of every contributor’s work. A structure that everyone follows helps the team respond quickly without first having to untangle the project.

Make Organization a Habit with 5S

5S is a Japanese system for keeping workplaces organized, efficient, and ready for use. Its five practices—sort, set in order, shine, standardize, and sustain—mean removing what is unnecessary, giving useful items a clear place, keeping the workspace clean, and building habits that preserve that order. These practices help people find what they need, spot problems early, and work consistently.

In a software project, that means removing dead code, keeping related files together, using clear names, and following consistent rules for where code belongs. Maintain those habits through everyday changes and code reviews. When the structure is predictable, teammates spend less time searching and can more easily understand how a change affects the rest of the project.

Keep Functions, Objects, and Files Focused

Robert C. Martin’s Clean Code emphasizes small functions and classes with clear responsibilities. Apply that principle to functions—including methods—objects, and files: each should have a purpose that is easy to name and explain. A function that formats a payment amount should focus on formatting, rather than also calculating fees, updating records, and sending notifications.

Focused units are easier to understand, test, and verify. Their inputs, outputs, dependencies, and expected behavior are clearer, so developers can check individual rules and edge cases without setting up an entire workflow. For objects, keep methods and state centered on the same responsibility.

Smaller units can be assembled by a composer or orchestrator that expresses the larger workflow. For example, a payment service might coordinate validation, allocation calculation, persistence, and notification. Each step belongs to a focused function or object, while the orchestrator makes the sequence clear. Test individual units for correctness and the orchestrator for how they work together.

Apply the same discipline to files. Each file should have a purpose that its name describes, such as formatting payment amounts or coordinating payment processing. If explaining its purpose requires listing unrelated jobs, review whether those responsibilities belong in separate files.

Name Functions by What They Do

A function’s name should explain its purpose before someone reads its implementation. Use a specific verb or verb phrase that describes the action and what it acts on. This applies to methods as well as standalone functions, and follows guidance from Google’s JavaScript style guide and Microsoft’s naming guidelines.

  • getPayment retrieves a payment.
  • setActiveAccount changes the active account.
  • calculatePaymentTotal computes a total.
  • formatCurrency converts a value into display text.
  • validatePaymentRequest checks a request against defined rules.
  • savePayment persists a payment.
  • sendNotification sends a notification.

Make Boolean Checks Read Like Questions

For functions that return true or false, use names such as isPaymentValid, hasOutstandingBalance, or canSubmitPayment. These names make conditions easy to read:

if (canSubmitPayment(payment)) {
  submitPayment(payment)
}

Prefer affirmative names. Expressions such as !isNotEligible(customer) introduce a double negative that makes the condition harder to understand. Google’s guide uses is and has for Boolean getters, and Microsoft recommends affirmative names for Boolean properties.

Make Side Effects Predictable

A name should help callers distinguish reading or calculating from changing something. calculatePaymentTotal suggests a calculation; savePayment suggests a database write. Naming according to side effects is also part of Swift’s API design guidance.

Keep those expectations reliable. A formatting function should not unexpectedly modify its input, and a retrieval function should not also update records or send notifications. When an operation changes state, choose a verb that communicates that change, such as update, remove, or save.

Use a Consistent Vocabulary

Choose terms the team understands and use them consistently. Avoid switching between get, fetch, load, and retrieve for equivalent operations without a reason. If those verbs represent different behavior, document the distinction and follow it throughout the project.

Prefer recognizable words over unfamiliar abbreviations. calculatePaymentAllocation communicates more clearly than calcPmtAlloc. Swift’s naming guidance favors clear terminology and discourages ambiguous abbreviations.

Read Names Where They Are Called

Evaluate a name in the code that uses it. The surrounding object or module may already provide enough context:

paymentRepository.findById(paymentId)

Repeating that context adds noise:

paymentRepository.findPaymentByPaymentId(paymentId)

A standalone function may need the more explicit name findPaymentById. Choose enough detail to make the call clear without repeating information already visible. Swift’s API guidelines also emphasize clarity at the point of use.

Name Orchestrators by the Overall Operation

Orchestrators follow the same naming principle, but describe a broader business action. processPayment might coordinate validation, allocation calculation, persistence, and notification. Its name describes the workflow, while the functions it calls describe the individual steps.

Composers describe what they assemble. For example, buildPaymentSummary might combine payment details, calculated totals, and display values into a result. Neither role requires a special suffix; the name should communicate the operation or outcome.

Reserve broad verbs such as process for functions that actually coordinate broader work. For individual steps, avoid vague names such as handleData, doWork, or paymentHelper.

Make the Contract Clear

A name cannot explain every detail. Establish consistent conventions for return values, errors, and mutation. Does findPayment return null when no payment exists? Does validatePaymentRequest return validation errors or throw an exception?

Use signatures and documentation to make those details explicit. Keep the name focused on purpose, and make the function’s actual behavior match what callers reasonably expect.

Use Size Limits as Review Points

Code size can signal that a function, file, or directory is becoming difficult to understand. Use these reference points to guide a review:

  • Functions: about 60 lines. Rule 4 of The Power of Ten, written by NASA/JPL’s Gerard Holzmann, recommends that a function fit on one printed page, typically about 60 lines. The rule was developed for safety-critical C code to make functions understandable and verifiable. Use it as a reference point rather than a universal limit. See The Power of Ten.
  • Files: about 200 lines. This is a practical review threshold. Check whether the file contains distinct responsibilities that would be easier to understand, test, and change separately.
  • Directories: about 12 files. This is another review threshold. Look for groups of files with a shared purpose that would benefit from a meaningful subdirectory.

These measures apply at different levels. A file containing many short functions can still have too many responsibilities, and a directory containing small files can still be difficult to navigate.

Split code when doing so clarifies its purpose or makes it easier to test and change. Keep related code together when splitting would only force readers to jump between files. Avoid creating tiny helpers or extra directories solely to meet a line count or file count.

Check Whether the Structure Helps

Before finishing a change, imagine a teammate returning to the feature next month. Can they:

  • Find the code they need to change?
  • Follow how it works and identify the other parts it affects?
  • Find the tests that check its behavior?

Use those questions during edits and reviews. When the answers are unclear, improve the names, boundaries, or placement while the code is still fresh in your mind.