Skip to content

From .txt to JSON – and from chaos to structure 😄

This week I built a simple command-line To-Do app.

View source code on GitHub

At first, it looked easy:

  • read from a file
  • append tasks
  • delete tasks

But then reality happened.

🧠 First lesson: structure matters

I started with everything in one file.
It worked… until it didn’t.

So I refactored:

  • separated helper functions into a dedicated module
  • introduced a clean main entry point
  • added logging
  • handled edge cases

That was my first real “aha” moment.

📁 From TXT to JSON

Originally, tasks were stored line-by-line in a .txt file.

Then I upgraded it to JSON.

Not because it was required — but because I wanted:

  • structured data
  • safer reads/writes
  • better error handling
  • future extensibility

The app now follows a clean read–modify–write pattern.

🛡 Defensive programming

I also added:

  • JSON structure validation
  • graceful handling of corrupted files
  • input validation
  • proper logging levels

This project may look simple.

But for me, it marks a shift:
I’m no longer just writing code that works —
I’m writing code that is structured, safe, and extensible.

And that feels different.

View source code on GitHub