Design Raw and Computed Spreadsheet Views
RipplingSoftware Engineer · OnsiteLast updated
Design raw and computed spreadsheet views with formula parsing, dependency replacement, cache invalidation, atomic edits, and undo semantics.
Design a spreadsheet object model that can display both a cell's raw content and its computed value. A raw value may be a literal or a formula; changing a cell from one kind to the other must correctly update dependencies and cached values.
Constraints & Assumptions
- Preserve the user's raw expression for editing, separately from the parsed expression and computed result.
- Dependent cells must reflect changes to their inputs, including formula-to-literal and literal-to-formula replacements.
- This is an object/API design exercise. Choose and state a formula grammar and error policy only as needed to illustrate the design; the report does not give a complete callable contract.
- Begin with one writer and an in-memory sheet. Persistence, undo/redo, and concurrent editing are possible extensions, not assumed product requirements.
Clarifying Questions to Ask
- Should
getRawpreserve exact user formatting or a normalized expression? - Should an invalid or cyclic edit be rejected, or stored and shown with a computed error?
- Do reads need to be constant time, or can values be evaluated lazily?
Hints
Hint 1
Treat an edit as a dependency change: Replacing a formula can remove edges as well as add them. A cached numeric result alone cannot tell you which old dependencies must be detached.
Follow-up questions
- How would undo/redo restore the raw value and derived graph state safely?
- What must change if a client reads several cells while another client edits the sheet?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.