<?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 Mikhail Smal on Medium]]></title>
        <description><![CDATA[Stories by Mikhail Smal on Medium]]></description>
        <link>https://medium.com/@mikhailsmal?source=rss-f5dcbf3aed9e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*utN20TJNAWUtpzCXEOUPUw.jpeg</url>
            <title>Stories by Mikhail Smal on Medium</title>
            <link>https://medium.com/@mikhailsmal?source=rss-f5dcbf3aed9e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:01:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mikhailsmal/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[AutoMapper considered harmful]]></title>
            <link>https://medium.com/@mikhailsmal/automapper-considered-harmful-f4de2c6819cb?source=rss-f5dcbf3aed9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4de2c6819cb</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[fsharp]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Mikhail Smal]]></dc:creator>
            <pubDate>Mon, 05 Oct 2020 18:37:14 GMT</pubDate>
            <atom:updated>2020-10-05T18:37:14.937Z</atom:updated>
            <content:encoded><![CDATA[<p>If I were to briefly describe the software development, I would say that we essentially just take data in one place, transform (map) it to another shape and send to a different place. In other words, the whole development process is mapping.</p><p>In some cases we try to simplify the process of mapping and there are a few ways to do that. One of the options is to use a special library.</p><p>I have been doing C# for many years and as my friends (most of them are C# developers) used AutoMapper in my projects. I believe it was and is the most popular library for mapping objects.<br>The main advantage of AutoMapper is the economy of time spent or writing mapping code. If two objects have the same field name, the field will be automatically mapped with the help of reflection.</p><p>Lately I had yet another debate with my friend about the pros and cons of AutoMapper and I would like to share my thoughts up here.<br>Disclaimer: I don’t use AutoMapper since I don’t use C# anymore and in F# there is no need for it anyway. I also have to mention that the concerns below are related to any similar mapping library, not only AutoMapper itself.</p><h4>Poor code navigation experience</h4><p>If your objects are mapped with default Automapper config, you cannot find where a field takes its value. Even if you use good tooling (VS, Rider) and try to “Find usages” you won’t be able to find neither assignment nor usage. This is especially bad for developers new to project.</p><h4>Refactoring issues</h4><p>At some point you might want to rename a field in one of the models. If you do that, the compiler won’t complain of anything and you will find the issue at runtime, sometime, maybe… Since there is no usage of field in the code for mapping, you might have a really bad debugging. Similar problem can appear with nullable types. But in C# it is still not the easiest thing to solve, especially on older projects. That’s where F# with its static typing and the lack of implicits shines. Should you change a field type to `Option&lt;T&gt;`, you get a compilation error. And then if it compiles, it works :)</p><h4>Domain Driven Development</h4><p>As I mentioned above, the main advantage of AutoMapper is that it saves time spent on writing the mapping code. I got this question: “Do you really write mapping code for all 50+ fields of a type?” And the answer is simple. If you have to do that and your fields have exactly the same names, you are probably doing something wrong. Usually that comes from some storage (a DB). But that means you are doing Data driven development. If you start modeling your types based on domain regardless of how the data should be stored you will most likely have different names of fields and smaller objects.</p><p>Anyway, even if you need to write that much mapping code, remember, it is not the bottleneck of development speed. You will save much more time on maintaining and refactoring the code later on.</p><h4>Mapping validation</h4><p>AutoMapper provides a method for validating the mapping configuration in tests. You can run tests to make sure all your mapping configurations are valid. But this, again, is the same comparison between “dynamic” typing and the need to write more tests and the static typing, which is checked by compiler and eliminates the necessity to write type checking tests. Also the compiler is usually used by the IDE and provides you with errors in real time, even before the compilation.</p><h4>To summarize</h4><p>I strongly discourage you from using Automapper or similar libraries. Write the code you can reason about and take responsibility for.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4de2c6819cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigation with Fable.Elmish]]></title>
            <link>https://medium.com/@mikhailsmal/navigation-with-fable-elmish-1b33717dc14b?source=rss-f5dcbf3aed9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b33717dc14b</guid>
            <category><![CDATA[fable]]></category>
            <category><![CDATA[elm]]></category>
            <category><![CDATA[elmish]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[fsharp]]></category>
            <dc:creator><![CDATA[Mikhail Smal]]></dc:creator>
            <pubDate>Sun, 30 Dec 2018 09:01:00 GMT</pubDate>
            <atom:updated>2018-12-30T09:01:00.735Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is my contribution to the 5th <a href="https://sergeytihon.com/2018/10/22/f-advent-calendar-in-english-2018/">#FsAdvent</a> calendar. Thanks to everyone involved, you make the F# world better.</p><p>F# allows to develop not only server applications, but also front-end side with the help of <a href="https://fable.io/">Fable</a> (F# to JavaScript) compiler. Besides the compilation itself, you, as a front-end developer, need to choose the architecture of your client-side application (of course if you don’t want to have just a couple of JS animations on a static page). In the Fable world, the most popular approach is to utilize MVU<em> (Model-View-Update)</em> architecture, borrowed from the <a href="https://elm-lang.org/">Elm</a> language. F# implementation of MVU pattern is called <a href="https://elmish.github.io/">Elmish</a>, where <a href="https://reactjs.org/">ReactJS</a> (fable-react) is commonly used for View part.</p><p>Elmish provides several helpers for building large-scale single-page applications, including not only Model-Update lifecycle, but also navigation APIs for browsers. In this article I would like to go through the possible types of Elmish navigation.</p><p>Nowadays modern browsers support two types of routing:</p><ul><li><strong>Hash-based</strong> (when SPA handles the changes only in the hash part of the URL)</li><li><strong>Push-state</strong> (when SPA handles the changes in the whole path of the URL thanks to <a href="https://developer.mozilla.org/en-US/docs/Web/API/History_API">window.history</a> API)</li></ul><p>Fable.Elmish supports both of them.</p><h3>Hash-based routing</h3><p>This type of routing is supported even with the oldest browsers, since only the hash part of the URL is being changed; and initially hash was used for anchor links on the same page. It can implemented easily with UrlParser.parseHash helper. The simplest example we could even imagine:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b778ba6559c7d95eb889da51a6417cf/href">https://medium.com/media/5b778ba6559c7d95eb889da51a6417cf/href</a></iframe><p>We have a tiny application, with a model, containing only the current page. Depending on the selected page we show either “Home page” or “About page” text. To update the model with the current page, we rely on parseHash helper, but to handle the mapping, we need to provide a parser (pageParser). In our case it has only basic string mappings to home and about terms with a fallback to home for root(/) path. When a parser finds the appropriate route, it passes the page to our urlUpdate function, where we finally update the model if the URL matches some route, otherwise we modify the URL to fallback to Home page. At this point we can get the arguments (path, query string). We also need to implement init function with a parser result argument, so we could update the model with the current page at the initialization stage.</p><p>Note that this application is totally simplified, it doesn’t even have messages, so the update function doesn’t do anything, just returns the same model.</p><p>Hash-based routing meets all requirements of any possible SPA. With it you just use links with hashes, and Elmish subscribes to hash changes for the navigation. This approach is handy, but I would say, hash is a bit outdated, URLs without it look much better.</p><h3>Push-state routing</h3><p>Push-state routing is visually much nicer. URLs look like regular links with a path, but there is no full reload of a page. However, in Elmish it requires manual control on the links. Elmish.Navigation has an event <br>let [&lt;Literal&gt;] internal NavigatedEvent = &quot;NavigatedEvent&quot;. Unfortunately, it is internal, but we can use the string to cheat a bit. ;)</p><p>So let’s implement a wrapper element, which we can use to trigger this event.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36fec5d798efc9643a8a6a6d00705898/href">https://medium.com/media/36fec5d798efc9643a8a6a6d00705898/href</a></iframe><p>First of all we create LinkProp type with necessary properties:</p><ul><li>To — for replacement of Href property</li><li>Replace — if we want to replace the current history state instead of pushing a new one (Replace false)</li></ul><p>Secondly, we implement the same not as a discriminated union, but as an interface, to be able to use the props as an strongly typed object.</p><p>Then, we implement the link itself. It is just a function with two arguments: props and children. It wraps the passed children with an a element, but with handling its OnClick event. In the handler, we check:<br>if the user passed custom OnClick handler, just invoke it;<br>if not, we check that defaultPrevented = false, the click was not modified by any button, such as ctrl, alt, shift or meta key, that the link doesn’t have Target &quot;_blank&quot; and the link is clicked only with the left mouse button.</p><p>If all conditions are met, we can be sure that it is a standard link click. So we prevent default, depending on Replace property we <em>push </em>or <em>replace</em> the history state and then we trigger the &quot;NavigatedEvent&quot;, which will be handled by Elmish.</p><p>We also want to pass the rest of properties to the a element, so we filter out LinkProp and HTMLAttr.Href props and concat the list with our OnClick and Href props.</p><p>For push-state routing, Elmish app implementation will be pretty much the same, except that you need to use parsePath instead of parseHash and our custom link instead of just a.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd101165e7052625072cbc6136a2f057/href">https://medium.com/media/fd101165e7052625072cbc6136a2f057/href</a></iframe><h3>Wrapping up</h3><p>Comparing the above mentioned types of routing, I, personally, prefer the latter, since it is more modern, using the latest history API and with better URL look. There are a couple of drawbacks, of course: browser compatibility and manual handling of the links, which is a bit cheaty in the provided implementation. However, I believe, that Elmish is stable enough and we can make the NavigatedEvent public.</p><p><em>P.S. The implementation of </em><em>link element is inspired by </em><a href="https://reacttraining.com/react-router/"><em>react-router</em></a><em> project, which has almost the same approach.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b33717dc14b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>