liveBook · Manning

Code duplication

As explained in Build Financial Software with Generative AI (From Scratch)

Code duplication is the repetition of substantially similar implementation logic in multiple places within a software system.

Code duplication repeats substantially similar implementation logic across a system. It may speed delivery briefly, but repeated fixes make future maintenance difficult and tedious. section 5.3.2 section 8.8.1

Reduce duplication by:

  • Extracting repeated methods into utility or helper classes, using IDE assistance when available. section 5.3.2
  • Creating reusable components that accept either complete or filtered data. section 8.8.1
  • Evaluating whether a component should receive data or fetch it, especially when redundant API calls are possible. section 8.8.1

ACH processing and exception views

While adding ACH file-header storage, duplicated database-access code prompted consideration of helper extraction. In the interface, a shared exceptions component replaced copied page and DataGrid logic, serving both complete and file-filtered exception lists. section 5.3.2 section 8.8.1

Listing 8.38 Stand-alone exception component
…
interface ExceptionsProps {
    exceptions: AchExceptionsResponse[];
}

export default function Exceptions({exceptions}:
➥ Readonly<ExceptionsProps>) {

    const [isOpen, setIsOpen] = useState(false);
    const [unparsedRecord, setUnparsedRecord] = useState('');
    const columns: GridColDef[] = [
…
           <DataGrid columns={columns} rows={exceptions}/>
…
           <AlertMessage open={isOpen} setOpen={setIsOpen}
➥ message={unparsedRecord} title="Unparsed Record" />
…

Shows a stand-alone exceptions component that receives exception data and renders a reusable DataGrid. section 8.8.1

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Demonstrates duplicated methods and page logic, then applies extraction and component reuse without formal measurement or taxonomy.
Examples
Uses duplicated get_db code, ACH parsing, and a shared exceptions DataGrid component.
What it assumes
Assumes basic application code, database access, and page components; teaches reuse decisions through ACH and exception examples.
What you can do after
Apply it by extracting duplicated methods into helpers or reusable components and evaluating component data flow.
How it connects
Connects duplication with refactoring, helper classes, reusable components, unit testing, maintainability, and testability.

Also explained in

Compare how 3 books explain code duplication →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.