Why concepts beat memorised code
Memorised code solves the one problem it was copied from. A concept is the idea underneath, and it solves every problem of that shape. Code changes with every language and library; ideas such as exact arithmetic, separation of concerns or validation stay the same.
Concepts also explain why code is written the way it is. Knowing that a computer cannot store 0.1 exactly in a normal number makes the decimal module an obvious choice, not a rule to remember.
How I learn a concept
- Build something small that needs it, so the idea has a real job to do.
- Break it on purpose: give it the edge case, the wrong input, the missing file, and watch what happens.
- Explain it in my own words, as in this note. If I cannot explain it simply, I do not understand it yet.
- Test it, so my understanding is checked by something other than my own confidence.
- Meet it again in a bigger project, where it connects to other ideas.
The concepts
Each concept below starts with what it means in general, then shows the project where it stopped being abstract. I am still learning all of them.
Exact arithmetic
Computers store most numbers in binary floating point, which cannot represent many decimal fractions exactly: 0.1 + 0.2 is not exactly 0.3. For marks and money, a tiny error can push a value across a boundary. Decimal arithmetic stores numbers the way people write them, and the rounding rule is chosen on purpose.
In GPA Tracker: Class boundaries are decided on a rounded mean, so a raw 59.995 already counts as 60. Writing the grading rules showed me why floating-point numbers and banker’s rounding are risky for this job, and why the app uses the decimal module with half-up rounding.
Separation of concerns
Each part of a program should have one job. Calculation rules should not know about buttons, and screen code should not contain rules. A part with one job is easier to understand, to change and to test on its own.
In GPA Tracker: The app keeps grading and validation logic free of GUI code, confines SQL to one module, and puts the KivyMD interface in its own layer (main.py and theme.py). The practical payoff came when the interface was rebuilt in KivyMD: the grading, database and planner code stayed as it was, and its unit tests still run without any GUI toolkit.
Validation and error handling
Never trust input, whether a person typed it or it came from a file. Validation checks input before it is used; error handling decides what happens when something still goes wrong, so the program explains the problem instead of crashing or damaging data.
From small scripts to GPA Tracker: Early scripts such as the banking exercise wrap float(input()) in try/except ValueError and return 0 so the balance does not change. GPA Tracker applies the same idea more systematically: an error-translation layer at the database boundary turns sqlite3 failures into plain advice, and a damaged file is never modified.
Data persistence
Persistence means data survives after the program closes. It raises questions a running program never asks: which copy is the truth, what happens if saving fails halfway, and how to recover from a damaged file.
In the Library Terminal and GPA Tracker: The Library Terminal saves its records as JSON files, which taught serialization. GPA Tracker moved to SQLite, which raised questions that files do not: what is the source of truth, how to back up safely, and how to repair stored data without losing it.
Choosing the right data structure
The way data is organised decides which operations are easy and which mistakes are possible. Keeping all the parts of one record together stops them drifting apart.
In the Learning Lab: The quiz script stores each question with its answer in a dictionary. The shopping scripts keep items and prices in separate parallel lists, which works but depends on the lists staying the same length. Comparing the two showed me why keeping a record’s data together is safer.
Data-driven pages
Data-driven design separates what to show (the data) from how to show it (the code). One change to the data then updates every place that uses it.
On this site: Instead of copying card markup, the site holds its content in one file and draws the cards from it. Doing that exposed copies that had drifted apart (three projects in one place, five in another), and it is why content is inserted as text rather than HTML. The same data later fed a second consumer, a tool that builds a page for every project and note, without any change to the data itself.
Progressive enhancement
Build a page in layers: HTML that works on its own, then CSS for appearance, then JavaScript for extra behaviour. If a layer fails, the layers below it still work.
On this site: without JavaScript, plain lists show every project and note, each linking to its own page. Content that fades in is hidden only after a script confirms JavaScript is running, and an automatically generated block of simpler CSS keeps the colours and layout in browsers that do not understand CSS variables.
Static site generation
Pages can be built in the visitor’s browser on every visit, or once, ahead of time, on the developer’s computer. Building ahead of time gives every reader, including search engines, a finished page.
On this site: the cards on the portfolio are built in the browser, but each project and note also has its own page, generated from the same data file by a small Node.js tool. Each page has its own title and share preview, so a shared link shows that project instead of the home page.