On Thu, Jun 22, 2017 at 8:17 AM, <[email protected]> wrote:

> *TL/DR: what's the purpose of new_directive() wrapper around NamedTuple()?*
>
> I've been following Beancount for a while, and I wanted to fork the
> project and make some modifications for my own use and maybe contribute
> back to the project at some point. But before that I want to get a good
> understanding of the source code. I was going through the basic data
> structures, and I'm trying to understand the *new_directive *factory. In
> beancount.core some classes (e.g. Posting) are created via a
> *NamedTuple()*, while others (e.g. Transaction) are created via
> *new_directive()*. *new_directive()* itself is a thin wrapper around
> *NamedTuple()* anyway.
>
> So I would like to know what is the rationale for using one over the
> other, or for new_directive() existence in general?
>

It's just a convenience function that avoids having to repeat the common
attributes "meta" and "date".
It also makes it clear all directives are guaranteed to have those
attributes.

(I tend to use functional programming principles in my programming and
Beancount's source code is an example of that; I don't believe that
"functional" is an attribute of the language one uses - though certainly
some languages offers more support than others to craft functional programs
- but rather that it is an attribute of the patterns of data mutation one
utilizes (or avoids).)

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/CAK21%2BhNp1gQpv_TRpC9mNh_QaCS2-%3Dcgb%3DXPYMqGOQpXhHZ0ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to