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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Fl4m3Ph03n1x" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Fl4m3Ph03n1x/120/11709_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Fl4m3Ph03n1x
                    <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">
								<aside class="quote group-Phoenix-Core-Team" data-username="lance" data-post="8" data-topic="21702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/l/7ab992/48.png" class="avatar"> lance:</div>
<blockquote>
<p>It seems that the ultimate question you’re asking is, “Is it ok to represent a domain entity as a GenServer?” (Please let me know if I’m mischaracterizing that.)</p>
</blockquote>
</aside>
<p>That is precisely the question <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p>
<aside class="quote group-Phoenix-Core-Team" data-username="lance" data-post="8" data-topic="21702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/l/7ab992/48.png" class="avatar"> lance:</div>
<blockquote>
<p>When we build a GenServer, what are we really doing? We’re defining callback functions that will work in a separate process. That’s it. OTP provides for the common wiring and plumbing to make that happen.</p>
<p>We’re still working with modules, functions, and data. The difference is that they are designed to run in a separate process (or processes).</p>
</blockquote>
</aside>
<p>I understand this point. However I still have the following question:</p>
<ul>
<li>Given that the core should be functional, should we care about processes at all? Isn’t a process a runtime requirement that is independent from the functional requirements (the core of the application)?</li>
</ul>
<p>I ask this, because when I used to work with Java (yes yes, I can hear you mocking me, that’s fine :P) we used to focus our application in the functional requirements, and only then if needed, we added threads for concurrency. I understand Java threads are a poor comparison to erlang processes but the idea I am trying to take out of here is how to organize workflow and to separate runtime concerns from other concerns.</p>
<p>I am not saying I don’t agree that we need a process. I think this is a sound solution that makes a whole lot of sense (and now that Supervisor follow, it makes even more sense) I am just asking if when you build application cores and, you already think about processes.</p>
<p>Perhaps this image helps explain my doubts:</p>
<p></p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.elixirforum.com/uploads/default/original/2X/0/0a2e512d8133e815a4f20d567c81a6ef84276990.png" data-download-href="https://forum.elixirforum.com/uploads/default/0a2e512d8133e815a4f20d567c81a6ef84276990" title="" rel="nofollow"><img src="https://forum.elixirforum.com/uploads/default/original/2X/0/0a2e512d8133e815a4f20d567c81a6ef84276990.png" alt="" role="presentation" width="474" height="475"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename"></span><span class="informations">474×475 14.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><p></p>
<p>So, I have the idea that Island, Guesses, Board, Coordinate, Rules and Game all belong to the core layer. OTP would be the layer on top, the Domain one, where we add processes, supervisors and support for fault tolerance / concurrency.</p>
<p>Perhaps I am miss-interpreting the lessons in the book, perhaps this onion model doesn’t really fit (perhaps both), but I am struggling to understand where each piece fits. This struggle is where my questions come from <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p>
<p><a class="mention" href="/u/peerreynders" rel="nofollow">@peerreynders</a> He he, yeah, I would personally separate them. But now I am keen on knowing the disadvantages of coupling to OTP behvaiours (topic for another discussion).</p>
<p>Thanks for the code though, that is exactly the module I was referring to !</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="124684" 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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-124684" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="124684"
                     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="124697" data-post-id="124697">
  <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="Fl4m3Ph03n1x" data-post="12" data-topic="21702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/48/11709_2.png" class="avatar"> Fl4m3Ph03n1x:</div>
<blockquote>
<p>we added threads for concurrency.</p>
</blockquote>
</aside>
<p>Usually to satisfy some non-functional requirements. And when threads are introduced the structuring of the logic is impacted, sometimes severely.</p>
<p>In the end OTP is simply a standard library containing “formalizations of common patterns” of using the underlying virtual machine - it’s not some external system.</p>
<p>The other difference is that with threads you focus on flow of control while with processes you focus on the flow of messages (data). That will fundamentally impact how you structure your logic.</p>
<p>With the BEAM processes exist inside the core and domain of the onion diagram, just like in Java the threads package wouldn’t be pushed into the API layer (unlike lets say java.sql which is only used to communicate with an external system, a database).</p>
<blockquote>
<p>Given that the core should be functional</p>
</blockquote>
<p>Where is this coming from?</p>
<p>With the BEAM there is sequential programming and concurrent programming. Sequential programming is functional programming and happens strictly inside a process. Concurrent programming is about communicating processes.</p>
<p>The whole point of the BEAM is that you use both styles in concert.</p>
<hr>
<p>Let’s turn this around. What in your view disqualifies a process from being an entity?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="124697" 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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-124697" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="124697"
                     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="124709" data-post-id="124709">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Fl4m3Ph03n1x" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Fl4m3Ph03n1x/120/11709_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Fl4m3Ph03n1x
                    <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">
								<aside class="quote no-group" data-username="peerreynders" data-post="13" data-topic="21702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/48/5826_2.png" class="avatar"> peerreynders:</div>
<blockquote>
<p>Let’s turn this around. What in your view disqualifies a process from being an entity?</p>
</blockquote>
</aside>
<p>The fact that it mixes runtime concerns with functional concerns. So, how would you classify the structure of the Islands project in the book? Where would you put Island, Rules (state machine) Guesses, Board and the Game entity?</p>
<p>All together in the core? All together in the Domain? Separated (if so how?)<br>
Perhaps you would use another Onion Diagram instead of the one I proposed?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="124709" 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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-124709" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="124709"
                     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 #13"></div>
  </section>
</div>
    <div class="postbit" id="124713" data-post-id="124713">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rvirding" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rvirding/120/1409_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rvirding
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Erlang</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Fl4m3Ph03n1x" data-post="3" data-topic="21702" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/48/11709_2.png" class="avatar"> Fl4m3Ph03n1x:</div>
<blockquote>
<p>Would you find this code easy to port to erlang or another language?</p>
</blockquote>
</aside>
<p>Porting to Erlang is easy as Elixir more or less runs on top of Erlang and all the system building concepts like OTP come from Erlang.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="124713" 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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-124713" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="124713"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="124720" data-post-id="124720">
  <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="Fl4m3Ph03n1x" data-post="14" data-topic="21702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/48/11709_2.png" class="avatar"> Fl4m3Ph03n1x:</div>
<blockquote>
<p>The fact that it mixes runtime concerns with functional concerns.</p>
</blockquote>
</aside>
<p>When a method is used to access or mutate a class instance it does so under the flow of control of a thread <em>implicitly</em>. It’s only after you decide that you need distinct flows of control i.e. multiple threads that they become <em>explicit</em>.</p>
<p>Process oriented design addresses these type of runtime concerns deliberately at design-time by always making them explicit.</p>
<blockquote>
<p>Where would you put Island, Rules (state machine) Guesses, Board and the Game entity?</p>
</blockquote>
<p>The domain. But you have to accept the fact that “entities” can manifest in different forms. In Java it may be a single class instance or an aggregation of instances. On the BEAM an entity could simply be represented as a data structure, a process, or multiple collaborating processes. As the earlier code has shown, you can view a process as an aggregate of its state and the process shell.</p>
<blockquote>
<p>All together in the core? All together in the Domain?</p>
</blockquote>
<p>The relationship between the Domain and the Core is muddy at best.</p>
<ul>
<li><a href="https://jeffreypalermo.com/2008/07/the-onion-architecture-part-1/" rel="noopener nofollow ugc">here</a> the application core cuts across domain model, domain services, and application service.</li>
<li><a href="https://declara.com/content/va7eLmgJ" rel="noopener nofollow ugc">here</a> Application + Domain are lumped together.</li>
</ul>
<p>So the nature of the boundary between Core and Domain isn’t exactly clear. The Core at times comes across as some kind of standard library of non-domain specific building blocks. So are we talking about arrays, lists, maps, etc? <img src="https://forum.elixirforum.com/images/emoji/apple/man_shrugging.png?v=15" title=":man_shrugging:" class="emoji" alt=":man_shrugging:" loading="lazy" width="20" height="20"></p>
<p>Then on the BEAM processes are in the core, as is OTP.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="124720" 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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-124720" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="124720"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="124750" data-post-id="124750">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lance" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lance
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Functional Web Development with Elixir, OTP, and Phoenix</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>My first impression here is that I’m wary of trying to apply ideas from other ecosystems wholesale onto the BEAM ecosystem. When I was new to Elixir, I did it, and I know it did not help me.</p>
<p>Part of the idea of the book is to explore what’s possible in this new world. There are things that we can do on the BEAM that you would be hard pressed to do in other languages/ecosystems. Trying to apply rules/approaches/schemes from those other ecosystems onto this one seems unhelpful.</p>
<p>My strong preference would be to look at what we’re doing in the book and judge it on it’s own merits rather than comparing it to other systems or trying to fit it into a paradigm from another ecosystem.</p>
<p>That’s me trying to say, let’s please leave Java at the door. :^)</p>
<p>I’m also reminded of that old joke about the best answers to software questions always beginning with, “It depends.”</p>
<p>To me, questions like the one we’re looking at come into the realm of design decisions based on the constraints of the individual project. As we have no doubt seen, the only constant in software work is change.</p>
<p>The most important thing, then, is to design things with flexibility in mind. The individual choices we make are important, but the ability to easily change what we’ve done seems to me to be even more important.</p>
<p>Early in the book, we talk about having the ability to run thousands and thousands of games on the same node. I take that a constraint on the system. We need to solve for that in the design.</p>
<p>You’ve agreed that when we build a GenServer, we’re really defining a module and functions that work on some data. The change is that we decided that those functions should all run in a separate process (or processes).</p>
<p>To me, that says that we’re still working with the same things we were working with when we defined <code>Board</code>, <code>Island</code>, <code>Guesses</code>, and <code>Coordinate</code>, but by making this piece a GenServer, we satisfy the need for many games on the same node.</p>
<p>By using GenServer, we just did the two things at once - define the entity with a module, some functions, and some data as well as allow us to run it in multiple processes.</p>
<p>Here’s where your personal choice comes in. If this makes you feel uncomfortable, you can absolutely use the code for an intermediary module that <a class="mention" href="/u/peerreynders" rel="nofollow">@peerreynders</a> wrote up. All will be well.</p>
<p>To me, the key point is that the design we have in the book makes that refactor a straight forward affair. You could do it wholesale. You could do it one api function/callback at a time.</p>
<p>It’s your choice. You can do it in response to changing requirements. You can manage the transition safely.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="124750" data-batch-url="/posts/batch_likers">
                        8
                      </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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-124750" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="124750"
                     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 #16"></div>
  </section>
</div>
    <div class="postbit" id="125344" data-post-id="125344">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Fl4m3Ph03n1x" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Fl4m3Ph03n1x/120/11709_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Fl4m3Ph03n1x
                    <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>After reading everyone’s replies, I must say I am confused.</p>
<p>I understand we ought to leave Java at the door - I find that perfectly reasonable and I agree (after all, Elixir/Erlang has a different kind of OO than Java because they were more influenced by SmallTalk and their first version/prototype was done in Prolog iirc).</p>
<p>But at the same time, I find it very hard to understand, that a decade of architectural design patterns should just be thrown out of the window because Elixir is <em>new</em>. I mean, surely there are some concepts, some links we can make from the most common layered architectural design patterns right? Sure, maybe the onion one is a terrible pattern to apply in Elixir, perhaps the hexagonal one is way better because it only has 3 zones (application, DMZ where the adapters are and the OHW, aka, outside horrible world) but we should still have some sort of resemblance going on.</p>
<p>I say this, mainly because I am with Pragmatic Dave when he says “Building applications in INSERT_TECHNOLOGY_X_HERE doesn’t change how good applications are built because the basic good core tenets of architecture are the same no matter which technology you use”.</p>
<p>I am not saying the book example is lacking a good architecture. I am just saying I am personally having trouble comparing the tenets of well known architectural patterns to the example and connecting the dots.</p>
<p>This is not a problem with the book, this is a problem with me, I am very well aware of that - I am quite obsessed with design and architecture and the main reason I want to <em>get it right</em> in Elixir is because I have been through years and years of suffering from bad design choices made by others and I have grown honestly rather tired.  I am just trying to keep that cycle from repeating itself and I know that starts with me, but first I need to understand where all the pieces fit together.</p>
<p>In your opinions, is there any architectural pattern that somehow resembles what the example in the book follows? Is this is a new approach that is seen in most Elixir applications and that I missed because I am still learning Elixir?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="125344" data-batch-url="/posts/batch_likers">
                        1
                      </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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-125344" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="125344"
                     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 #17"></div>
  </section>
</div>
    <div class="postbit" id="125358" data-post-id="125358">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I guess <em>I’m</em> confused what you mean when you say the “entity” layer. In the context of the book, the games are built as data structure. They take in new data and provide a new data structure back to you. In order to take these data structures and make them into a useful <em>game</em> we put the data structure in a process and allow the process to manage the lifecycle of that game. I’m really not sure where the hangup is I guess.</p>
<p>As to throwing things out, I don’t think anyone is throwing out any established architectural patterns here. The book provides an alternative to all of the patterns you mentioned. At least I think it does. Out of all the patterns you’ve mentioned the only I’d ever heard of was “hexagonal” (a pattern that I’m not a fan of tbh). I don’t know what “onion” or “lasagna” architectures are but I guess they involve layers?</p>
<p>Either way I don’t think that you should take the book as the end all be all to design. If you want to just put stuff in a database that’s quite alright and that concept will generally scale well and lead to less stateful designs. But if you need to bring state into your system then the book shows you a way to layer together a functional interface with stateful processes.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="125358" data-batch-url="/posts/batch_likers">
                        5
                      </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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-125358" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="125358"
                     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 #18"></div>
  </section>
</div>
    <div class="postbit" id="125381" data-post-id="125381">
  <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">
								<p>Is there a “shortage” of Erlang/Elixir patterns? Maybe, maybe not:</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="http://erlang.org/pipermail/erlang-questions/2007-October/030091.html">
  <header class="source">

      <a href="http://erlang.org/pipermail/erlang-questions/2007-October/030091.html" target="_blank" rel="noopener nofollow">erlang.org</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="http://erlang.org/pipermail/erlang-questions/2007-October/030091.html" target="_blank" rel="noopener nofollow">[erlang-questions] Design methodology going from Object oriented...</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Garrett Smith attempted an <a href="https://github.com/gar1t/erlang-patterns/tree/master/patterns" rel="noopener nofollow ugc">Erlang specific repository</a> but contributions stalled.</p>
<p>And even if a prescriptive pattern was followed - it could still be <em>wrong</em> if it is applied in the wrong context (this is a real problem in OOP with respect to design patterns).</p>
<p>Ultimately <code>Game</code> is just a process manipulating some data structures (<code>Board</code>, <code>Coordinate</code>, <code>Guesses</code>, <code>Island</code>, <code>Rules</code>) - and <code>Game</code> itself is going to be part of a supervision tree which itself is part of an OTP application.</p>
<p>For a discussion on how to structure supervision trees: <a href="https://ferd.ca/the-hitchhiker-s-guide-to-the-unexpected.html" rel="noopener nofollow ugc">The Hitchhiker’s Guide to the Unexpected</a><br>
Data structure vs Process: <a href="https://www.theerlangelist.com/article/spawn_or_not" rel="noopener nofollow ugc">To spawn, or not to spawn?</a><br>
<a href="http://www.duomark.com/erlang/publications/acm2004.pdf" rel="noopener nofollow ugc">Structured Programming Using Processes (2004)</a></p>
<blockquote>
<p>Building applications in INSERT_TECHNOLOGY_X_HERE doesn’t change how good applications are built</p>
</blockquote>
<p>Yes, but going from Java to C# isn’t changing the paradigm so the solution shape isn’t impacted. But going to Erlang/Elixir you are shifting paradigms into “Concurrency Oriented Programming” which means that processes and most of OTP becomes part of the <em>Core</em> rather than being a</p>
<aside class="quote no-group" data-username="Fl4m3Ph03n1x" data-post="1" data-topic="21702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/48/11709_2.png" class="avatar"> Fl4m3Ph03n1x:</div>
<blockquote>
<p>third party concept</p>
</blockquote>
</aside>
<p>What seems to currently be challenging you the most is that a process can be an entity.</p>
<aside class="quote no-group" data-username="Fl4m3Ph03n1x" data-post="18" data-topic="21702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/48/11709_2.png" class="avatar"> Fl4m3Ph03n1x:</div>
<blockquote>
<p>Sure, maybe the onion one is a terrible pattern to apply in Elixir</p>
</blockquote>
</aside>
<p>I’ve commented on the <a href="https://forum.elixirforum.com/t/discussion-onion-architecture/6164/8" rel="nofollow">onion architecture before</a> and in my view the most insightful aspect was that the <em>domain</em> layer gets to dictate the contracts while the infrastructure has to implement those contracts (e.g. nothing in the data store is influencing what is going on in the domain).</p>
<p>That particular advice still applies to Elixir - if that is the type of system that is being built.</p>
<p>Most of these architectures boil down to examining the structure and characteristics of a system along certain dimensions:</p>
<ul>
<li>Boundaries
<ul>
<li>at all levels of granularity (types, user defined types (modules), processes, supervision trees, applications, systems)</li>
<li>physical vs logical boundaries</li>
<li>(high) cohesion of logic within any one boundary</li>
<li>(low) coupling between boundaries
<ul>
<li>dependencies from within the boundary</li>
<li>dependencies on the boundary</li>
<li>i.e. good inter-boundary contracts (hiding implementation details, correct (specification → implementation) direction, etc.)</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>Alongs those lines what are the problems that you see with the design of <code>Game</code>?</p>
<p>Now there are some <a href="https://forum.elixirforum.com/t/mox-and-protocols/15277/12" rel="nofollow">games you can play</a> to hide whether or not something is a data structure or a process. But processes that are part of a supervision tree are <em>known</em> to be processes - otherwise they couldn’t be part of the tree.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="125381" data-batch-url="/posts/batch_likers">
                        6
                      </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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-125381" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="125381"
                     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 #19"></div>
  </section>
</div>
    <div class="postbit" id="125426" data-post-id="125426">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lance" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lance
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Functional Web Development with Elixir, OTP, and Phoenix</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>First, I want to echo what <a class="mention" href="/u/keathley" rel="nofollow">@keathley</a>  and <a class="mention" href="/u/peerreynders" rel="nofollow">@peerreynders</a>  had to say. They covered a lot of good ground pretty thoroughly, so I’m going to take another direction in trying to answer your question.</p>
<p>I’d like to start by making a distinction between design patterns and design principles.</p>
<p>The Gang of Four book is probably the most famous source of design patterns, but the architectural patterns you mentioned - hexagonal and onion - are as well. My sense of design patterns is that they’re fairly strict. There are rules to follow. There are definitions and technical terms to learn.</p>
<p>Design principles are more loose and general. These are often just phrases like “build in layers”, “minimize complexity”, “name things expressively”, and so on.</p>
<p>Design principles most often use common terms with their everyday meanings. They tend not to emphasize hard and fast rules, but this doesn’t make them any less useful. In fact, their flexibility makes them applicable in a broader range of cases.</p>
<p>That flexibility gives the developer a lot of discretion, but it requires the developer to exercise more of their own judgement as well.</p>
<p>Here’s where this applies to the concern you raised that we might be throwing hard won knowledge out the window.</p>
<p>When folks started to write Gang of Four style books for other languages (GoF was originally written for C++ iirc), they needed to change and adapt the patterns. Sometimes they needed to make considerable changes. Sometimes they needed to throw patterns away completely because they didn’t make any sense in the new target language. (I’m thinking of the Ruby one especially.)</p>
<p>This reinforces the idea that patterns aren’t very flexible. It’s really hard to apply them across languages. It’s way harder to apply them across the OOP/FP border.</p>
<p>Principles are much more likely to make that trip successfully. My suspicion is that in the line you quoted from Dave Thomas, he’s talking about something closer to principles than patterns. (But that’s only my suspicion, and I don’t want to put words in Dave’s mouth.)</p>
<p>Also in this respect, Elixir isn’t really new, as you say. Elixir semantics are very close to Erlang’s, and Erlang has been around for decades. Elixir and Erlang are just <em>different</em> from most other paradigms. So this idea that we can readily apply patterns, not principles, from OOP seems really unlikely to me.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="125426" data-batch-url="/posts/batch_likers">
                        4
                      </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/functional-web-development-with-elixir-otp-is-otp-part-of-the-entity-layer/21702/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-125426" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="125426"
                     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 #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/21702/load_more?page=3">Load more posts (9 remaining)</a>
</div></template></turbo-stream>