<?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 Nestor Marsollier on Medium]]></title>
        <description><![CDATA[Stories by Nestor Marsollier on Medium]]></description>
        <link>https://medium.com/@nestormarsollier?source=rss-6d94fe6a2a64------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hhPqRNiji27ebrtY.jpg</url>
            <title>Stories by Nestor Marsollier on Medium</title>
            <link>https://medium.com/@nestormarsollier?source=rss-6d94fe6a2a64------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 04:26:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nestormarsollier/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[Avoiding unnecessary Interfaces in Go]]></title>
            <link>https://nestormarsollier.medium.com/avoiding-unnecessary-interfaces-in-go-a4b96975b948?source=rss-6d94fe6a2a64------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4b96975b948</guid>
            <dc:creator><![CDATA[Nestor Marsollier]]></dc:creator>
            <pubDate>Tue, 19 Jan 2021 15:38:45 GMT</pubDate>
            <atom:updated>2021-01-19T15:38:45.011Z</atom:updated>
            <content:encoded><![CDATA[<p>Most developers write their apps using OO strategies, using structures, and interfaces, then they implement the interface, all this just because they need to mock data, to allow unit test.</p><p>Personally I think that we are loosing the opportunity to write our code a funcional way, providing simplicity, and focusing our code on results, instead of unit tests.</p><p>The question is, how we mock a function, the answer is really simple, using function pointers.</p><p>Just write your functions like a var function pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*Dj1u71d03BXkfRG6_4FUig.png" /></figure><p>And then to mock the function, just replace the pointer with the desired result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*R363uHQh8a5wn0JrVuG-0g.png" /></figure><p>You may want to save the original function pointer reference in the test sequence to restore it at the end. Or the function will keep mocked.</p><p><strong>Why we need to forget interfaces to just test the code</strong></p><ul><li>Because an interface means strategy pattern, tests are not a reason to implement strategies.</li><li>Functional programming is perfect for small projects.</li><li>Dependency Injection is synonym of coupling.</li><li>Because functional programming lets you think in singe responsibilities.</li></ul><p><strong>Advantages:</strong></p><ul><li>No more unwanted interfaces</li><li>Code simplicity.</li><li>Less code, and more focused on results</li><li>Easier to test</li><li>No more dependency injection</li></ul><p><strong>When this technique is not useful</strong></p><p>When we are coding a shared library, where the shared elements needs to be mocked outside the module.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4b96975b948" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>