Day 6 Task 03 Code improvement

Task 03. Improve the Code (Code Refactoring)

Refactor working but tangled spaghetti code into readable clean code with Codex AI.

Task 03 Task 03 Code Improvement Lab Guide

📥 Lab input

  • • day6_meeting_notes.md (meeting notes)

💾 Lab output

  • • day6_clean_code.js

1. Story and lab background

After many ups and downs, you finished code where the screen shows and there are no errors. You think it's all done since it works, but your team lead looks at the code and sighs: "There are too many duplicate functions here, and I can't tell what the variable names mean. If we release it like this, in a month even you will struggle to fix it."

A working program is only the 'minimum requirement' of development; if the code is messy and tangled like spaghetti, it holds back business growth. In this lab, Codex reviews your code, groups duplicate logic into reusable functions and applies clear Naming Conventions, tidying it into Clean Code with the best readability and maintainability.

2. Learning goals

  • Understand the structural difference between complex code that just works and readable, maintainable code.
  • Pull out duplicate features and hard-coded values into a reusable structure.
  • Rename variables/functions clearly and refactor based on AI code review suggestions.

🛠️ Follow-along lab guide

  1. Create the lab file: press the download button below and save day6_meeting_notes.md in the automation/ folder.
  2. Hand refactoring to Codex: send the **Codex request prompt** below in the Codex Client prompt box to ask for a code cleanup.
  3. Analyze the refactor: check that the messy source is organized into readable modules, and compare the reasons for renamed variables with the comments.

Download lab materials

Codex request prompt

Task 03 Prompt
Analyze the source in the provided day6_dirty_code.js and refactor it into an improved clean version: 1) split duplicate markup binding logic into a shared utility function, 2) rename vague variables (ex: a, temp, fn) with real-world words, and 3) add suitable one-line comments for easier maintenance.

4. Example output

Codex analyzes the meeting notes and outputs a normalized data entity mapping and Mermaid ERD script like below.

FileBeforeKey improvementsRefactoring effect
day6_dirty_code.jsDuplicate HTML handling and vague variable names everywhereMerged into a shared utility function and names fixedBetter readability and less maintenance time

5. AI use points

  • Detect Code Smells: finds long methods that are hard to read, duplicate branches and poor parameter structures.
  • Auto comments: adds short summary comments other developers can grasp at a glance to key algorithms and state checks, instead of complex explanations.