A Singapore Government Agency Website

Aspects of Code Quality

Correctness is only one aspect of code quality. On top of doing the job it was intended to do, we want our code to be readable, performant, secure, reliable and maintainable.

Readability

It is said that code is read much more than it is written. Enforcing a clear and consistent code style really helps developers read, understand and modify the code easily. This can be done using tech-stack specific code linting tools, which can be run on the command line or integrate with the IDE during local development for even faster feedback. The team can configure these tools to their agreed norms and share the config in version control.

Linters can run in the CI/CD pipeline, preventing non-standard code from being shared or merged. Running a linter in a git pre-commit hook prevents code style violations from even being committed.

Structuring the codebase according to Domain-Driven Design principles helps us navigate it more easily and quickly find the relevant place to make changes.

Performance

Writing high-quality application code means being mindful of how that code behaves under real-world conditions. One of the foundational practices for writing performant code is understanding the time and space complexity of the algorithms and data structures used. Developers should be aware of how their code scales with input size and system load — inefficient choices like nested loops over large datasets or unbounded memory growth can introduce serious bottlenecks as applications grow.

However, there is a balance to strike between performance and maintainability. Code that is heavily optimized for speed can often become more complex, harder to read, and more difficult to modify. Maintainable code, on the other hand, may not be the fastest but is easier to evolve over time. Teams must be intentional about when to introduce complexity for the sake of performance, ensuring it’s justified by actual system needs, not just theoretical concerns.

This brings into focus the principle of YAGNI (“You Aren’t Gonna Need It”) and the dangers of premature optimization. Spending time early in development trying to optimize performance before there is a demonstrated need often leads to wasted effort and fragile code. Instead, it’s more effective to build clean, understandable solutions first, then measure performance in context and optimize based on real data.

The best performance improvements come from addressing real-world requirements observed through testing, profiling, and monitoring in production-like environments. This ensures that optimization work is targeted and relevant. For example, optimizing database access patterns may be more impactful than micro-optimizations in code if latency is dominated by I/O. By grounding performance work in actual usage patterns and bottlenecks, teams can improve user experience and system efficiency without compromising other aspects of code quality.

Security

High-quality code doesn’t just function correctly — it also protects data, resists misuse, and guards against known and unknown threats. Writing secure code means building systems that are resilient to attacks, difficult to exploit, and safe by default.

Security-conscious development begins with minimizing common vulnerabilities through defensive coding practices and awareness of threats such as those cataloged in the OWASP Top 10. Proper handling of inputs, authentication, authorization, and error conditions are all essential to avoid exploitable flaws. Reliable error handling, limited privilege, and secure defaults can dramatically reduce a system’s attack surface.

Well-structured, readable code contributes to better security by making it easier to identify and fix issues. On the other hand, complex or inconsistent code can hide subtle vulnerabilities. Security reviews and static analysis tools help detect insecure patterns early, but a security mindset during development is key.

Secure code quality also means avoiding dependencies with known vulnerabilities, using trusted libraries, and keeping software components up to date. By integrating security into the development lifecycle and treating it as a shared responsibility, teams can ensure that security becomes a natural part of maintaining overall code quality.

Reliability

Reliability refers to the ability of application code to consistently perform its intended functions under expected conditions. Reliable code behaves predictably, handles edge cases gracefully, and recovers from failures without corrupting data or causing crashes. In practical terms, reliability means that users can trust the application to work as expected — every time. This trust is built through careful design, thorough testing, and attention to how the application interacts with external systems and unpredictable real-world inputs.

Reliable code also emphasizes robustness and fault tolerance. This includes validating inputs, handling exceptions properly, and ensuring that the system degrades gracefully when something goes wrong—such as a failed network call or an unavailable dependency. Automated testing plays a crucial role here, particularly integration and end-to-end tests that verify how the system behaves as a whole. Moreover, designing for reliability often involves defensive coding techniques and using established error-handling patterns to ensure that one faulty component doesn’t take down the entire application. In environments where high availability is important, reliability isn’t a luxury — it’s a necessity, and a defining measure of code quality.

Maintainability

The ability to change the code to meet future requirements is important for the longevity of the product. Therefore, maintainability of the codebase is key.

Some measurable factors that impact code maintainability:

  • Cyclomatic complexity - a measure of the concurrent decision paths present in the code. This makes code harder to follow and reason about, potentially leading to more bugs. Refactoring to extract out functions responsible for individual parts of the logic can help.

  • Duplication – duplicated code can be an indication that it is being copy-pasted rather than reused, which introduces multiple places to make any changes, and potentially multiple sources of truth for business logic. Refactoring code to extract out reusable components instead helps us to not repeat ourselves.

  • Churn – how much a piece of code changes over time. If there is a high amount of churn, it could be an indication that our code is not conforming to the Open-Closed Principle, and is being modified rather than extended. It could also mean that different developers are constantly overriding each other’s design of the code and should work together to enforce consistency. However, a healthy amount of churn can mean that the code is being refactored and kept clean as it should. So this is more of a relative measure – areas of the codebase with more churn can be investigated further to find out the reasons behind it.

These code quality metrics are in addition to a list of possible code smells that can build up as technical debt in the codebase if not given attention.

Enforcing code quality standards

We can get feedback on code quality from automated tools, and some issues can be fixed automatically.

Linting

Language-specific linters can be configured to enforce code style rules that the team agrees on, making it more consistent, readable and maintainable. Some of these problems can even be fixed automatically, by running a command.

The team’s agreed standards can be shared via configuration files in version control.

IDE feedback

Popular IDEs have integrations with linting tools, reading their configuration files from the codebase and enforcing their rules, turning them into syntax warnings or errors in the code as you type. These are added to the IDE’s own opinions on code quality, and possible fixes. Accepting the IDEs suggestions until you get to a “green check mark” of approval means your code meets defined standards.

The IDE configuration itself can be shared too, and there’s even a standard EditorConfig that works across different supporting editors.

VCS hooks

Version Control Systems such as git have hooks that can be used to run code quality tools and prevent commit or sharing of the offending changes until issues have been fixed.

CI pipeline

Static analysis tools in the CI pipeline can be guardians of team code quality, ensuring that changes don’t introduce new issues, and that quality stays above a certain threshold before being considered part of our Definition of Done.

Sharing to uplift quality

Sharing learnings, high-quality reusable code and coding standards across an organisation, and allowing contributors to uplift the quality of libraries, can help to improve the pool of available code and provide examples for teams to use as beacons, encouraging a culture of transparent collaboration.

Innersourcing is the concept of sharing code across an organisation by default, and applying open-source practices to manage it - including forks, pull requests and issue tracking.

SC-9: Internal Code Collaboration and Sharing

Share source code within Government to enhance code quality, accelerate innovation, and improve problem-solving efficiency.

Summary

Maintaining a high quality of our code is essential to keeping our software soft - allowing it to be easily changed to add new features or modified to meet changing requirements as the codebase grows. Quality is everyone’s responsibility, and a culture of transparent collaboration can help to uplift our shared standard of quality work.

Chat with me!
Bot Launcher