<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="38684" data-post-id="38684">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Woody88" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Woody88
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>[quote=“peerreynders, post:8, topic:6342, full:true”]</p>
<aside class="quote no-group quote-modified" data-username="Woody88" data-post="1" data-topic="6342">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/w/977dab/48.png" class="avatar"> Woody88:</div>
<blockquote>
<p><a href="http://theerlangelist.com/article/spawn_or_not" rel="noopener nofollow ugc">To spawn, or not to spawn?</a> is quite specific:</p>
<ul>
<li>Use functions and modules to separate thought concerns.</li>
<li>Use processes to separate runtime concerns.</li>
<li>Do not use processes (not even agents) to separate thought concerns.</li>
</ul>
<p>Now initially I would have been tempted to use “design concerns” instead of “thought concerns” - but that would have been a grave mistake because in Erlang/Elixir “runtime concerns” <strong>are</strong> also “design concerns” - less so because of performance but moreso because of fault-tolerance. So my interpretation of “thought concerns” is the typical compartmentalization of functionality that we engage in to make things “easier to reason about” while simultaneously structuring the application to align itself with the user’s domain. So deck, hand, round align with the domain concepts while round_server and notifier are primarily concerned with orchestrating how the rounds unfold over time.</p>
</blockquote>
</aside>
<p>First I would like to say thank you for taking the time to write everything that you wrote , that also includes everyone else. I wanted to reply to multiple people with this single reply but not sure how…</p>
<p>Now in regards to the principle of separating thought concerns I think that I get the the picture, but where I kind of get lost is when you need to interact with a database or an entity that holds your state for example processes, ets, mnesia, etc..  Usually one would tend to write their module based on their data storage format. For example a User module would probably be defined as struct so you could give it the id, name, and other attributes. But with the approach of the <a class="mention" href="/u/sasajuric" rel="nofollow">@sasajuric</a> and from reading everyone else reply - it seems like the the system itself and whatever data storage you use(even memory) would be a complete different entity, if I may say a complete different system that would interact with your main system. I’m I wrong ?</p>
<p>So in other words one would have to create a separate client that would handle retrieving data in the storage and transform it in the format the main system module requires it to be in to be able to continue processing the data.</p>
<p>So the picture that I have is for example: System &lt;— Client ----&gt; Data storage .<br>
(I’m very visual so pictures, some kind of representation or code are very helpful.)</p>
<p>The reason why I am mentioning data storage is because I still feel uneasy with the part that in fp you don’t have some kind of object/class to hold your state. On contrary in fp one would use a function that would either have the whole state as an argument or some separate module such as a process that would hold the state.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="38684" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/process-and-stateness-are-they-object/6342/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-38684" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="38684"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="38692" data-post-id="38692">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Woody88" data-post="12" data-topic="6342">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/w/977dab/48.png" class="avatar"> Woody88:</div>
<blockquote>
<p>But with the approach of the <a class="mention" href="/u/sasajuric" rel="nofollow">@sasajuric</a> and from reading everyone else reply - it seems like the the system itself and whatever data storage you use(even memory) would be a complete different entity, if I may say a complete different system that would interact with your main system. I’m I wrong ?</p>
</blockquote>
</aside>
<p>This is why in DDD there is the concept of a <a href="http://dddcommunity.org/resources/ddd_terms/" rel="noopener nofollow ugc">repository</a>:</p>
<blockquote>
<p><strong>Repository:</strong> A mechanism for encapsulating storage, retrieval, and search behavior which emulates a collection of objects.</p>
</blockquote>
<p>So while everybody is talking about Ecto’s “repo” - in the DDD sense that <strong>is not</strong> your application’s <em>repository</em> because Ecto’s repo is leaking all sorts of implementation details about the storage technology (RDBMS and schema details) that are irrelevant to the application’s domain. The application repository would have to wrap Ecto’s repo and “talk” to the rest of the application only in terms of the domain’s types.</p>
<p>Now for smaller projects this effort may not be worth it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="38692" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/process-and-stateness-are-they-object/6342/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-38692" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="38692"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="38694" data-post-id="38694">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="aseigo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/aseigo/120/10674_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  aseigo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Woody88" data-post="12" data-topic="6342">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/w/977dab/48.png" class="avatar"> Woody88:</div>
<blockquote>
<p>On contrary in fp one would use a function that would either have the whole state as an argument or some separate module such as a process that would hold the state.</p>
</blockquote>
</aside>
<p>At the end of the day, those are actually the same things with Elixir. In the process there is always a function that is currently executing (possibly waiting on a message ..), and the state is indeed handed from one function to the next in a state-holding process.</p>
<p>The reason the state is not visible from the “outside” is that the state is held in a function waiting on messages to arrive … when a message arrives (without the state, of course), the receiving function now has the “next thing to do” from the message and the state that it received when it started.</p>
<p>This is why GenServer callbacks (for instance) all take and return a state parameter! So processes are a nice way to wrap those functions-bearing-state in an easy to use package.</p>
<p>So now this:</p>
<aside class="quote no-group" data-username="Woody88" data-post="12" data-topic="6342">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/w/977dab/48.png" class="avatar"> Woody88:</div>
<blockquote>
<p>when you need to interact with a database or an entity that holds your state for example processes, ets, mnesia, etc</p>
</blockquote>
</aside>
<p>SQL databases, ets and mnesia are about “durable” storage → storage that exists outside of the rest of the program and may live a different life cycle .. (ok, there are details in there i am glossing over, but let’s roll with that simplification for now).</p>
<p>Data in processes are just parameters in functions (representing state) that are waiting to be used when a message is received.</p>
<aside class="quote no-group" data-username="Woody88" data-post="12" data-topic="6342">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/w/977dab/48.png" class="avatar"> Woody88:</div>
<blockquote>
<p>it seems like the the system itself and whatever data storage you use(even memory) would be a complete different entity, if I may say a complete different system that would interact with your main system.</p>
</blockquote>
</aside>
<p>Yes, they are separate entities .. but you can view them all as being “things we wrap in functions”. So for a SQL database we write Ecto queries (or maybe go straight to postgrex if we’re feeling like that <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> ) inside of functions and write other functions that know how to manipulate those queries and their results (perhaps with structs). Those functions create the surface with which you call out into these “separate systems”, and when using those functions your program can generally ignore the “detail” that they are separate from your program.</p>
<p>I think I may understand where you feel the flow is dropping out from under your feet: with OO there is this make-believe world of data being managed in very solid things (called “objects” even!), but it’s really just functions wrapped behind functions with syntactic sugar that keeps the data&lt;-&gt;functions association for you (in that sense, Elixir processes are analogous to objects); with structural languages like C, there are globals and the endless passing of pointers .. but that also is just data being handled by functions.</p>
<p>There is no extra magic, or lack thereof, in functional programming in that regard. It just doesn’t try to hide the fact that data and functions are loosely coupled, if at all .. it goes so far as to tell us that functions are also just data, which is obvious when you think about the fact that they are just bits in memory that the computer reads through to know what instructions to execute .. bits are bits, right?</p>
<p>When I came to functional programming, I also felt a bit of vertigo over where was my data going to find its way through the program … all the facades I was used to relying on as mental abstractions for the reality were gone. But then you learn not to worry about it .. it’s just data, some of which are executable functions <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>.. and that’s true in EVERY language .. they just have different ways of exposing it, and different rules for interacting with the data that is your program.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="38694" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/process-and-stateness-are-they-object/6342/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-38694" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="38694"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>