Writing Code
Definition
Writing Code (Coding/Implementation) is the SDLC phase where the design is translated into actual, executable source code in a chosen programming language — the point where the abstract design becomes a concrete, working system.
Goals of Good Code Writing
- Correctness — implements the design/requirements accurately
- Readability — clear, understandable by other developers
- Efficiency — reasonable use of time and memory resources
- Maintainability — easy to modify/extend later
- Reliability — handles errors and edge cases gracefully
Good Coding Practices
1. Follow the Design Closely
Code should faithfully implement the structure/modules defined during design — avoid deviating without updating the design docs
2. Follow Coding Guidelines/Standards
Consistent naming, formatting, and style (see Coding Guidelines topic)
3. Keep Functions/Modules Small and Focused
Aligns with high cohesion — each function should do one thing well
4. Avoid Code Duplication (DRY Principle)
Extract common logic into reusable functions
5. Handle Errors Properly
Anticipate and gracefully handle invalid input, exceptions, edge cases
6. Write Self-Documenting Code
Use meaningful names so the code explains itself; supplement with comments where logic isn't obvious
7. Perform Incremental Testing While Coding
Test small pieces as you write them (unit-level), rather than writing everything and testing at the end
8. Version Control
Use systems like Git to track changes, enable collaboration, and allow rollback if needed
Relationship to Other SDLC Phases
- Coding follows Design — the structure/modules from the Structure Chart or Class Diagram guide what to implement
- Coding precedes Testing — code quality directly affects how much testing effort is needed
- Poor coding practices directly increase Maintenance cost later
Common Pitfalls
- Premature optimization (over-engineering for performance before it's needed)
- Ignoring the agreed-upon design (ad-hoc changes without updating documentation)
- Skipping error handling
- Writing overly clever/obscure code instead of clear code
Exam tip: This topic often overlaps with Coding Guidelines — if asked separately, emphasize the process of implementation (design → code, incremental testing, version control) rather than just style rules.