Files
snowprint 54f427ea21
Some checks failed
Deploy to GitHub Pages / build-and-deploy (push) Has been cancelled
init geek calc
2025-10-04 10:53:41 +08:00

3.6 KiB

Research: Geek Calculator Implementation

Key Unknowns Identified

  • Error handling for invalid expressions
  • Behavior for calculations that exceed numerical limits
  • Limits to calculation history storage
  • Specific percentage operation behaviors
  • Response to inputs exceeding v1 scope

Research Findings

Decision: Error Handling for Invalid Expressions

Rationale: For invalid expressions like "5 // 0" or "5 + * 3", the calculator will display "Error" in the display area and require clearing before continuing. Alternatives considered: Alternative was to show specific error messages (e.g., "Division by zero", "Invalid syntax") but the simpler "Error" approach maintains the minimal UI aesthetic.

Decision: Overflow and Large Number Handling

Rationale: For calculations that exceed JavaScript's numerical limits, the calculator will show "Infinity" or "-Infinity" for overflow, and "0" for underflow. Alternatives considered: Could have implemented custom large number handling but this would increase code size beyond 50KB target.

Decision: Calculation History Storage

Rationale: History will be stored in localStorage with a limit of 50 entries. When limit is reached, oldest entries are removed. Alternatives considered: Unlimited history was considered but would risk localStorage quota exhaustion and performance degradation.

Decision: Percentage Operation Behavior

Rationale: Percentage operations will follow standard calculator behavior: "100 + 10%" = 110, "50%" = 0.5, "100 * 5%" = 5. Alternatives considered: Scientific calculator percentage behavior (like "100 + 10%" = 100.1) was considered but standard behavior is more familiar to users.

Decision: Handling Out-of-Scope Functions

Rationale: For inputs that exceed v1 scope (like scientific functions), the calculator will display "Error" to maintain focus on core features. Alternatives considered: Ignoring invalid inputs silently was considered but providing feedback is better for user experience.

Technology Decisions

Decision: Vanilla JS Modules Architecture

Rationale: Using ES6 modules will provide clean separation of concerns while maintaining zero dependencies as required by the constitution. Alternatives considered: Single file vs. modular approach; modular was chosen for maintainability despite the single-file requirement for the final deliverable.

Decision: RPN Implementation

Rationale: Implementing RPN with a stack data structure will provide the required functionality while keeping the code efficient. Alternatives considered: String-based RPN processing vs. stack-based; stack-based was chosen for better performance and clearer code.

Decision: Testing Framework

Rationale: A minimal custom test harness will be implemented to avoid external dependencies while providing necessary test coverage. Alternatives considered: External testing libraries like Jest were considered but rejected to maintain zero dependencies requirement.

Decision: Service Worker Strategy

Rationale: A cache-first service worker will ensure full offline functionality as required by the constitution. Alternatives considered: Network-first or stale-while-revalidate strategies were considered but cache-first better ensures offline capability.

Accessibility Implementation

Decision: ARIA Roles and Keyboard Navigation

Rationale: Using semantic HTML with appropriate ARIA roles and comprehensive keyboard event handling will meet WCAG requirements. Alternatives considered: Custom accessibility solutions vs. standard HTML patterns; standard patterns were chosen for better compatibility and maintainability.