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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>As a guy why was on both sides of the fence, I can’t differentiate between dependency injection in Java and mocking in Elixir.</p>
<p>Yes, the way it’s done is mechanically different but the achieved result is the same.</p>
<hr>
<p>I’m not certain what exactly is <a class="mention" href="/u/seanshubin" rel="nofollow">@SeanShubin</a> trying to encourage us to think about, having in mind that both imperative / OOP and FP languages have very good tools to tackle the problem of side effects and misbehaving 3rd party libraries. Even though I’ve carefully read his long comment above, my only impression is that he wants to change the meaning of words that are already well-established. <img src="https://forum.elixirforum.com/images/emoji/apple/person_shrugging.png?v=15" title=":person_shrugging:" class="emoji" alt=":person_shrugging:" loading="lazy" width="20" height="20"></p>
<p>And yep, <code>Mox</code> or <code>Patch</code> will do the job. <code>Mock</code> too, I’ve used that successfully as well.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="283074" 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/how-do-i-test-things-like-io-file-and-system/54817/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-283074" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="283074"
                     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="283089" data-post-id="283089">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="SeanShubin" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/SeanShubin/120/30038_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  SeanShubin
                    <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="dimitarvp" data-post="12" data-topic="54817">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/48/38664_2.png" class="avatar"> dimitarvp:</div>
<blockquote>
<p>my only impression is that he wants to change the meaning of words that are already well-established</p>
</blockquote>
</aside>
<p>It is not my intention at all to change the meaning of well established words.  I am encouraging people to think about the meaning of the words they use, and use them with intention and precision.  The meaning of the word “function” is very well established with a precise mathematical definition.  The solution I demonstrated was a functional approach according to this already well established definition created a long time ago by many people who had a lot more collective time to think about it than I ever could.</p>
<p>What I see is a lot of is people thinking they are doing “functional” programming, while at the same time getting inputs from a global namespace rather than getting those inputs from the parameters to their function, or thinking I am not doing functional programming because I have some locally scoped mutable state or an imperative style, while definitionally it is still a function because the same inputs always get the same outputs with no observable side effects.</p>
<p>I can’t control your impressions of what I am saying, I can only attempt to be as clear as I possibly can be.  I just want to make sure observers of this thread are aware that the particular impression of me wanting to redefine well established terms is a construct of your own mind that has nothing to do with what I was trying to say.  I never said or implied that.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="283089" 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/how-do-i-test-things-like-io-file-and-system/54817/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-283089" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="283089"
                     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="283091" data-post-id="283091">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="SeanShubin" data-post="13" data-topic="54817">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/seanshubin/48/30038_2.png" class="avatar"> SeanShubin:</div>
<blockquote>
<p>The meaning of the word “function” is very well established with a precise mathematical definition.</p>
</blockquote>
</aside>
<p>Sure. We can’t have 100% pure code without side effects however.</p>
<p>Maybe my mind is not on the same frequency as yours – I am just not sure what you are after in practical terms.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="283091" 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/how-do-i-test-things-like-io-file-and-system/54817/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-283091" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="283091"
                     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="283100" data-post-id="283100">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="SeanShubin" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/SeanShubin/120/30038_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  SeanShubin
                    <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>My aspirational goal is to get 100% of my Elixir code tested with unit tests alone.  Code not run by the Erlang runtime system, such as SQL database queries, while certainly side effecting, is not Elixir code so I am fine with using integration tests for those as long as all of the Elixir code used to transmit the SQL to the database is unit tested.</p>
<p>In this sense, I believe my sample using dependency inversion <strong>did</strong> achieve 100% pure code with no side effects for every single bit of my Elixir logic, in a way that can be generalized to <strong>any</strong> kind of side effects.  The only class that did not have test coverage was the class that configured which production implementations to use, which is fine by me because that configuration contains no application behavior, just direct pass throughs to the underlying implementations.  It is so simple it it could be generated.  All of the application behavior is easy to stub out for unit tests, no need for integration tests for Elixir code and no need to skip test coverage on anything.</p>
<p>That said, I am also willing to be pragmatic about my aspirational goal, and am willing to pull back on it in cases where there is good reason and a decent alternative.  I don’t want to be writing Elixir code in a style completely alien to the rest of the Elixir community just for the sake of principle.</p>
<p>I am also willing to explore alternative suggestions that can get me close to my aspirational goal through means I might not be able to think of on my own due to my inexperience with Elixir.  This is why I am grateful for the suggestions to look into Mox, Ecto, and jjh42/mock.  I might have missed these on my own.  Once I have had a chance to review all of the solutions, I feel like I can make an informed decision regarding what tradeoffs between functional purity and pragmatism are sensible.  I don’t want to presume I have to make a tradeoff, I want to make sure any tradeoffs I make are for well understood and good reasons.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="283100" 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/how-do-i-test-things-like-io-file-and-system/54817/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-283100" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="283100"
                     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="283106" data-post-id="283106">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hello <a class="mention" href="/u/seanshubin" rel="nofollow">@SeanShubin</a> and welcome.</p>
<aside class="quote no-group" data-username="SeanShubin" data-post="7" data-topic="54817">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/seanshubin/48/30038_2.png" class="avatar"> SeanShubin:</div>
<blockquote>
<p>My intent is to encourage people to think more precisely about what they mean by “functional” and especially about what are the real reasons why we think we need an integration test instead of a unit test.</p>
</blockquote>
</aside>
<p>Your target audience is a bit unclear here.  Your writing style is attracting responses from seasoned Elixir developers and seasoned Elixir developers are well aware they are not working in a purely functional language.  Erlang was developed to solve a practical problem and its functional properties emerged as a consequence of that.  It’s never been academic.  Elixir developers generally favour pure functions for the most part and push all side-effects to a particular boundary which isn’t necessarily the top boundary (depending on how you think about your system).</p>
<aside class="quote no-group" data-username="SeanShubin" data-post="15" data-topic="54817">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/seanshubin/48/30038_2.png" class="avatar"> SeanShubin:</div>
<blockquote>
<p>I don’t want to be writing Elixir code in a style completely alien to the rest of the Elixir community just for the sake of principle.</p>
</blockquote>
</aside>
<p>I’d say go for it if you want.  You will generally find people around here encouraging others to code however they see fit.  If you look through some prominent open source Elixir projects there are all sorts of different styles.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="283106" 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/how-do-i-test-things-like-io-file-and-system/54817/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-283106" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="283106"
                     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="283112" data-post-id="283112">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="SeanShubin" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/SeanShubin/120/30038_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  SeanShubin
                    <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="sodapopcan" data-post="16" data-topic="54817">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sodapopcan/48/34668_2.png" class="avatar"> sodapopcan:</div>
<blockquote>
<p>Your target audience is a bit unclear here. Your writing style is attracting responses from seasoned Elixir developers and seasoned Elixir developers are well aware they are not working in a purely functional language.</p>
</blockquote>
</aside>
<p>I think that is a consequence of me being new to Elixir while at the same time having such ambitious goals regarding testability.  When I start coding in a programming language that is new to me, I want to get certain foundations nailed down first.</p>
<p>I have found the ability to write code in a pure functional style has very little to do with the language.  I can write any program in a language such as Java in 100% pure functional style and Java is not even trying to be a functional programming language.  I have also seen code in Haskell, a pure functional programming language, where the side-effecting IO Monad has so permeated the entire code base that I can’t even comprehend what it means to call that code functional.</p>
<p>The reason why I am so focused on precision regarding what it means to be functional, is that I am trying to parse out the justification for when to take a functional vs non-functional approach.  Sometimes it is because of language limitations that ruin the aesthetics of certain styles, sometimes it is the way people are used to coding, sometimes there are well established conventions, and I guess that comment was a challenge to see if the only reason the functional approach was not chosen in a particular case is because it doesn’t occur to people that it is even possible.  If you tell me I can’t have pure functional, or maybe it doesn’t make sense to strive for pure functional, that may very well be true, I just want to know why.</p>
<p>I am not seeking any more clarification right now though, I got enough suggestions to keep me busy.  I am glad you let me know about the history of Elixir being practical and becoming functional as a side effect, not the other way around.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="283112" 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/how-do-i-test-things-like-io-file-and-system/54817/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-283112" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="283112"
                     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>