Senior · Design · Expression trees are data and delegates execute

Design a bounded arithmetic-expression service that can inspect and execute only its supported operations.

Think through your answer before opening the explanation.

Runtime & concurrency

Reveal answer and reasoning

Define the accepted signature, numeric domain, overflow policy, and explicit node subset before executing user-supplied structure. Validate parameters, constants, and supported arithmetic nodes, and reject unsupported calls or member access rather than assuming every tree is harmless because it is data. Choose interpretation or another supported execution strategy according to the actual runtime, keeping compilation or provider translation as an explicit separate boundary.

Test direct expected results, empty or invalid structures, unsupported nodes, and relevant overflow boundaries. If a remote provider is involved, run real translation and execution tests against it; local interpretation cannot establish those semantics. Preserve ownership for any captured reference values, or require visible parameters when that simplifies reuse. The wrong design invokes every supplied tree immediately, assumes its result is trustworthy, and treats successful Compile as proof of safety, native-code generation, or compatibility with an unrelated database engine.

What a strong answer covers

  • Specify a supported node and numeric contract.
  • Reject unsupported structure before execution.
  • Validate actual execution and translation boundaries separately.

Common pitfall

Executing arbitrary expression structure without a deliberate validation and runtime policy.

Follow-up questions

  1. How would you avoid hidden mutable captures?
  2. When would an ordinary delegate be a simpler API?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions