<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Rodrigo Martins</title>
    <description>The latest articles on Forem by Rodrigo Martins (@rrmartins).</description>
    <link>https://forem.com/rrmartins</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F233358%2Fdf2f9797-832a-4148-9353-dcb8d2aa9738.JPG</url>
      <title>Forem: Rodrigo Martins</title>
      <link>https://forem.com/rrmartins</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rrmartins"/>
    <language>en</language>
    <item>
      <title>Testing in Elixir: Ensuring code quality</title>
      <dc:creator>Rodrigo Martins</dc:creator>
      <pubDate>Thu, 29 Jun 2023 21:29:05 +0000</pubDate>
      <link>https://forem.com/rrmartins/testing-in-elixir-ensuring-code-quality-4ajn</link>
      <guid>https://forem.com/rrmartins/testing-in-elixir-ensuring-code-quality-4ajn</guid>
      <description>&lt;p&gt;Testing plays a crucial role in software development, helping to ensure code quality and identify issues before they manifest in production. When it comes to functional programming, one of the most popular languages is Elixir. We will explore testing in Elixir and discover how it can help to maintain the integrity of the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why test ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before diving into the details of testing in Elixir, it’s important to understand why test is so important.&lt;/p&gt;

&lt;p&gt;Elixir is a language that is built on solid principles of functional programming and offers powerful features for writing clean and concise code. However, even with Elixir’s elegance, errors can occur. By writing tests, you can verify the correctness of your code and avoid future issues.&lt;/p&gt;

&lt;p&gt;Elixir provides a testing library called ExUnit, which provides a solid framework for writing tests. ExUnit makes it easy to create test cases and execute test suites. Let’s take a look at some basic concepts.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Test Organization:&lt;br&gt;
Tests in Elixir are organized into separate modules, usually within a directory called test. Each test module contains a series of test functions that check the expected behavior of the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Writing Test Cases:&lt;br&gt;
Test cases in Elixir are defined as functions that start with the test prefix. Within each test function, you can call functions from your code and use assert functions to check if the results are as expected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running Tests:&lt;br&gt;
After writing test cases, you can run them using the command line or integrate them into your build process. ExUnit will provide a detailed report on tests that passed and those that failed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits of testing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you write tests in Elixir, you reap several benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Early problem detection: Tests allow you to identify issues before they affect production. By writing comprehensive test cases, you can uncover bugs and logic errors before they impact other components of your system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simplified maintenance: Tests act as living documentation of your code. When you need to make changes to a code snippet, you can run the tests to ensure that the changes do not affect the existing behavior.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reliability: With well-written tests, you can have confidence in your code. When making changes or adding new features, you can run tests to verify that everything continues to function as expected.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Testing is essential to ensure the quality and reliability of your code in any programming language. With ExUnit and its solid framework, writing tests in Elixir becomes a straightforward and efficient task. By adopting testing in your development workflow, you can build robust and reliable systems. So, don’t hesitate to explore the testing features in Elixir and take your code to the next level!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>beginners</category>
      <category>programming</category>
      <category>elixir</category>
    </item>
    <item>
      <title>Clearing the Code with Delegate in Elixir</title>
      <dc:creator>Rodrigo Martins</dc:creator>
      <pubDate>Thu, 29 Jun 2023 17:48:26 +0000</pubDate>
      <link>https://forem.com/rrmartins/clearing-the-code-with-delegate-in-elixir-5dg2</link>
      <guid>https://forem.com/rrmartins/clearing-the-code-with-delegate-in-elixir-5dg2</guid>
      <description>&lt;p&gt;One of the key principles in Elixir programming is writing clear and concise code. The language provides various constructs and features to achieve this goal. In this blog post, we’ll explore one such feature called “delegate.” Delegation in Elixir allows you to simplify your code by forwarding function calls to another module. Let’s dive into the concept of delegate and how it can help improve code readability and maintainability.&lt;/p&gt;

&lt;p&gt;Delegation is a design pattern that enables one module to delegate or forward function calls to another module. In Elixir, delegation is achieved using the defdelegate macro. By delegating functions, you can eliminate repetitive code and create a cleaner and more modular codebase.&lt;br&gt;
To delegate functions in Elixir, you use the &lt;code&gt;defdelegate&lt;/code&gt; macro. Here's an example of how it's used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="k"&gt;defmodule&lt;/span&gt; &lt;span class="no"&gt;MyModule&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="k"&gt;defdelegate&lt;/span&gt; &lt;span class="n"&gt;my_function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to:&lt;/span&gt; &lt;span class="no"&gt;AnotherModule&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the &lt;code&gt;my_function&lt;/code&gt; in &lt;code&gt;MyModule&lt;/code&gt; is delegated to &lt;code&gt;AnotherModule&lt;/code&gt;. This means that any calls to &lt;code&gt;my_function&lt;/code&gt; in &lt;code&gt;MyModule&lt;/code&gt; will be automatically forwarded to &lt;code&gt;AnotherModule&lt;/code&gt;, without having to write explicit forwarding code.&lt;/p&gt;

&lt;p&gt;Delegation offers several benefits when it comes to code clarity and maintainability:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Readability: Delegating functions helps make the code more readable by abstracting away the details of the delegated functionality. It allows developers to focus on the high-level logic without being burdened by the implementation details.&lt;/li&gt;
&lt;li&gt;Code Organization: By delegating functions, you can group related functionality in separate modules, promoting a modular and organized code structure. This separation of concerns improves code maintainability and allows for easier collaboration among team members.&lt;/li&gt;
&lt;li&gt;DRY Principle: Delegation helps adhere to the “Don’t Repeat Yourself” (DRY) principle by avoiding duplication of code. Instead of duplicating function implementations across multiple modules, you can delegate the responsibility to a single module and reuse it throughout your codebase.&lt;/li&gt;
&lt;li&gt;Flexibility and Abstraction: Delegation provides flexibility by allowing you to change the implementation of a function in the delegated module without affecting the calling module. This level of abstraction helps decouple components and makes your code more adaptable to changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While delegation can be a powerful tool, it’s essential to use it judiciously and consider some best practices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limit Delegation: Avoid excessive delegation, as it can introduce unnecessary complexity and hinder code comprehension. Delegate only the functions that genuinely benefit from the abstraction.&lt;/li&gt;
&lt;li&gt;Clear Documentation: Document the delegation relationships in your codebase to make it clear which functions are delegated and where they are implemented. This helps other developers understand the codebase and navigate through the delegation hierarchy.&lt;/li&gt;
&lt;li&gt;Test Delegated Functions: Ensure that the delegated functions are properly tested, both in the delegated module and in the calling module, to guarantee their correctness and maintain code reliability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Delegation is a powerful feature in Elixir that allows you to write cleaner, more modular, and maintainable code. By delegating functions to other modules, you can improve code readability, adhere to the DRY principle, and promote code organization. However, it’s important to use delegation judiciously and follow best practices to maintain code clarity. So, embrace the power of delegation and take your Elixir code to new heights of elegance and simplicity!&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>cleancode</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
