Menu
Jay Huang

writing

What 205 lb leaves out

A 45 lb bar with 45 + 25 + 10 on each sleeve weighs 205 lb. So does a 45 lb bar with 35 + 35 + 10 on each sleeve. If I save the total, I lose the distinction. Even the sum on each side loses the order in which I stacked the plates. A sleeve with 45 + 25 + 10 and one with 10 + 25 + 45 contribute the same mass. I have to remember which setup I used if all I recorded was the sum.

That is the reason to keep the arrays. In HabitTracker, PlateLoad takes the bar weight, a single unit, and an ordered list for each side. It can calculate both sleeve totals and the display number from there. IsBalanced asks whether the sleeve totals are equal. It says precisely that, even when the composition or order differs. The plate value and its derived properties

The value needs to survive an edit

There’s a small test with a 45 lb bar and one 45 lb plate per side. It passes the same mutable array to the constructor for both sleeves, then changes the source element to 100. Here’s the whole test body. The source-array test

decimal[] plates = [45];
var load = new PlateLoad(45, plates, plates, WeightUnit.Pounds);
plates[0] = 100;
Assert.Equal(135, load.TotalWeight);

With two read-only wrappers around the caller’s array, I’d still have a mutable load. The wrappers protect access through the new references. The old reference could change both sleeves, taking the result from 135 to 245. PlateLoad copies each input before exposing it as read-only. The same rule matters when the builder mirrors a stack. The value captured for this set should survive later edits in the builder. Copying and parsing the stacks · The bounded array copy

The parser is another boundary. It accepts 45lbs+25lbs+10 in pounds and allows an empty sleeve. A suffix has to agree with the selected unit. It parses decimal points with an invariant culture, which gives a pasted plate expression one interpretation across clients. A 20 kg bar with 20 + 5 + 1.25 on both sleeves produces 72.5 kg. That is a decimal value in the original unit all the way through the calculation. The parser and display conversion · The fractional plate and invalid input cases

Save enough to recalculate

The HTTP request carries the bar, stacks, and unit without a total. The API validates those inputs and stores each stack as JSON on the set row. When it responds, it reads the arrays back into a PlateLoad and calculates the total. In the integration test, a 205 lb request comes back with both ordered arrays after an HTTP reload. The endpoint derives 1,025 lb of training volume for five reps from that same set. The request contract · The save and reload test

Storing each sleeve as one column has a tradeoff. The current history query looks up sessions and exercises, and a sleeve has at most sixteen entries. Reading or writing the array is a small part of the set operation. A query such as “show every set with a 1.25 kg plate on the inside sleeve” would need to interpret JSON, or give plate membership its own representation and index. There is no such query in the training workflow. The history operation that matters is rebuilding the setup I selected. The set mapping · Constructing the historical load

More HabitTracker articles