logoalt Hacker News

jltsirenlast Saturday at 5:52 PM1 replyview on HN

Negative numbers are a hack in the sense that they can be confusing, and it's easy to make mistakes with them. For example, I would interpret "-100 L/min outflow" as an indirect equivalent of "100 L/min inflow". To avoid confusion, you could drop terms "inflow" and "outflow" completely and talk about "-100 L/min (net) flow". Or you could separate the type and the magnitude of the flow.


Replies

dagsslast Saturday at 7:28 PM

There's a difference between UI and code. In code, it is more complicated to do

    if (change.direction == OUT) {
        total -= change.value
    } else {
        total += change.value
    }
than to simply use negative numbers and do

    total += change
The same in accounting, it can in my experience often be convenient that your Entry database tables look like

    account          amount
    ---              ---
    income/sales     -100
    receivables      +100
rather than

    account       debit    credit
    ---           ---      ---
    income/sales           100
    receivables   100

The first one is just simpler, and you also get the nice graph properties (cuts, zero-sums, etc) discussed in the OP. Simpler database model, simpler code, less cases to test, easier to do ad hoc analysis queries, etc.

Of course in the UI one can simply flip signs on credit-normal accounts to avoid displaying negative numbers if one wishes.

show 1 reply