Unit VI

Coding

Coding standards, review practices, and clean room testing ensure that written code is correct, readable, and maintainable from day one.

๐Ÿ“ Coding Standards

Coding standards are a set of guidelines and best practices that developers must follow when writing code. They ensure consistency, readability, and maintainability across a codebase.

Naming Conventions

  • Use meaningful, descriptive variable names
  • Constants in UPPER_CASE
  • Classes in PascalCase
  • Functions/variables in camelCase
  • Avoid single-letter names (except loop counters)

Formatting Rules

  • Consistent indentation (spaces or tabs)
  • One statement per line
  • Limit line length (e.g., 80โ€“120 chars)
  • Blank lines between logical sections
  • Braces on consistent positions

Documentation Standards

Golden Rule: Code is read far more often than it is written. Write for the next developer who will read it โ€” even if that's future you.

๐Ÿ” Code Review

Code review is a systematic examination of source code intended to find bugs, improve quality, and ensure standards are followed. Three main types:

1. Code Walkthrough

An informal review led by the code's author. The author presents and explains the code to a small group of colleagues, who ask questions and identify potential issues.

2. Code Inspection

A formal, structured review with defined roles, checklists, and procedures. More rigorous than walkthrough and statistically more effective at finding defects.
RoleResponsibility
ModeratorLeads the inspection, schedules meetings
AuthorAnswers questions, does not defend choices
InspectorReviews code, identifies defects using checklist
Scribe/RecorderDocuments defects found
Inspection Process Flow
Planning Overview Preparation Meeting Rework Follow-up

Walkthrough vs Inspection

AspectWalkthroughInspection
FormalityInformalFormal
Led byAuthorModerator
ChecklistNoYes
Defect loggingInformalFormal records
EffectivenessModerateHigh

๐Ÿงน Clean Room Testing

A software development methodology developed at IBM. Aims to produce software with the quality of cleanroom manufacturing โ€” zero defects through rigorous formal specification and statistical testing.

Key Idea: Developers never execute the code they write during development. All testing is done by an independent testing team using statistical methods. The goal is to prevent defects, not find them.

Core Principles

Advantages

  • Very high reliability
  • Defects prevented, not just found
  • Well-suited to safety-critical systems

Limitations

  • Requires high developer skill
  • Formal methods are time-consuming
  • Not practical for all project types