Skip to content

Commands.Balance: pass allCommodities in AmountFormat - #2728

Draft
thielema wants to merge 2 commits into
hledgerorg:mainfrom
thielema:amount-format-all-commodities
Draft

thielema wants to merge 2 commits into
hledgerorg:mainfrom
thielema:amount-format-all-commodities

Conversation

@thielema

Copy link
Copy Markdown
Contributor

I try to address the suggestion by Opus AI:
#2691 (comment)

The suggestion was to avoid the allCommodities parameters by using the displayCommodityOrder field of the AmountFormat parameters.

Currently the exported reporting functions call lower-level functions with an AmountFormat parameter, that is usually one of noCostFmt, oneLineNoCostFmt, machineFmt or modifications of those. On the way down some fields like displayCommodity and displayCommodityOrder are replaced. I do not like this design very much, because it is not obvious that some fields of AmountFormat you pass to a public reporting function are just overwritten, and thus ignored. I'd prefer if a user only passes values that have an effect.

However, I also see that AmountFormat is huge and an approach without overwriting fields would require many more function parameters.

This draft pull request leaves the AmountFormat mutation approach and sets displayCommodityOrder at a higher level in case of layout=barewide. In principle this works, but e.g. in multiBalanceReportAsSpreadsheetParts we need to extract the displayCommodityOrder from fmt, which is a Maybe. This must be Just whenhever layout == LayoutBareWide, but we cannot enforce this condition in types.

That is, I propose not to include this pull request, but maintain it closed for further discussion.

However, the first commit 5fe4e4a swaps parameters of setDisplayCommodityBare, which I now think is more idiomatic. I think we should apply this one.

…ceRowAsCellBuilders: remove allCommodities parameter

Caller must pass commidities in fmt.displayCommodityOrder instead.

setBareWideCommodityOrder: according helper function
@simonmichael

Copy link
Copy Markdown
Member

Ok @thielema.

@simonmichael

Copy link
Copy Markdown
Member

I'm fine with keeping things as they are for now. But from the warning it sounds like a potential source of future bugs:

It's meaningless for 4 of the 5 layouts, and it carries an unenforced invariant: it must be a superset of every commodity rendered, because orderedAmounts silently drops amounts whose commodity isn't in displayCommodityOrder. Violating it doesn't crash, it prints zeros.

so maybe we should mention it briefly in a dev comment at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants