What Makes Code Truly Great? 10 Essential Traits Every Developer Should Master
This article outlines ten key characteristics of high‑quality code, illustrates common bad‑code pitfalls, and explains how thorough requirement analysis, system design, testing, and operational practices together produce maintainable, efficient, and scalable software.
Good Code Characteristics
Robust (Solid and Robust) – Code must handle a wide range of error conditions, including system and function call exceptions, because error‑handling logic often dominates production‑grade programs.
Fast – Programs should consume minimal resources (CPU, storage, I/O) by applying appropriate data structures and algorithms while respecting runtime constraints.
Maintainable and Simple – Logic should be clear and easy to understand; simple solutions are preferred over complex, obscure ones.
Small – Keep code concise; however, brevity must not sacrifice readability.
Testable – Correctness must be verified through automated tests (e.g., TDD) to quickly surface quality issues.
Reusable – Leverage existing libraries and frameworks to avoid reinventing functionality and encourage internal code sharing.
Portable – Design abstractions that allow the program to run on multiple operating systems, often via an adaptation layer.
Observable / Monitorable – Provide mechanisms for continuous monitoring of runtime state, especially for online services.
Operational – Consider cost, efficiency, and stability during design; operational concerns must be addressed early.
Scalable and Extensible – Support both capacity scaling and functional extension, using plugin architectures or tools like Protocol Buffers.
Bad Code Examples
Bad Function Name – Names like do() or overly personal names such as myFunc() convey little meaning.
Bad Variable Name – Single‑letter or generic names (e.g., a, b, i, temp) are acceptable only for tiny scopes; broader scopes require descriptive names.
No Comments – Skipping comments raises the cost of code comprehension.
Function Lacks Single Purpose – Functions that do multiple things (e.g., LoadFromFileAndCalculate()) become hard to maintain and reuse.
Bad Layout – Ignoring formatting leads to unreadable code; even if a program compiles, poor indentation hampers human understanding.
Not Testable – Code that cannot be reliably tested lacks quality guarantees.
How Good Code Is Produced
Good code results from a series of coordinated activities, not just writing code. Before coding, thorough requirement analysis and system design are essential but often neglected. During coding, developers should write both implementation and unit tests. After coding, integration testing, deployment, and continuous operation/iteration are required, each demanding significant effort.
Investing more resources in the early stages (analysis and design) yields greater returns than focusing solely on later stages, because errors introduced early propagate costly rework throughout testing, deployment, and maintenance.
Requirement Analysis vs. System Design
Requirement Analysis defines the black‑box behavior of the system—what it should do—from an external perspective.
System Design defines the white‑box mechanisms—how and why the system works—from an internal perspective.
Clear separation of these phases prevents mixing requirements with design details and leads to more maintainable software.
For example, a car’s exterior and controls represent the requirements, while the engine and transmission represent the design.
Source: Excerpt from 《代码的艺术:用工程思维驱动软件开发》 .
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
