Don’t Sink Your First Attempts at Plaintext Accounting

338 views
Skip to first unread message

Robert Nielsen

unread,
Apr 19, 2017, 6:20:20 PM4/19/17
to hledger

I wrote the article below to help newcomers to plaintext accounting. Simon, if you think this would be useful for any of your websites, you have my permission to post it there.


Enjoy!


Don’t Sink Your First Attempts at Plaintext Accounting

 

Plain text accounting programs such as Ledger and HLedger are powerful, helpful tools, but your own user errors can take the wind out of your sails when you would rather be breezing through your accounting. Here, then, are several mistakes—ones that I have personally tested—that you will want to avoid in order to enjoy the benefits of plaintext accounting without unnecessary pain.

 

Preliminary assumptions:

 

·      You have Ledger or Hledger already installed and running on your PC, and you are ready, or have already begun, to start entering your data.

·      You understand that there are normally three lines of text for each transaction, and you know basically what’s supposed to go in each line

 

Formatting Can Be Critical

 

The following two formatting errors will cause your work to come to a screeching halt. Here’s how to avoid them.

 

First, as you enter transactions, make sure that the second and third (and any additional) lines in a transaction are indented by at least one space. In other words, do this:

 

2017/01/15 Acme

  Expenses:Household   $20.00 ;roadrunner trap

  Liabilities:CreditCard

 

Not this:

 

2017/01/15 Acme

Expenses:Household   $20.00 ;roadrunner trap

Liabilities:CreditCard

 

The above two transactions look very similar to the human eye, but the second one doesn’t work.

 

Another formatting issue that’s easy to miss, is that you need at least two spaces between the category ”Expenses:Household,” below) and the amount of the transaction (“$20.00”):

 

2017/01/15 Acme

  Expenses:Household  $20.00

  Liabilities:CreditCard

 

Contrast this with the wrong way:

 

2017/01/15 Acme

  Expenses:Household $20.00

  Liabilities:CreditCard

 

As it’s very hard to see the number of spaces in the critical parts, I have written them out in the two transactions below.

 

Correct:

 

2017/01/15 Acme

  Expenses:Household[space][space]$20.00

  Liabilities:CreditCard

 

Wrong:

 

2017/01/15 Acme

  Expenses:Household[space]$20.00

  Liabilities:CreditCard

 

Again, it’s easy for us humans to miss the difference between one space and two, but your plaintext accounting program will notice.

 

Use Currency Symbols Consistently

 

Here’s another error that’s easy to make and easy to overlook – omitting a currency symbol. For example:

 

2017/01/15 Acme

  Expenses:Household   20.00

  Liabilities:CreditCard

 

If you have been working with US dollars, it’s very easy to think that the above 20.00 refers to $20.00, but Ledger and HLedger will process this amount as something other than US dollars.

 

Using a Comma When You Need a Period

 

Another mistake to avoid is inadvertently typing a comma where a decimal in required. Let’s say, for example, that you are recording the purchase of a yacht for slightly more than $1.2 million. Here is the error:

 

2017/01/16 Mega Yacht Company

   Expenses:Leisure   $1,245,449,72

   Assets:Bank:Checking

 

The correct way to write this is:

 

2017/01/16 Mega Yacht Company

   Expenses:Leisure   $1,245,449.72

   Assets:Bank:Checking

 

If you are using Emacs, erroneously using a comma instead of a decimal point as shown above can manifest itself as a confusing error message about no transactions that need to be cleared.

 

Summary

 

·      Indent the second and following lines of each transaction. The first line of the transaction needs to be flush left.

·      Use two spaces after the transaction category and before the currency symbol (assuming that you are working with currency).

·      Use the currency symbol before every amount that’s currency.

·      Don’t use a comma when you need to write a decimal point.

 

So, avoid the above mistakes and enjoy some clear sailing with plaintext accounting.


Author: Robert Nielsen

Simon Michael

unread,
Apr 19, 2017, 7:03:09 PM4/19/17
to hle...@googlegroups.com
Hi Robert,

I love it! Thanks for writing docs. If you don't have a blog or site where you'd like to keep it, I'll gladly add it to hledger.org/docs or plaintextaccounting.org - let me know your preference.

In the context of hledger, the handling of decimal point and digit groups is a bit more complicated; we also support comma for decimal point and period for digit groups (and those groups don't have to be thousands). So I think that section may need at least a little tweaking. See http://hledger.org/manual.html#amounts and https://en.wikipedia.org/wiki/Decimal_mark.

The hledger manual also explains a little about how amounts are formatted, eg the first-amount-sets-style feature, which might be another thing to consider alerting newcomers to.

Robert Nielsen

unread,
Apr 20, 2017, 6:49:27 PM4/20/17
to hledger
Thank you for the encouragement, and the piece might fit plaintextacounting.org slightly better so that would be my first thought. I would be very happy to have it posted there. 

Also, in response to your comments, I added a paragraph to provide additional information regarding the alternate system for separating thousands and integers from decimals. The updated version is attached.

Rob Nielsen
Plain Text Accounting -- Errors.docx

Simon Michael

unread,
Apr 20, 2017, 7:49:32 PM4/20/17
to hledger
Thanks! I have converted this to markdown and added it at

http://plaintextaccounting.org/#docs -> Don’t Sink Your First Attempts at Plaintext Accounting

I made one change to the content: consistent use of Hledger instead of HLedger. The canonical name which I always use is hledger, but capitalising one letter is not so bad. Two leads to madness!

If you have a github account, one way to make changes is

(plaintextaccounting.org -> footer -> github repo -> plaintext-accounting-errors.md -> pencil)

and if you let me know your accountname, I'll make sure you have write access. You might want to consider adding your author name/contact info, revision number/last updated date, etc.

Best,
-Simon



-- 
You received this message because you are subscribed to the Google Groups "hledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hledger+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<Plain Text Accounting -- Errors.docx>

Martin Blais

unread,
Apr 21, 2017, 11:16:59 AM4/21/17
to hle...@googlegroups.com
These all look to me like they should be bug reports, not required reading.

- The two space rule hurts everyone at some point. Why not design the syntax to not be subject to the problem in the first place? Constrain the syntax not to allow spaces and you don't have this problem anymore.

- A missing currency symbol could be inferred automatically in many cases. If you don't use it and you can't infer it, an error should be raised.

- Bad commas in numbers should be easily detectable in the parser in most cases (they have to align to every three; if not aligned to groups of three, an error should be raised).

 

So, avoid the above mistakes and enjoy some clear sailing with plaintext accounting.


I'd suggest you can make the software not allow those mistakes in the first place.
Smooth sailing is a clear and unambiguous error message raised by the interpreter...

Simon Michael

unread,
Apr 21, 2017, 11:40:04 AM4/21/17
to hle...@googlegroups.com
On Apr 21, 2017, at 8:16 AM, Martin Blais <bl...@furius.ca> wrote:
These all look to me like they should be bug reports, not required reading.

Hi Martin.. a very reasonable thought. We should do better. The devil is in the details, which I'd like to make some headway on:

- The two space rule hurts everyone at some point. Why not design the syntax to not be subject to the problem in the first place? Constrain the syntax not to allow spaces and you don't have this problem anymore.

I've thought of it many times. Ok, we disallow spaces in account names. What would be the plan for migrating (a) existing user data (b) existing docs and examples ? What would be the cost of this particular incompatibility with Ledger ?

- A missing currency symbol could be inferred automatically in many cases. If you don't use it and you can't infer it, an error should be raised.

How would that work ? Is that assuming one currency per account ? What about cases where it can't be inferred ?

- Bad commas in numbers should be easily detectable in the parser in most cases (they have to align to every three; if not aligned to groups of three, an error should be raised).

I think you're not saying drop support for using comma as decimal point ? And you are saying that digits should only be grouped in threes ?

According to https://en.wikipedia.org/wiki/Decimal_mark#Digit_grouping , digits are not (only) grouped in threes in India. I'm not finding other applications for that feature at the moment, but that seems a pretty big one. Maybe Kamar and others could comment.


Simon Michael

unread,
Apr 21, 2017, 11:44:29 AM4/21/17
to hle...@googlegroups.com
*Karan*, I meant.

Martin Blais

unread,
Apr 21, 2017, 12:28:57 PM4/21/17
to hle...@googlegroups.com
On Fri, Apr 21, 2017 at 11:40 AM, Simon Michael <si...@joyful.com> wrote:

On Apr 21, 2017, at 8:16 AM, Martin Blais <bl...@furius.ca> wrote:
These all look to me like they should be bug reports, not required reading.

Hi Martin.. a very reasonable thought. We should do better. The devil is in the details, which I'd like to make some headway on:

- The two space rule hurts everyone at some point. Why not design the syntax to not be subject to the problem in the first place? Constrain the syntax not to allow spaces and you don't have this problem anymore.

I've thought of it many times. Ok, we disallow spaces in account names. What would be the plan for migrating (a) existing user data (b) existing docs and examples ? What would be the cost of this particular incompatibility with Ledger ?

(a) A Python script users can run over their file
(b) Another Python script you can run over your docs

 
- A missing currency symbol could be inferred automatically in many cases. If you don't use it and you can't infer it, an error should be raised.

How would that work ?

If it's unambiguous the currency is interpolated automatically.
e.g. if all the other postings's cost currency is the same.
Actually, if you have mixed currencies, one could even look at whether the rest balance and ignore those, e.g.

   2017-04-01 * "Train tickets"
    Liabilities:CreditCard     -230.00 USD
    Expenses:Trains       230.00 USD
    Assets:Points     150 AMTKPTS
    Income:Rewards   -150

The first two above balance, so clearly the fourth posting's currency is AMTKPTS


 
Is that assuming one currency per account ?

No, but using the set of per-account currency constraints is yet another source of disambiguation.

Basically, if the currency is missing, from 
- the set of unbalanced postings
- per-account currency constraints
compute the intersection of possible currencies. 
If the size of that set > 1, throw an error. Otherwise, assign it (and perhaps warn if in pedantic mode).

 
What about cases where it can't be inferred ?

Throw an unambiguous error instead of silently accepting it.

 

- Bad commas in numbers should be easily detectable in the parser in most cases (they have to align to every three; if not aligned to groups of three, an error should be raised).

I think you're not saying drop support for using comma as decimal point ? And you are saying that digits should only be grouped in threes ?

Yes.
Or whatever weird convention the locale says is legit.


According to https://en.wikipedia.org/wiki/Decimal_mark#Digit_grouping , digits are not (only) grouped in threes in India. I'm not finding other applications for that feature at the moment, but that seems a pretty big one. Maybe Kamar and others could comment.

Another option is to choose not to support it.

BTW I haven't solved this one either, I just strip the commas for now.

jungle boogie

unread,
Feb 20, 2018, 12:06:30 PM2/20/18
to hle...@googlegroups.com
On 04/19/2017 03:20 PM, Robert Nielsen wrote:
> I wrote the article below to help newcomers to plaintext accounting.
> Simon, if you think this would be useful for any of your websites, you
> have my permission to post it there.
>
>
> Enjoy!
>
>

Thanks for posting this! Good info in here.

>
> Formatting Can Be Critical
>
>
>
> The following two formatting errors will cause your work to come to a
> screeching halt. Here’s how to avoid them.
>
>


I use vim and I'd like to setup a vim modeline in the hledger file. Do
you have a recommendation on what I should use?

When I do hleder -f file.journal print > printed, the spacing is much
greater than two spaces, but I don't quite know what it is. I'd like the
file to be uniform throughout and when I open in a text editor (other
than vim), for the file to look sane.

Simon Michael

unread,
Feb 20, 2018, 12:41:46 PM2/20/18
to hledger

> On Feb 16, 2018, at 9:05 PM, jungle boogie <jungle...@gmail.com> wrote:
> I use vim and I'd like to setup a vim modeline in the hledger file. Do
> you have a recommendation on what I should use?
>
> When I do hleder -f file.journal print > printed, the spacing is much
> greater than two spaces, but I don't quite know what it is. I'd like the
> file to be uniform throughout and when I open in a text editor (other
> than vim), for the file to look sane.

I think print indents by four spaces by default. I prefer two spaces myself, but I think most other tools like Ledger and ledger-mode use four, so it has been easier to just follow that style.
Reply all
Reply to author
Forward
0 new messages