News for hackers. Stuff that matters.
Re:Double Entry Accounting for Developers by goat_whisperer on Monday July 27, 2020 @07:40PM (#23970658)
From the site:

"I found the core explanation of double entry accounting to be confusing. After some time I distilled it down to the following:

"Debits decrease the value of an account. Always. [1] Credits increase the value of an account. Always. [1]

"[1] (1, 2) This is absolutely not what accountancy teaches. You’ll quickly see that there is a lot of wrangling over what account types get increased/decreased with a debit/credit. I’ve simplified this on the backend as I strongly feel this is a presentational issue, and not a business logic issue."

I mean, this is just....wrong. Maybe I'm not smart enough to see why this isn't completely incorrect? I mean I feel mathematically this will work but goes against so many core accounting principles it won't have much use except in the simplest of cases.

Re:Double Entry Accounting for Developers by neffy on Monday July 27, 2020 @09:02PM (#23971190)
The operation performed by debit/credit depends on the classification of the accounts. Accounts are listed traditionally with Assets on the left, and Liabilities and Equity on the right. A debit to a Liability account is a minus, and a credit is a plus, but it's the other way around on the asset side, where a debit is a plus, and a credit is a minus. (This kind of thing happens when English mugs other languages - Italian in this case - for its vocabulary).

The easy way to remember this is just to think that the right hand side is what you think it should be, and the left hand side isn't.

Double entry book keeping is under appreciated - it's one of the earliest examples of error correction and detection coding kicking around.

Re:Double Entry Accounting for Developers by wrycoder on Tuesday July 28, 2020 @01:12AM (#23972492)
I’ve found the best way is to remember the phrase, “Debits come in and credits go out.”

Let’s say you have a bank account. Your view of that account is opposite from the bank’s view.

You have $100 cash. That’s an asset from your POV, and it carries a debit balance on your books - when you received it, the cash “came in”.

You walk into the bank and deposit it. The cash goes out of your books, but an asset (the increase in your bank account) comes onto your books. You credit cash and debit asset.

From the bank’s POV, cash came in - they debit their cash account. And they credit your account in their books. That account is a liability from their POV - they owe you the money.

Notice how the debit and credit to cash even balanced across entities. If you talk about pluses and minuses, you’ll get confused quickly.

One of the worst things that ever happened was banks issuing “debit cards”. When you take cash from an ATM, it’s a debit from the bank’s POV. The bank carries your account as a liability, which carries a credit balance. (You are the bank’s creditor!)

So the bank debits your account (credit came in again) and credits their cash (cash went out).

You credit the bank account on your books (asset went out) and debit your cash (cash came in)

Just remember that a “debit card” reflects the banks POV and don’t let that confuse you about the meaning of “debit”. Debiting an asset is generally a good thing!

When making accounting transactions, debits always balance credits - meaning they total to zero in the code itself. It’s conventional to make assets positive (hey, having lots of assets is good, right?).

OP gains nothing but confusion by turning everything upside down.

Re:Double Entry Accounting for Developers by fauigerzigerk on Tuesday July 28, 2020 @05:44AM (#23974026)
>It’s conventional to make assets positive (hey, having lots of assets is good, right?). OP gains nothing but confusion by turning everything upside down.

I agree. However, the problem is that you can either make the vocabulary consistent or you can make the math simple, never both.

Making the math simple means you have to make a decision to always treat debits as positive and credits as negative or the other way around. You just have to be consistent.

Making the vocabulary work means you have to switch signs based on account type. But that makes the math and hence the software complicated and error prone.

Assets being positive makes sense. But debiting an asset account to make it more positive is counter intuitive. And expenses being positive doesn't make much sense either, because having lots of expenses is not so good, is it?

We're just accepting the inconsistent vocabulary as a price for having a simple mathematical model.

Re:Double Entry Accounting for Developers by wrycoder on Tuesday July 28, 2020 @09:05AM (#23975277)
Not inconsistent. It’s a matter of POV. Your mortgage is an asset from the bank’s POV, but a liability from your POV.

Expenses come in and cash goes out. Debit expense, credit cash.

From an accountancy POV, the debits of a transaction equal the credits. From a software POV, the account changes total zero. There is a difference in what the word “balance” means.

Re:Double Entry Accounting for Developers by lisper on Tuesday July 28, 2020 @02:11AM (#23972792)
> Debits come in and credits go out.

That is the complete opposite of common usage. When I get a credit on my credit card statement, it means money is coming in to me. When I get a debit on my debit card, it means money is going out from me. It's not rocket science, or at least it shouldn't be. And yet somehow accountants have managed to turn it into something even more confusing.

Re:Double Entry Accounting for Developers by paublyrne on Tuesday July 28, 2020 @02:35AM (#23972939)
Isn't this just a matter of perspective. You are being debited by the third party, meaning they are requesting money. The bank credits your account with money when they put something in your account.
Re:Double Entry Accounting for Developers by kgwgk on Tuesday July 28, 2020 @03:09AM (#23973122)
Common usage has turned the terms into something confusing. It's not the accountants fault.

Your credit card is linked to an account in someone else's books. They opened that credit account for you.

Re:Double Entry Accounting for Developers by wrycoder on Tuesday July 28, 2020 @09:27AM (#23975489)
If you want to track the bank account on your own books, what they call a debit, you call a credit. Ït’s a mirror image.

Debits come in to an entity, credits go out.

Re:Double Entry Accounting for Developers by SifJar on Tuesday July 28, 2020 @02:43AM (#23972985)
> Just remember that a “debit card” reflects the banks POV
Re:Double Entry Accounting for Developers by dragonwriter on Tuesday July 28, 2020 @09:15AM (#23975375)
> > Debits come in and credits go out.

> That is the complete opposite of common usage.

Nah, it's exactly the usage you are used to from statements you get.

> When I get a credit on my credit card statement, it means money is coming in to me.

When you get a credit card statement, it's a statement of the portion of your account in the card issuer’s books.

If you were keeping books for the card, they would be mirror images of the bank’s books.

Re:Double Entry Accounting for Developers by wrycoder on Tuesday July 28, 2020 @09:20AM (#23975419)
Your checking account is a liability from the bank’s POV.

Your credit card account is an asset from Visa’s POV. And a liability from your POV.

When Visa refunds that fee, it reduces their asset. And on your books, it reduces your liability.

A debit on your books is a credit on the counterparty’s books. A plus on your books is a minus on the counterparty’s books.

Re:Double Entry Accounting for Developers by hluska on Tuesday July 28, 2020 @05:27AM (#23973936)
I prefer to think of double entry accounting (with reasonable controls) as the first reasonable implementation of a blockchain. At its core, a double entry accounting system is a giant ledger where each transaction is linked to the last one ‘forever’ (assuming proper controls).

It’s likely the only reasonable implementation of a blockchain but we won’t know that for sure until cryptocurrency matures enough to develop reasonable controls. I’m not holding my breathe because then it’s just an accounting system with reasonable controls built in and there are already more than enough of those built with databases.

Re:Double Entry Accounting for Developers by verytrivial on Tuesday July 28, 2020 @06:59AM (#23974403)
> The operation performed by debit/credit depends on the classification of the accounts.

OP has chosen a consistency in the operation of debit+credit sign and applied a 'display adjustment' to implement the classification. This actually sounds like a lower entropy way to remember it -- no left hand/right hand stuff, just 'There two account types are sign reversed on display'. But it will confuse anyone who isn't indoctrinated to the convention, but one could argue that it is these various conventions that make double entry seem arcane in the first place!

Re:Double Entry Accounting for Developers by bdowling on Monday July 27, 2020 @08:21PM (#23970922)
> I mean, this is just....wrong.

It's beyond wrong. The developer here is redefining established accounting terms because he doesn't like their inconsistencies.

Re:Double Entry Accounting for Developers by gowld on Monday July 27, 2020 @09:04PM (#23971212)
> It's beyond wrong.

How so?

> The developer here is redefining established accounting terms because he doesn't like their inconsistencies.

Yes. What's wrong with fixing inconsistencies? Established accounting terms are from 500 years ago when people had trouble with subtraction.

Re:Double Entry Accounting for Developers by steventhedev on Tuesday July 28, 2020 @01:42AM (#23972653)
It's wrong in the sense that anyone who's studied standard accounting will look at your books and consider them to be incorrect.

This is important if you want to share your books or reports with your local tax office, who will begin investigating you for committing tax fraud. It's the same reason why no one fixes the HTTP "Referer" header typo. You can, but if you do then you'll have difficulty communicating with the outside world.

Re:Double Entry Accounting for Developers by verytrivial on Tuesday July 28, 2020 @07:04AM (#23974436)
> look at your books

I think OP is encoding the sign-reversal internally though, right? It "displays" the two incorrectly classified account types exactly per the standard convention instead of re-applying the convention at every operation. All reports would follow the 'Classic' conventions. At least that was my reading!

Re:Double Entry Accounting for Developers by navaati on Tuesday July 28, 2020 @10:15AM (#23975991)
It doesn't, the Equity account displays a negative number if the company is in the green (it decreases when you emit stocks), the Expense account displays positive numbers (it increases when you spend money), the Income account displays negative numbers (it decreases when you earn money).

In beancount, the accounting equation is Expense+Income+Equity=0 and all signs are always left intact (there is only addition).

So you start a company with a seed capital of $5. You borrow $5 to the bank, buy an expensive apple for $10, sell it for $15 and give the money back to the bank with an interest of $1, then close the exercise and carry the profits (don't distribute dividends). Your ledger is:

  Initial capital
    Assets:Cash +5 USD
    Equity:Seed -5 USD
  
  Borrow to the bank
    Assets:Cash +5 USD
    Liabilities:Bank -5 USD
  
  Buy an apple
    Assets:Apples +10 USD
    Assets:Cash -10 USD
  
  Sell the apple
    Income:Sales -5 USD
    Assets:Apples -10 USD
    Assets:Cash +15 USD
  
  Reimburse the bank
    Liabilities:Bank +5 USD
    Expenses:Interest +1 USD
    Assets:Cash -6 USD
  
  Close the exercise # beancount does that for you for any time period btw
    Expenses:Interest -1 USD
    Income:Sales +5 USD
    Equity:PreviousProfit +4 USD
Notice how every transaction balances to 0 just by summing it, no need to remember anything.

Now, you're at the beginning of the next exercise. To know your accounts you just compute a sum of every operation to it, again no special case. So your accounts are:

  Expenses 0 USD
  Income 0 USD # as expected at beginning of exercise
  Assets:Apples 0 USD
  Assets:Cash 9 USD
  Liabilities:Bank 0 USD
  Equity:Seed -5 USD
  Equity:PreviousProfits -4 USD
And yet again, the sum of all of that is 0.

Personally I like it, not having any special cases. Yes, it may confused an accountant (because they learned the special cases by heart ! Somebody coming with a fresh mind has no reason to be confused, it's all just conventions !) but it's simpler for me and just as consistent.

Re:Double Entry Accounting for Developers by verytrivial on Tuesday July 28, 2020 @11:33AM (#23976818)
FWIW I did an accounting elective at college and ran the books for a small business for a couple of years. I'm comfortable with the conventions :-) I was just saying OP was choosing to encode the conventions differently internally and display them a different way to meet the external convention, like GMT+TZ. You need never known your computer stores time in GMT and most people don't, even the accountants.
Re:Double Entry Accounting for Developers by PhasmaFelis on Monday July 27, 2020 @11:19PM (#23971959)
> What's wrong with fixing inconsistencies?

Nothing, if you can convince the entire user base to do it at the same time. If you decide to unilaterally fix inconsistencies, you've just made it impossible to understand what anyone is saying without additional metadata saying which version you're using.

And if you start telling learners that your "fixed" version is all there is, hiding the actual standard that most of the world uses, you are basically lying to them and setting them up to fail.

Re:Double Entry Accounting for Developers by dragonwriter on Tuesday July 28, 2020 @09:24AM (#23975461)
> What's wrong with fixing inconsistencies?

There are no inconsistencies to fix; the credit/debit model is fully consistent, just implementation inconveniences. And I don't think anyone would have trouble with this if it was titled “implementing double entry accounting in software” rather than “double entry accounting for developers”; that is, it's a fairly decent explanation of how, if you have preexisting understanding of the domain, to reduce it to software internals, but very bad as an explanation of the domain (whether to an audience of developers or otherwise.)

> Established accounting terms are from 500 years ago when people had trouble with subtraction.

People still have trouble with substraction compared to addition, especially with large numbers.

Re:Double Entry Accounting for Developers by bdowling on Monday July 27, 2020 @10:24PM (#23971699)
> What's wrong with fixing inconsistencies?

In general, nothing. It's just not the software developer's job. If the accounting profession decided to change certain terms to fix inconsistencies, that would be fine.

Re:Double Entry Accounting for Developers by fauigerzigerk on Tuesday July 28, 2020 @06:18AM (#23974192)
I think that's missing the point of the original article. Of course you have to present a view of the accounts that is consistent with accounting rules and conventions. But that doesn't necessarily mean you have to adopt that external view as an internal model for any software you're writing.
Re:Double Entry Accounting for Developers by inopinatus on Tuesday July 28, 2020 @07:46AM (#23974709)
At audit time the world of “holy shit what were these people thinking?” will be colossal, because we do not get to pretend that a system is a black box at audit time.

If those records don’t make sense to an accounting professional, then they’re fucked up, and that’s all she wrote. The world of audit has seen a million shysters try to falsify their books under the guise of alternative methods, and they are not interested in some self-serving hubris from programmers about re-inventing their own profession.

So this guide isn’t just philosophically off beam. It could get someone fired or sued.

Probably not prosecuted though. Probably.

Re:Double Entry Accounting for Developers by 3pt14159 on Tuesday July 28, 2020 @08:17AM (#23974920)
Yeah I've worked on so many systems that dealt with money. Telephone invoicing, business accounting, ticket sales, etc.

One of the businesses I worked for did online invoicing and they initially started off without double ledger accounting. I was employee 30 or so and I kept repeating "we need double ledger accounting" every month or so. Nobody really listened to me (to be fair I was young, but this was after the telephone invoicing job) until the cracks started to form. It took them years to transition to a new system. Do not re-invent accounting with your own terms. International commerce runs on it and it has figured out a lot of the edge cases.

Re:Double Entry Accounting for Developers by fauigerzigerk on Tuesday July 28, 2020 @08:41AM (#23975078)
Accounting professionals can only ever look at user interfaces. If there is a suspicion of fraud then a court can ask expert witnesses to look into the software itself.

The law does put some constraints on what accounting software must and must not allow users to do (e.g change data without leaving a trace).

But I'm not aware of any specific legal requirements regarding data representation or mandating the use of specific algorithms where mathematically equivalent ones exist.

Re:Double Entry Accounting for Developers by Lazare on Tuesday July 28, 2020 @10:27AM (#23976131)
There are no inconsistencies here.

We have an algebraic indentity, a + b = x + y. (Let's not even think about what those might represent; it doesn't matter.)

The two sides must always be equal. Any transaction must maintain that equality. Therefore, any transaction must increase both sides by the same amount, decrease both sides by the same amount, or leave both sides unchanged.

One way to ensure this is respected is to add up everything which increases the left side or decreases the right side, then add up everything which decreases the left side or increases the right side, and ensure these two subtotals match. If they do, the transaction balances, and is legal.

By convention, we call things of the first type (which increase the left side or decrease the right side) "debits", and things of the second type (which increase the right side or decrease the left side) "credits". This lets us say "debits must equal credits" as a shorthand, although again what we really mean is that the two sides must continue to balance.

The end. There's really no inconsistency here.

Re:Double Entry Accounting for Developers by mariomariomario on Monday July 27, 2020 @09:39PM (#23971420)
Generally Accepted Accounting Principles
Re:Double Entry Accounting for Developers by juped on Tuesday July 28, 2020 @02:43AM (#23972988)
There's a lot wrong with fixing consistencies.
Re:Double Entry Accounting for Developers by jlj on Monday July 27, 2020 @10:56PM (#23971859)
I learned from my accounting 101 professor, "debits on the left, credits on the right."

Then later after learning about natural account balances, it all made sense. If an account has a debit balance, a debit increases the balance and a credit decreases it. An asset or expense account has a debit balance.

Credit balance is just the opposite. Liabilities, revenue, accounts. Credit is an increase, debit decrease. (I think equity too but I always have to look it up. Rarely work with equity accounts in my day to day)

Re:Double Entry Accounting for Developers by juped on Monday July 27, 2020 @11:30PM (#23972006)
Equity accounts are confusing.
Re:Double Entry Accounting for Developers by jkulubya on Tuesday July 28, 2020 @12:32AM (#23972295)
I wish I could tell you how to remember it from first principles, but I can’t do what I did was burn the A = L + (OE/Equity) accounting equation into my head. Then I remember that the when my bank balance goes up, the bank speaks of a credit in their accounts which is a debit to assets in my account. Then L + OE must be credit accounts.

Why are OE and L on the same side? Well to finance an asset, say a new car for your business, the company would either take on some debt (L) or you’d put in some of your own money (OE) in exchange for more ownership. I don’t know if that’s more confusing or less

Re:Double Entry Accounting for Developers by juped on Tuesday July 28, 2020 @02:42AM (#23972984)
I mean, it's not hard to remember. They're liability-like. It's just their uses in practice that're confusing.

BTW, nonprofits have Net Assets accounts instead of Equity accounts.

Re:Double Entry Accounting for Developers by junkrat002 on Tuesday July 28, 2020 @01:05AM (#23972453)
Ex-finance SWE here. I closed the article after that part. If you don't understand accounting and read this, you'll only be more confused when you learn how accounting actually works.

For the most part, devs in general should not be teaching accounting. There's a reason that it is so challenging to earn a CPA.

Re:Double Entry Accounting for Developers by Hamuko on Tuesday July 28, 2020 @01:36AM (#23972619)
>For the most part, devs in general should not be teaching accounting. There's a reason that it is so challenging to earn a CPA.

Surely there's a big difference between earning a CPA and just knowing the basics of accounting.

I had a summer job helping out with entry in a family member's small accounting firm. I don't think that double entry accounting is that crazy of a concept that it cannot be grasped by someone without a degree in the field.

Re:Double Entry Accounting for Developers by junkrat002 on Wednesday July 29, 2020 @02:20AM (#23983940)
Yes I agree, a vast difference between basic accounting and a CPA. I am not a CPA, but I do understand accounting.

That doesn't change the fact that I'd be wary of any accountant writing a blog post on how to write good quality code for production. Are there accountants out there who can do a good job of that? Absolutely. Are there many more accountants who would do a poor job of that? My guess is also yes.

Re:Double Entry Accounting for Developers by inopinatus on Tuesday July 28, 2020 @08:19AM (#23974935)
Learning anatomy doesn’t qualify someone as a surgeon.
Re:Double Entry Accounting for Developers by rbg246 on Tuesday July 28, 2020 @06:53AM (#23974362)
It's not that hard to qualify, it's the equivalent of three years software engineering experience with some side study.

It's more a case of someone who has one year of writing JavaScript shouldn't be writing on the theory of software development.

Re:Double Entry Accounting for Developers by junkrat002 on Wednesday July 29, 2020 @02:26AM (#23983970)
I agree with your statements. If someone has spent three years studying accounting, I would certainly expect that he or she is able to blog coherently about double entry accounting.
Re:Double Entry Accounting for Developers by Havoc on Tuesday July 28, 2020 @04:15AM (#23973541)
>I mean, this is just....wrong.

I wouldn't call it wrong per se, but it's about what would happen if I as accountant designed a database architecture. It would work, but any programmer looking at the dodgy code would think "omg what have you done?"

Re:Double Entry Accounting for Developers by watsocd on Monday July 27, 2020 @08:10PM (#23970855)
That was the first thing I saw that was wrong.

All account balances should normally be positive. Depending on what side of the balance sheet they are, a debit or credit could increase or decrease an accounts balance.

Re:Double Entry Accounting for Developers by qznc on Tuesday July 28, 2020 @12:48AM (#23972379)
In my opinion the core idea is about the data model: Double entry accounting stores movements of money instead of accounts.

Everything else follows from that idea plus a bunch of terminology.

Re:Double Entry Accounting for Developers by t-vi on Friday July 31, 2020 @05:23AM (#24007032)
Well, if you want to define accounting in an alternate universe, you can define it that way. However, if you want to describe accounting as it is done, it is utterly wrong. Doing this will bite you once you read other sources on accounting, talk to accountants, the tax office, etc.

From my experience, if you're doing accounting beyond a hobby, you likely want to follow whatever GAAP (generally accepted accounting practices), and likely need to consult references for how specific cases are represented. If you then don't use the same language and conventions as everyone else, it's just even more of a pain than it is.

My experience here is that I was with a large audit company, albeit as an actuary rather than an accountant. I did have the opportunity to dig quite deep accounting records of insurance companies there. Now I own an incorporated company and do my own accounting and taxes (with GnuCash for accounting, even if I hand-rolled reporting for XBRL export and all).

Re:Double Entry Accounting for Developers by SnowingXIV on Tuesday July 28, 2020 @10:23AM (#23976088)
Spot on. This is another situation of trying to solve a problem that doesn't exist and the writer does not understand at all. There are reasons why GAAP and IFRS exist. Accounting can make a lot of sense to a programmer, I've moved between fields early on with relative ease because accounting is extremely rule based/puzzle-oriented and adheres to a structured and specific framework. I haven't touched accounting in years (though I do have a bachelors in accounting) but this is jarring and would not recommend this to anyone.
Re:Double Entry Accounting for Developers by goat_whisperer on Tuesday July 28, 2020 @10:49AM (#23976370)
Hey Snowing, would love to learn more about your experience -- I'm a fellow accountant (BS accounting) looking to move into development.
Re:Double Entry Accounting for Developers by SnowingXIV on Tuesday July 28, 2020 @01:52PM (#23978636)
Nothing too special, I worked for a few large tech consulting companies early on in finance but did a bunch of a side development projects/freelance work as well. One of those ended up becoming a full-time gig so jumped ship and went from there.

Best of luck!

Re:Double Entry Accounting for Developers by juped on Monday July 27, 2020 @11:33PM (#23972024)
It's actually less wrong, but still wrong, to say the exact opposite (i.e., "Debits always increase and Credits always decrease").
Re:Double Entry Accounting for Developers by juped on Monday July 27, 2020 @11:27PM (#23971990)
This comment expressing confusion on this valiantly misguided OP seems like a good place to throw my standard explanation out into the aether to do neither readers nor myself any good.

A transaction has two polarities, because it represents a flow of value. The credit side is the source, the debit side is the sink/destination/whatever. Let's temporarily pretend that every transaction hits exactly two accounts for the moment (which is not true), to make it easier.

Let's say we have $1000 in Cash, which is an Asset, and we want to buy a Pizza, which is also an Asset, for $20. How does this look in accounting?

Cash provides the source side, and Pizza provides the sink. Cash is credited $20, and Pizza is debited $20. If we ran the balances now, Cash would come out to $980, and Pizza would come out to $20.

Let's unwind that transaction. We're a business; we don't trade cash for pizzas. We contract for delivery of pizzas with a pizza vendor, who invoices us.

So here we are, with $1000 in Cash and $0 worth of Pizza. The pizza delivery driver comes, and hands us a pizza and an invoice. We know we have to debit Pizza $20; what is the credit source for this debit? Well, the pizza vendor has actually extended us a loan worth $20, in a sense (this is called "trade credit"), and the offsetting entry is the fact that we owe the vendor $20, as memorialized in its invoice. This goes in a Liability account, usually called something like Accounts Payable.

Current balances (if we ran them - "running the balances" is thought of by accountants as a discrete operation, just FYI):

  Assets/Cash $1000
  Assets/Pizza $20
  Liabilities/Accounts Payable $20
Accountants think of accounts as being naturally debit-increased, like Assets, or naturally credit-increased, like Liabilities. I find it a bit misleading to try to think of these as positive or negative signs, as you might be inclined to at this point. It's just $20 - don't even think of it as cr $20, IMO. (dr and cr are the abbreviations for debit and credit.)

Let's just leave that on the books and eat the pizza. After eating the pizza, we no longer have $20 worth of pizza, so we have to credit Assets/Pizza $20. What do we debit to offset this - i.e., where did the pizza value flow to? In this case, it would be a Depreciation account (these are debit-increased) - something like Depreciation/Eaten Pizzas. So we have:

  Assets/Cash $1000
  Assets/Pizza $0
  Depreciation/Eaten Pizzas $20
  Liabilities/Accounts Payable $20
(a commenter below points out correctly that this would be an Expense, not a Depreciation, and I'm still in the edit window!)

Meanwhile, someone pays us on one of our invoices, which we had sent out earlier offscreen. When we delivered our fine $50 widget and invoiced the buyer, we entered that into our accounting system as a debit of $50 to Assets/Accounts Receivable, and a credit of $50 to Assets/Widgets. This part of the system looks like (we still have 9 widgets in stock):

  Assets/Cash $1000
  Assets/Widgets $450
  Assets/Accounts Receivable $50
But now that the invoice is paid, $50 of value flows from our receivables asset into our cash asset - i.e., we credit A. R. $50, and debit cash $50. Getting paid is nice.

  Assets/Cash $1050
  Assets/Widgets $450
  Assets/Accounts Receivable $0
After the customarily long delay, our accounts payable department has approved payment of the pizza invoice. Cash has to be credited, because cash is flowing out, and it's probably easy to guess the debit where it goes to - that's right, our Liabilities/Accounts Payable is finally cleared, because we don't owe the pizza vendor $20 anymore.

  Assets/Cash $1030
  Assets/Pizza $0
  Assets/Widgets $450
  Assets/Accounts Receivable $0
  Depreciation/Eaten Pizzas $20
  Liabilities/Accounts Payable $0
Hope that makes sense. It gets more complicated in real life. Accounting is nontrivial. If there are any accountants in the thread, maybe they can correct any errors I've made.
Re:Double Entry Accounting for Developers by juped on Tuesday July 28, 2020 @02:56AM (#23973054)
BTW, why is "running the balance" a discrete operation to accountants? Because accountants' source of truth is the transaction log, which they call a "ledger".

Ledger entries look (conceptually, not literally) like this:

  |tx id|      account      | debit|credit|
  |  123|Cash (bank 1)      |    25|     0|
  |  123|Cash (bank 2)      |    25|     0|
  |  123|Accounts Receivable|     0|    50|
with the constraint that a transaction is not valid unless the sum of debits equals the sum of credits (and, no, you can't have both nonzero debit and credit in one line, though sometimes both are zero).

Accounting is, of course, way older than computers, so accountants like to regularly "close the books" (checkpoint the state and generate reports).

Aside, I think the mental block for techies when it comes to accounting is just that many don't want to accept that accountants understand accounting. It looks like databases to them, and those are TECH!

Re:Double Entry Accounting for Developers by feanaro on Tuesday July 28, 2020 @05:29AM (#23973953)
Well, they are databases. That doesn't imply accountants don't understand accounting. Both can be true.

I think a large factor in the "programmers reinterpreting accounting" phenomenon is the fact that accounting is full of somewhat idiosyncratic terminology and conventions which are somewhat counter to modern mathematical conventions. These conventions should still be upheld in order to be mutually intelligible with the accounting world, but it seems quite unlikely they are the optimum in terms of ergonomics and ease of understanding. If we designed accounting from scratch today, I doubt we would end up with these conventions.

A naive programmer is perhaps in one of the best positions to see these idiosyncrasies and think "This is using the wrong conventions and can be made much simpler by just shifting some signs around!".

Re:Double Entry Accounting for Developers by patmcc on Monday July 27, 2020 @11:33PM (#23972026)
One minor "error" - depreciation only happens on capital assets, that should be a Pizza Expense.
Re:Double Entry Accounting for Developers by juped on Monday July 27, 2020 @11:35PM (#23972036)
Yeah, I guess eating pizza usually counts as opex.
Re:Double Entry Accounting for Developers by kgwgk on Tuesday July 28, 2020 @05:30AM (#23973959)
But looking down at the balance you may find some of it gets capitalized.
Re:Double Entry Accounting for Developers by navaati on Tuesday July 28, 2020 @11:07AM (#23976568)
(for these who struggled like me: the weighting balance,not the account balance. Nice one once you get that :)
Re:Double Entry Accounting for Developers by akgoel on Monday July 27, 2020 @07:45PM (#23970684)
Even bullet 4 has assets and expenses multiplied by -1. Completely .... wrong.

Maybe this might work for a bank where assets and liabilities are sort of flipped from a non-bank business?

Re:Double Entry Accounting for Developers by patmcc on Monday July 27, 2020 @11:38PM (#23972047)
Banks and non-banks don't treat assets/liabilities in different ways in accounting - banks just engage in transactions most other businesses don't, as a normal matter of business.

For example - if you're holding someone's money for them, that's a liability - you have to pay it back some time. If someone owes you money, that's an asset - it's worth something. Banks use the cash from liabilities (people's savings accounts) to pay for assets (mortgages) and make money on the spread.

Re:Double Entry Accounting for Developers by navaati on Tuesday July 28, 2020 @11:21AM (#23976711)
Except Fractionnal Reserve. It kinda throws off the idea, how do they do then ?

Let's see, when they lend money they don't have (which is what it is) they increase the number on your account, that is they create a big liability for themselve. On the other hand they create an asset wich is your debt to them. So accounting-wise, it works out, like theorically I could do that (lending) even if I have €0, it's all paper.

But then you're gonna go and empty that account to buy your house, reducing their liability and taking (reducing) their cash instead... that they don't have !

So how does it work ? Does it just work because you don't actually buy houses with bills and coins but with bank transfers, then just shifting the paper magic to another bank ?

To be honest I know they can do something my broke self can't, and it has to du with central banks, but what is it exactly ? Something like "if everybody happens to empty their account to cash at the same time, don't worry mate we'll print them bills and give them to you, pinky promise" ?

Re:Double Entry Accounting for Developers by sago on Monday July 27, 2020 @07:55PM (#23970745)
I agree. Except I think you're being generous :)

It would not work for a bank. The only reason they 'sort of flip' is that they give your account from their perspective. Your statement is a slice of their accounting.

Re:Double Entry Accounting for Developers by inopinatus on Tuesday July 28, 2020 @07:41AM (#23974678)
They’re not flipped. From a bank’s point of view, any money they hold on your behalf is a liability. Your bank statement is an extract from their books. When they take a fee, it’s a debit on your statement, because it’s a credit to revenue on theirs.
Re:Double Entry Accounting for Developers by Lazare on Tuesday July 28, 2020 @10:04AM (#23975891)
The traditional accounting identity is something like "Assets = Liabilities + Equity", or in an expanded form "Assets = Liabilities + Contributed Capital + Revenue - Expenses - Dividends" (from Wikipedia https://en.wikipedia.org/wiki/Accounting_equation). You can re-arrange that as:

Assets + Expenses + Dividends = Liabilities + Contributed Capital + Revenue

Traditional accounting takes this as says: "All accounts have positive values. All transactions contain an equal number of debits and credits. Debits always come first, are always written on the left, and so it (sort of) makes sense for debits of left hand side accounts to always increase the value of the account, while debits of right hand side accounts always decrease the value in the account. Similarly, credits come second, are always written on the right, credits of right hand side accounts increase the value of the account, and credits of left hand side accounts decrease the value of the accounts."

It turns out if you work through the implications of this, it works perfectly. I buy lunch for $5, so I must have a $5 debit and a $5 credit. That's an expense; my expenses are going up, expenses are on the left, so they go up via a debit. The matching credit could be to cash; cash is an asset, it's also on the left, credits make left hand accounts go down, that makes sense. Or the matching credit could be an accounts payable account, that's on the right hand side, and credits make right hand accounts go up, which again makes sense.

The core logic here is that changes must balance. If your changes are both on one side, one will be positive and one will be negative (summing to 0). If your changes are on opposite sides, either both will be positive or both will be negative (still summing to zero).

But, you could also re-arrange the equation further:

Liabilities + Contributed Capital + Revenue - Assets - Expenses - Dividends = 0

Algebraically, that's the same. If you built a system on that, you could say something like "All transactions must sum to zero. Asset, expense, and dividend accounts are subtracted from the balance, while other accounts are added to it." That still works. My $5 lunch increases expenses, which is a "negative type" account, so I have to either increase a matching "positive type" account (like liabilities) or decrease a matching "negative type" account (like assets) so everything stays zero. It doesn't feel...easier, but it works.

Or you could take it a step further, and weirder, and say:

Assets + Expenses + Dividends + Liabilities + Contributed Capital + Revenue = 0

That...uh....doesn't work mathematically, unless you flip the sign of all assets, expenses, and liabilities. So maybe:

(-Assets) + (-Expenses) + (-Dividends) + Liabilities + Contributed Capital + Revenue = 0

I dunno, this is getting a bit weird. Now my $5 lunch is a $5 credit and a $5 debit. Expenses has gone up, so that must be what the author calls a credit, but since expenses is a magic negative account the displayed value will go down. And then we must have a match debit (in the authors terms) which will make an account go down. And again, we can pick assets to go down (if I spent cash), except again assets is a magic flipped account so will make the displayed value of assets increase, or we could pick liabilities which is a normal account and thus the value will actually go down.

Technically, all this is interchangeable. However: The standard form (LHS = RHS, debits increase LHS and decrease RHS, credits increase RHS and decrease LHS, debits = credits) is universally used around the globe, and has been in active use since the middle ages. It's also, in my view, relatively intuitive once explained. The middle form (all accounts sum to zero) is unorthodox, but also fine. Both require to to know an equality, and ensure that each transaction respects the equality.

The linked form is, in my view, by far the least intuitive, and also re-uses accounting terms with a different meaning. Not only does it not, in my view, help novices understand accounting, but I fear learning it makes it actively harder because you'll need to unlearn it first.

But it does, technically, work.