A table of four numeric fields and one text field is converted to a uniform-type rectangle — what happens to the numbers?
answer
- one representation for every cell
- the field that cannot narrow decides
- text and number share only two homes
- packed numbers stop being packed
- convert the numeric fields alone
basics
~20 sA uniform-type rectangle holds one representation for every cell, so the single text field decides it for all of them. The numeric values stop being packed numbers and are re-held in whatever form can also carry text.
solid answer
~50 sInside a labelled table each field carries its own **column representation** — the one physical form its values are stored in — so four numeric fields and a text field coexist with no tension. A uniform-type rectangle has no such freedom: it is one buffer of one representation, and that representation has to hold every cell. Only two candidates can hold both a number and arbitrary text — a text representation, or the pointer-per-cell fallback, which stores a reference per cell rather than a packed value — and which one a given design produces is a design choice, not a fact of the subject. Say which you mean before drawing a consequence: under the first, comparison becomes lexical, so `10` sorts before `9`; under the second, values keep their own kind but nothing is packed. What holds in both is that the numeric fields are no longer a packed run. Convert the numeric fields alone and leave the text field in the table.
go deeper
Recall that a uniform-type rectangle stores every cell the same way, while a table lets each field differ. So a text field among numeric ones has to be accommodated by all of them once they share a rectangle.
Explain the mechanism: the representation is chosen to hold every cell, so the field that cannot be expressed more narrowly sets it. Say which two representations can hold both a number and text, and what each costs.
Show that you would catch this at the seam. The conversion returns a rectangle of the expected axis lengths with no warning, so an immediate check of the result's representation is the cheap defence against a wrong number much later.
The angle worth arguing is which fields are allowed to reach a conversion at all. A rule that converts an explicit numeric selection makes this failure impossible; a rule that converts whole tables makes it a matter of whoever last touched the source.
## A rectangle has room for exactly one representation A **labelled table** types its columns one at a time. A field's **column representation** — the one physical form every value in that field is stored in — is that field's own business, and four numeric fields next to one text field cost nothing, because nothing requires them to agree. A **uniform-type rectangle** is the opposite arrangement: one buffer, one representation, every cell alike. The conversion between them therefore has to answer a question the table never had to ask: *which single representation covers all of this?* The rule it follows is the obvious one. The result has to be able to hold every value handed to it, so the representation is driven by the field the others can be expressed in, not the other way round. One text field is enough to decide it for the entire rectangle. ## The two candidates, and this is where designs genuinely differ Only two kinds of representation can hold both a number and arbitrary text, and which one a tool reaches for varies: | result representation | what one cell holds | what follows from it | | --- | --- | --- | | a text representation | the characters of the value; numbers rendered as digits | comparison and sorting become lexical; the width is driven by the longest value | | the pointer-per-cell fallback | a reference per cell instead of a packed value | each value keeps its own kind, but nothing is packed and every access goes through an indirection | Name which outcome you mean before drawing a consequence from it. "The numbers became text" is true of the first and false of the second. "The numbers are still numbers" is true of the second and false of the first. What holds for **both** is the part that matters in an interview: the numeric fields are no longer a packed run of values, and the whole-buffer fast path over them is gone. ## What each outcome costs - **Lexical ordering.** Under a text representation, comparison follows characters, so `10` sorts before `9` and a maximum returns the longest-looking value rather than the largest one. - **Size.** A number rendered as digits usually takes more room than the packed number did, and a text representation sized to the longest value pays that width for every single cell, including the short ones. - **Indirection.** Under the pointer-per-cell fallback the rectangle is a grid of references. Per-cell work goes through one dereference each, and there is no packed run for anything to operate over in bulk. - **Silence.** Neither outcome is an error. The conversion succeeds and returns a rectangle with exactly the axis lengths you expected, so the first sign of trouble is usually a wrong number much further downstream. ## Why the table did not have this problem Nothing changed about any individual field. Each one had a perfectly good representation of its own a moment earlier. What the conversion removed was the *permission to differ*. That is worth stating carefully, because the natural sentence — "the text field changed the numbers' representation" — puts the cause in the wrong place. The text field did not reach into the numeric fields. The rectangle has one slot for a representation, the text field was the only candidate that could fill it, and the numeric values were re-held on the way in. ## The practical move 1. **Do not convert the whole table.** Select the fields whose representations are already compatible and convert only those. The text field stays where it is, in a holding built to let fields differ. 2. **Decide what the rectangle is actually for.** If the receiving code needs numbers, hand it numbers. If it needs the text too, it probably needs the table rather than the rectangle. 3. **Look at what came back, once, at the seam.** The conversion will not warn you. Checking the result's representation immediately after the conversion is cheap, and it catches this where it happened rather than three steps later. ## What an interviewer is listening for The weak answer is "it turns everything into text", offered as a law of the subject. The solid answer names the mechanism — one representation for the whole rectangle, decided by the field that cannot be expressed more narrowly — and then says which of the two outcomes a given design produces and what each costs. The strongest answer adds the correction: the fix is not to make the text field numeric, it is to keep it out of the rectangle.
- The rectangle came back holding a reference per cell rather than text. Is that the better outcome?Partly. Each value keeps its own kind, so a number is still a number and comparison stays numeric rather than lexical. But nothing is packed: the rectangle is a grid of references, per-cell work pays an indirection each time, and the whole-buffer fast path is just as gone. It avoids one failure mode, not the cost.
- How do you get a packed numeric rectangle out of this table at all?Select the fields that already share a compatible representation and convert that selection. The conversion has no way to carry two representations, so the narrowing has to happen before it, not inside it. The text field stays in the table, which was built to hold fields that differ.
- Why is the resulting rectangle often much larger than the values were in the table?Because the representation is sized for the widest thing it must hold, and every cell pays that size. Under a text representation a short number occupies the same room as the longest value; under the pointer-per-cell fallback every cell costs a reference plus whatever it points at.
saying these in an interview costs you the question
- Says each field keeps its own representation inside the rectangle.
- Assumes the text field is dropped rather than deciding the representation.
- Expects the conversion to warn or refuse when the fields disagree.
- Thinks the rectangle occupies about what the packed numbers did.
- States one outcome — text, or references — as what every design does.