You are browsing as a guest. Sign up (or log in) to start making projects!

Open comments for this post

3h 2m 28s logged

Devlog 2 — CLI Calculator Upgrade (Validation + History System)

What I set out to build:

Upgrade the CLI calculator into something more structured and “real tool-like” by adding proper input validation improving command handling and introducing a history system.


What I learned:

  • How to structure validation into layers (arity type domain)
  • How CLI arguments actually behave — missing inputs simply don’t exist in the array
  • How to use slice() + map(Number) to normalize input in one step
  • Why separating parsing validation and execution simplifies reasoning
  • How function hoisting allows referencing functions before declaration
  • How to maintain in-memory state using arrays
  • How for loops and forEach help format structured output
  • How small design choices like a numbers array simplify architecture

Biggest struggle:

This part was genuinely exhausting.

I kept getting stuck on when validation should happen and what exactly needed to be validated. I was duplicating checks mixing raw CLI arguments with parsed numbers and constantly second-guessing my logic.

I also misunderstood CLI arguments. I expected missing inputs to appear as undefined which made my validation more complicated than necessary.

The worst part was the flow. Everything felt tangled. Command lookup parsing validation execution like it was happening all at once. Even when the code worked I didn’t fully trust it which made the whole process frustrating.


Current features:

  • Command routing using a function map (commands[cmd])
  • Argument validation based on expected counts
  • Clean input parsing using slice() and map(Number)
  • Domain rules (division by zero negative square roots)
  • Scientific operations: sqrt pow log
  • In-memory history system
  • history command for session logs
  • Improved help command
  • More consistent error handling

Next steps:

  • Persist history to a file
  • Refactor validation into helper functions
  • Improve error messages

Reflection:

This stage felt like a shift from “writing code” to “understanding how programs behave.”

Validation was mentally draining. I kept mixing up arity type and domain rules and the code felt like a pile of checks instead of a system. It worked but I didn’t trust it.

The biggest reality check was the history system. I built it saw it work then ran another command and everything was gone. That’s when it clicked. CLI programs don’t persist memory. Every run starts fresh.

That was the most important lesson. Not everything you build “stays” unless you store it. It changed how I think about programs.

By the end the calculator is still simple but my understanding of structure and flow is much stronger. It feels less like guessing and more like knowing what I’m doing.

Note: The screenshot only shows a basic run and does not include all implemented features (validation command handling improvements and history tracking).

0

Comments 0

No comments yet. Be the first!