<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Moxley Stratton on Medium]]></title>
        <description><![CDATA[Stories by Moxley Stratton on Medium]]></description>
        <link>https://medium.com/@moxicon?source=rss-6afd185ab424------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iUkn1AMzVOJOqOY5gZeIBQ.jpeg</url>
            <title>Stories by Moxley Stratton on Medium</title>
            <link>https://medium.com/@moxicon?source=rss-6afd185ab424------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:25:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@moxicon/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Elixir at GroupFlow]]></title>
            <link>https://medium.com/@moxicon/elixir-at-groupflow-b0614944c9d7?source=rss-6afd185ab424------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0614944c9d7</guid>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Moxley Stratton]]></dc:creator>
            <pubDate>Tue, 21 Jan 2025 23:03:29 GMT</pubDate>
            <atom:updated>2025-01-21T23:03:53.737Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.groupflow.app/?utm_campaign=medium&amp;utm_content=blog-article">GroupFlow</a> is my SaaS application for social clubs. It takes care of all the common online problems clubs face: publishing a website, accepting member applications online, handling member dues, sharing member profiles, marketing events, and communicating to and between members.</p><p>GroupFlow’s backend codebase is 135k lines of <a href="https://elixir-lang.org/">Elixir</a>, using the <a href="https://www.phoenixframework.org/">Phoenix Framework</a>. It uses the <a href="https://ash-hq.org/">Ash Framework</a> and its <a href="https://github.com/ash-project/ash_graphql">AshGraphql</a> extension for all major new functionality since 2023.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*YPZ0NMt2G7Tnvwe4PyETgA.png" /></figure><p>The database is <a href="https://www.postgresql.org/">PostgreSQL</a>, and the frontend codebase is <a href="https://react.dev/">React</a>, <a href="https://www.typescriptlang.org/">TypeScript</a>, and <a href="https://nextjs.org/">Next.js</a>.</p><p>If you belong to a club with more than 50 members that handles member dues or event tickets, consider giving GroupFlow a try:</p><p><a href="https://www.groupflow.app/?utm_campaign=medium&amp;utm_content=blog-article">https://www.groupflow.app/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0614944c9d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Collapsing Ecto Migrations]]></title>
            <link>https://medium.com/@moxicon/collapsing-ecto-migrations-c58a32b6a4f0?source=rss-6afd185ab424------2</link>
            <guid isPermaLink="false">https://medium.com/p/c58a32b6a4f0</guid>
            <category><![CDATA[ecto]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[phoenix]]></category>
            <dc:creator><![CDATA[Moxley Stratton]]></dc:creator>
            <pubDate>Wed, 27 Nov 2019 16:51:13 GMT</pubDate>
            <atom:updated>2022-07-28T02:49:40.796Z</atom:updated>
            <content:encoded><![CDATA[<p>A migration file that no longer provides value as a distinct migration is just dead weight. It’s a liability. When an application reaches a year or two in age, the list of database migrations in its history can grow to an impressive size. Sometimes, changes to an application will cause migrations from the past to fail. When a new developer onboards the application, they can get blocked by these bugs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pA3drNpiKgBM3-cZFQc1eA.jpeg" /></figure><p>What if there was a way to flatten all old migrations into a single database schema? There is.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6daa00619b106c72ff2f8b56b1afabfb/href">https://medium.com/media/6daa00619b106c72ff2f8b56b1afabfb/href</a></iframe><p>Here’s how to do it:</p><ol><li>Pick the most recent migration that is deployed to production. Delete all the migrations before it.</li><li>Get a schema dump of the production database, with no data. Just the schema. Save it to /priv/repo/initial_schema.sql. For PostgreSQL, that might look something like this: pg_dump my_database --schema-only --no-owner --exclude-table=schema_migrations &gt; schema.sql</li><li>Rename the latest migration file and module name. Keep the timestamp in the filename, but rename the rest to something like “_initial_schema.exs”. Similarly, rename the module.</li><li>Replace the body of the module with the module body shown above.</li><li>Remove all migration files that came prior to this migration.</li><li>Test it in the test environment: MIX_ENV=test mix do ecto.drop, ecto.create, ecto.migrate. Then mix test.</li></ol><p>The modified migration calls out to psql, and passes the same connection parameters that the application’s Repo module uses. The schema dump is imported into the database via psql. This works for PostgreSQL. If you’re using another database, replace the psql command with the command that is provided by your database.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c58a32b6a4f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Speed Up Coding With Atomic Tasks]]></title>
            <link>https://medium.com/@moxicon/speed-up-coding-with-atomic-tasks-6ed69612e424?source=rss-6afd185ab424------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ed69612e424</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Moxley Stratton]]></dc:creator>
            <pubDate>Wed, 25 Apr 2018 13:55:12 GMT</pubDate>
            <atom:updated>2018-04-25T13:55:12.169Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you want to speed up your software development? Want to code with less stress, without feeling stuck?</p><p>Maybe you’ve heard the advice, “commit often”. That is, commit your recent changes to source control often, without letting too much code change in between commits. Has that turned out to be more difficult than it sounds?</p><h3>Breaking Down The Problem</h3><p>The key reason why developers get bogged down on a problem is that they don’t think enough about breaking down the problem into individual steps. They think about the end goal, and start coding towards that goal almost immediately.</p><p>Next time you’re tasked with a problem, do start with the end goal in mind, but don’t start coding yet. Open a text editor or a note taking app and start writing a checklist. Write down the end goal first. Under that and indented one level, think of a task that needs to be completed before the end goal can be considered complete.</p><p>After you’ve written your first task, look at that task, and figure out how many areas of the codebase you’ll have to change to complete that task. We’ll call these areas “components”. How many components need to change? One? Two? Three? Four or more? If it’s more than one, consider breaking down the task into smaller tasks. If it’s more than two, definitely break it down.</p><p>For a task that is broken down so that it touches only one or two components, we call it an “atomic task”. It doesn’t get broken down any further.</p><p>Don’t worry about breaking all the tasks down to atomic tasks. Just break down the next few you can start working on. As you work on them, continually update and break down the next several tasks.</p><h3>Task Ordering</h3><p>Ordering tasks is key to making this strategy work. For example, make sure that task number one doesn’t depend on the completion of task number two. Re-order the tasks so that the earlier ones don’t depend on the later ones.</p><p>While coding, when you come across a piece of code you know needs to change later on, just add that to your task list, and put it in a reasonable order.</p><h3>The Task List</h3><p>I use the Markdown language to manage atomic tasks (I use Markdown for all kinds of things, including writing this blog post). Here’s an example of a programming problem, and some of the tasks involved:</p><pre>[ ] Implement pagination SRVC-1923<br> — [x] Move `FeatureListParams` and `FeatureListResult` to own module<br> — [x] Define `GroupsListParams` type<br> — [x] Define `FeatureListResult` type<br> — [x] Convert `fetchGroups()` to use authStore as argument<br> — [x] Convert `fetchGroups()` to use `FeatureFlagApi`<br> — [x] Integrate `FeatureListResult` with `GroupsStore`<br> — [x] Integrate `GroupsListParams` with `GroupsStore.fetchGroups()`<br> — [x] Integrate filters with `GroupsStore.fetchGroups()`<br> — [x] Eliminate `GroupsStore.fetchGroupsByName()`<br> — [x] Fix pagination fetch: not passing filters<br> — [x] Eliminate unnecessary mutations in Groups component<br> — [ ] Include request params in GroupListResult<br> — [ ] When the search query or filter changes, reset the page number to `1`<br> — [ ] DRY up multiple calls to `fetchGroups()`<br> — [ ] Use return value from `fetchGroups()` instead of using cached value.</pre><h3>Task Completion</h3><p>Upon completion of an atomic task, your project’s tests should pass. Everything should be green. Commit the task to source control. You can use the task description as your commit message.</p><p>Sometimes, I fall out of the habit of breaking down problems into atomic tasks. When that happens, I find myself slowing down, getting stuck more of the time, and making less-frequent commits. So, the next time you feel like you’re getting stuck, let that be a reminder to use atomic tasks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ed69612e424" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elixir: Best Practices For Error Values]]></title>
            <link>https://medium.com/@moxicon/elixir-best-practices-for-error-values-50dc015a06f5?source=rss-6afd185ab424------2</link>
            <guid isPermaLink="false">https://medium.com/p/50dc015a06f5</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[software-design]]></category>
            <dc:creator><![CDATA[Moxley Stratton]]></dc:creator>
            <pubDate>Wed, 25 Apr 2018 13:53:04 GMT</pubDate>
            <atom:updated>2018-04-27T23:22:47.162Z</atom:updated>
            <content:encoded><![CDATA[<p>Having read and written Elixir code over the last three years, many patterns and best practices have emerged. Today, I’ll show some good practices for error handling in Elixir.</p><h3>Ok/Error Tuples</h3><p>In Elixir, it is common for functions to return values that represent either success or error. This is in contrast to many other languages that rely on a try/catch or raise/rescue paradigm.</p><p>These return values often take the form of a tuple, where the first element of the tuple is either :ok or :error.</p><p>The :ok tuple:</p><pre>{:ok, any} = my_function()</pre><p>The :error tuple:</p><pre>{:error, error_info} = my_function()</pre><p>Handling either an :ok or an :error status:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc2e5e2a7090482baafcf8b575be72d0/href">https://medium.com/media/dc2e5e2a7090482baafcf8b575be72d0/href</a></iframe><h3>Exceptions</h3><p>As mentioned already, raised or thrown exceptions are not a common error pattern in Elixir. This is especially true for libraries, where the library should leave it up to the consumer to decide what to do with the error.</p><p>The only time raised exceptions should be used are when the error would cause the application to be in an undefined state. Much more detail about this is covered here: <a href="http://michal.muskala.eu/2017/02/10/error-handling-in-elixir-libraries.html">http://michal.muskala.eu/2017/02/10/error-handling-in-elixir-libraries.html</a></p><h3>Best Practices for the Error Tuple</h3><h3>Two-Element Tuple</h3><p>For the error tuple, it’s a good idea to stick with two elements. This keeps the shape of the error value consistent and it makes reasoning about the error paths easier throughout a codebase. An two-element tuple is much easier to pattern match on than a variable-element tuple. When calling a function, you don’t need to investigate what size error tuple is returned in order to match on it. If two elements is the standard, then always pattern match on a two-element tuple.</p><p>If a particular error has more pieces of error information, then wrap the information in another tuple:</p><p>{:error, {:http_error, 404}}</p><h3>Avoid Strings</h3><p>Coming from other languages and frameworks that want you to encode error descriptions as strings (presumably for the end user), it is tempting to also use a string for the second element of the error tuple.</p><p>For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea7d0b95e15e53e759ca6648d5923546/href">https://medium.com/media/ea7d0b95e15e53e759ca6648d5923546/href</a></iframe><p>Although humans have no problem reading strings, programs can have trouble making sense the information in the string. We shouldn’t assume that a human will always be the only entity that needs to read the error value. Strings are unstructured and aren’t great to pattern match on.</p><p>Instead of a string, consider using an atom instead. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f056336e7853e764a80d21cc10dc7567/href">https://medium.com/media/f056336e7853e764a80d21cc10dc7567/href</a></iframe><p>With an atom or other structured data type, there is little room for doubt.</p><p>If a human user needs to read the error value, it can be easily — and often automatically — converted to a string.</p><h3>Exception Structs</h3><p>Even though exceptions are not commonly raised in Elixir programs, core Elixir uses them and has great support for them, including a rich set of exception types. These types are just special structs.</p><p>Here is the documentation for the RuntimeError: <a href="https://hexdocs.pm/elixir/RuntimeError.html">https://hexdocs.pm/elixir/RuntimeError.html</a></p><p>Elixir makes it easy to create your own error structs. You don’t need to raise them. They can be returned as error values from functions. Let’s create one to represent an error returned from an API call.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a3bebd77b1382fabe0f2e6636623ec3/href">https://medium.com/media/2a3bebd77b1382fabe0f2e6636623ec3/href</a></iframe><p>In the example above, the defexception macro tells Elixir that this is an exception module. Elixir generates a message/1 function, which we are free to override. When an instance of the exception struct is passed to Exception.message/1, it delegates to the message/1 on our struct’s module.</p><p>When defexception is used, the message/1 function is automatically generated, and you can count on it being there, or you can override it with your own message/1 function.</p><p>Here is an example of using our custom error struct in an application:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2625d3529159e476a2b3d2d38f008d38/href">https://medium.com/media/2625d3529159e476a2b3d2d38f008d38/href</a></iframe><p>Notice that when error structs are used, we no longer need to return tuples for success or error from a function. Error structs can be pattern matched. On success, just the happy value needs to be returned. In this case, it’s payload.</p><h3>Shared Error Handler</h3><p>Some applications have a top layer module that formats all errors that bubble up from the application. A good example is Phoenix’s fallback controller pattern:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42a1733130bfbcb879003c63e4517ecc/href">https://medium.com/media/42a1733130bfbcb879003c63e4517ecc/href</a></iframe><p>If you’re using exception modules (described above), the error handling module will have an easy time handling all the different error types. If you’re using tuples for errors, it’s a good idea to standardize not only on the size of the tuple, but the shape of the elements inside too.</p><h3>Encoding Errors in Regular Structs</h3><p>Although using an error tuple for errors is very common, some non-error structs are great for encoding the error status of a function too. A good example of that is the %Ecto.Changeset{} struct, which has the properties valid? and errors.</p><p>Here is an example of a function having two clauses:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff4c9e5d120654e74849dbdb2e2277de/href">https://medium.com/media/ff4c9e5d120654e74849dbdb2e2277de/href</a></iframe><p>The first function matches an invalid Changeset, and does nothing. The second is the fall-through match that is matched when the Changeset is valid. It encrypts a plaintext password, adding it to the Changeset, presumably before saving it to a database. The valid? property represents the error status of the Changeset, so an error tuple is unnecessary.</p><h3>Conclusion</h3><p>Next time you design a function can produce an error value, consider these error patterns.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50dc015a06f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>