title: Best practices for data management in Prolog
body: <p>I'm just getting involved in using Prolog to handle more than just the simplest forms of data (facts) and am looking for some guidance from the seasoned Prologers...</p>
  
  <p>If I want to dynamically manage data or facts, I have a couple of major choices, such as do I:</p>
  
  <ul>
  <li>Manage the data as assertions in Prolog, OR</li>
  <li>Interface to a database from Prolog, OR</li>
  <li>Possibly a combination of both</li>
  </ul>
  
  <p>If I manage facts as assertions in Prolog, I also have the question of the best way to represent those facts. Let's suppose I have a <code>person</code> who has a first name, last name, and an age. I can assert it as:</p>
  
  <pre><code>person(first_name(_), last_name(_), age(_)).
  </code></pre>
  
  <p>Or have an implicit assumption of what the attributes of person are:</p>
  
  <pre><code>person(_, _, _).  % first name, last name, age
  </code></pre>
  
  <p>If I want to associate a person with something else, I really need a key for a person. So I might be inclined to assert a person as:</p>
  
  <pre><code>person(id(_), ...).  % Maintain id as a uniq person key; or done implicitly as above
  </code></pre>
  
  <p>Of course, now I'm making my Prolog assertions look like relational database table entries. And it makes me wonder if I'm taking the wrong approach and overly complicating the representation of facts.</p>
  
  <p>So really, my question is: Are there some best practices to consider when managing medium to complex data in Prolog? The naming convention is the small side of it. I've read bits like the assert/retract in Prolog are inefficient. So I'm also wondering about how to approach the data organization itself, like when to resort to an external SQL database versus Prolog-only representation.</p>
  
  <p><strong>ADDENDUM</strong></p>
  
  <p>I would assume that use of a key for records, as is done in a relational database, would be desirable for the very reasons a relational database uses them. Which means that the key must be maintained. It seems cumbersome to do this manually (explicitly) in Prolog for each case, so how is this done generally? Or is my assumption in correct?</p>