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
forloops andforEachhelp format structured output - How small design choices like a
numbersarray 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()andmap(Number) - Domain rules (division by zero negative square roots)
- Scientific operations:
sqrtpowlog - In-memory history system
-
historycommand 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).
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.