<?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[Pavel Janecka - Medium]]></title>
        <description><![CDATA[.NET developer journeys into hostile waters of functional programming, javascript, stuff and sometimes even cloud. - Medium]]></description>
        <link>https://medium.com/pavel-janecka?source=rss----df2efca317f2---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Pavel Janecka - Medium</title>
            <link>https://medium.com/pavel-janecka?source=rss----df2efca317f2---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:54:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/pavel-janecka" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Migrating to higher .NET Core versions — meantime, keep the old code working!]]></title>
            <link>https://medium.com/pavel-janecka/migrating-to-higher-net-core-versions-meantime-keep-the-old-code-working-bd3d78cbbb18?source=rss----df2efca317f2---4</link>
            <guid isPermaLink="false">https://medium.com/p/bd3d78cbbb18</guid>
            <category><![CDATA[visual-studio]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[Pavel Janečka]]></dc:creator>
            <pubDate>Sun, 10 Sep 2017 18:48:06 GMT</pubDate>
            <atom:updated>2017-09-10T18:48:05.684Z</atom:updated>
            <content:encoded><![CDATA[<p>There’s currently no reason for not upgrading your .NET Core version to either LTS (1.1) or Current (2.0) and possibly to Visual Studio 2017. The migration steps go as follows:</p><ol><li>Install the new SDK</li><li>Make appropriate code changes</li><li>Deploy to production/push to repo</li></ol><h3>Problem with running Core 1.0 with higher SDK installed</h3><p>So you install the appropriate .NET SDK, that is, 1.0.4 for .NET Core runtime 1.1 or 2.0 for .NET Core runtime 2.0. Step one is done. Then you begin to work on step 2.</p><p>Suddenly, there’s a bug in production that needs to be fixed immediately. So you checkout the code that still depends on your previous SDK version, code the fix and try to run it. However, once you installed the new SDK, your project most likely starts throwing errors on startup and dotnet build complains about bad XML format.</p><h3>Global.json to the rescue</h3><p>Why? Chances are, esp. When you are on SDK preview, that you are sporting a project.json (or xproj, for that matter), which the new SDK cannot cope with. Once you install new SDK, all your dotnet commands (that are also used by VS) are going to reference the new SDK. Fortunately, you can use global.json file to specify which SDK you want to use:</p><p>1. Create a global.json file next to your .sln file.</p><p>2. Insert the content:</p><pre>{<br>  &quot;projects&quot;: [&quot;list&quot;, &quot;of&quot;, &quot;projects&quot; ],<br>  &quot;sdk&quot;: {<br>    &quot;version&quot;: &quot;&lt;dotnet sdk version&gt;&quot;<br>  }<br>}</pre><p>3. Replace &lt;dotnet sdk vesion&gt; with the actual version name. You can find the SDK versions in C:\Program Files\dotnet\sdk. Use the folder names</p><p>4. Right click the solution in VS solution explorer and select <em>Add &gt; Existing Item</em>. Select the global.json you have just created and you are good to go.</p><h3>Making the XUnit tests work again</h3><p>XUnit - 0 tests discovered, hostpolicy.dll missing.</p><p>For some strange reason, building XUnit test projects on older SDKs when having the new one installed fails to copy the hostpolicy.dll file to output. I have come up with the following fix that copies said file to the build output directory.</p><p>1. open &lt;Your test project&gt;/project.json .</p><p>2. add the following line to the scripts section:</p><pre>“postcompile”: “xcopy \”C:\\Program Files\\dotnet\\sdk\\1.0.0-preview2–003121\\hostpolicy.dll\” .\\bin\\Debug\\netcoreapp1.0\\win10-x64\\ /Y”</pre><p>where C:\\ProgramFiles\\dotnet\\sdk\\1.0.0-preview2-003121 is the path to your dotnet SDK.</p><p>After saving and rebuilding, the test project will allow your tooling to correctly discover and run tests. This concludes the article. Now you can run project using both old and new SDKs side-by-side.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd3d78cbbb18" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pavel-janecka/migrating-to-higher-net-core-versions-meantime-keep-the-old-code-working-bd3d78cbbb18">Migrating to higher .NET Core versions — meantime, keep the old code working!</a> was originally published in <a href="https://medium.com/pavel-janecka">Pavel Janecka</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing Libraries — Abstract Property or Abstract Method]]></title>
            <link>https://medium.com/pavel-janecka/designing-libraries-abstract-property-or-abstract-method-2221d5074b90?source=rss----df2efca317f2---4</link>
            <guid isPermaLink="false">https://medium.com/p/2221d5074b90</guid>
            <category><![CDATA[software-design]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Pavel Janečka]]></dc:creator>
            <pubDate>Sat, 20 Aug 2016 13:57:35 GMT</pubDate>
            <atom:updated>2016-08-20T13:57:35.018Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes you design a library, where you offer the user an operation. But for that operation, you need the user to provide you with a specific construct that you will reuse.</p><p>Imagine you maintain a key-value storage and want to let the user to store any document in it, without any schema restrictions. The only thing you need from your user is to tell you what’s the key in the object.</p><p>One way to solve this is to provide the library user with an abstract class like this:</p><pre>public abstract class KeyValueItemBase<br>{<br>  <strong>internal InternalRepresentation CreateRepresentation()<br>  {<br>    return new InternalRepresentation(this);<br>  }</strong><br>}</pre><p>The InternalRepresentation class will then be used within the library to be e.g. inserted in to the persistent store. But we are not yet telling it what’s the key. There are two very similar options how to achieve this, either using a property:</p><pre>public abstract class KeyValueItemBase<br>{<br>  <strong>protected abstract string Key { get; }</strong><br>  internal InternalRepresentation CreateRepresentation()<br>  {<br>    return new InternalRepresentation(this, <strong>this.Key</strong>);<br>  }<br>}</pre><pre>public class Person : KeyValueItemBase<br>{<br>  public string Name { get; set; }<br>  public string PersonId { get; set; }<br> <br>  // Overriden property<br>  <strong>protected override string Key =&gt; PersonId;</strong><br>}</pre><p>Or one can use an abstract method to achieve the same:</p><pre>public abstract class KeyValueItemBase<br>{<br>  <strong>protected abstract string GetKey();</strong><br>  internal InternalRepresentation CreateRepresentation()<br>  {<br>    return new InternalRepresentation(this, <strong>this.GetKey()</strong>);<br>  }<br>}</pre><pre>public class Person : KeyValueItemBase<br>{<br>  public string Name { get; set; }<br>  public string PersonId { get; set; }<br> <br>  // Overriden method, notice the brackets<br>  <strong>protected override string GetKey() =&gt; PersonId;</strong><br>}</pre><p>At first, I thought that there is no significant difference, so I chose the property way, because it’s a bit shorter, and it also feels more natural. Then I went to code some more, until I needed to create a class that inherits the KeyValueItemBase. In a rush, I auto-implemented the property like this:</p><pre>public class Person : KeyValueItemBase<br>{<br>  public string Name { get; set; }<br>  public string PersonId { get; set; }<br> <br>  // Overriden property<br>  <strong>protected override string Key { get; set; }</strong><br>}</pre><p>Now, what a crazy guy, you might think, designing his own classes and failing to use them. But well, sometimes stuff like this happens. But the point is, if it can happen to a library author it can as well happen to the library user. And that’s what I want to stress here.</p><p>Our job as programmers is not only to create a working software. Our job is also to make it easier for other programmers to reuse our work. With this in mind, the <strong>abstract method</strong> approach feels actually better, because there is less room for errors emerging from laziness or lack of time, and also, there is an explicit intent for the method to actually do something. So that’s in the end the way I built the thing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2221d5074b90" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pavel-janecka/designing-libraries-abstract-property-or-abstract-method-2221d5074b90">Designing Libraries — Abstract Property or Abstract Method</a> was originally published in <a href="https://medium.com/pavel-janecka">Pavel Janecka</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hierarchical Unit Test Names Effortlessly in C#]]></title>
            <link>https://medium.com/pavel-janecka/hierarchical-unit-test-names-effortlessly-in-c-e6d3cf1559fd?source=rss----df2efca317f2---4</link>
            <guid isPermaLink="false">https://medium.com/p/e6d3cf1559fd</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Pavel Janečka]]></dc:creator>
            <pubDate>Wed, 10 Aug 2016 19:31:52 GMT</pubDate>
            <atom:updated>2016-08-10T19:31:51.670Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing unit tests well is only one part of the key to success. Another would be keeping the tests clean as you would the code that actually does the hard work. So tests should benefit from inheritance, SOLID principles and stuff, just like the other code. But what if your tools make navigating through test run results uncomfortable?</p><h3>Motivation for Structured Unit Tests</h3><p>An imaginary .NET shop writes C# code, does continuous integration thru Visual Studio Team Services and favors the original Test Explorer window over the ReSharper alternative. People in the shop take pride in being good developers and write unit tests. For this, they use standard MSTest unit testing framework.</p><p>Unit tests are usually written without leveraging inheritance, sometimes resulting in a hard-to-find-anything-in-the-code situations. Structuring the tests hierarchically into folders would help separate scenarios tested (Single Responsibility Principle), while inheritance helps maintain common logic (e.g. creating mock objects) in one place (Don’t Repeat Yourself Principle). Applying these two simple rules results in much smaller classes and very maintainable, focused code.</p><h3>Problems the Structured Unit Tests Bring for standard tools</h3><p>However, it is more important how the code is used than how it is written, and with unit tests it is not different. And from this, an interesting argument arises: When nesting classes into folders, while using <strong>MSTest</strong> and <strong>default Visual Studio Test Explorer</strong>, suddenly, these methods are listed only by their name. Of course, one can group the methods by classes. But if the unit test writing pattern is:</p><ul><li>Folder per class</li><li>Nested folder per method</li><li>Class to hold tests for one method and scenario type</li><li>Test method for each scenario of that method</li></ul><p>Then you lose the information conveyed by the hierarchical structure created by folders. And navigating test results becomes messy. As you can see in the following picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*GX5b_xfzT0MHQ8NNsbx_3A.png" /></figure><p>Right clicking and selecting grouping by class could do the trick, except still, namespaces and folders are ignored. And now we have the following confusing state, where two tests expect different outputs from the same inputs. (Hint — they are part of a different namespace)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*hH_Hjb7x0LjEU52Gq09sTQ.png" /></figure><h4>Overcoming Navigation Issues With Resharper…</h4><p>One could offer that ReSharper test explorer solves the issue. And it is a correct remark, take a look on the next picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*KjAAjVs0zOj7cSd4VisSiw.png" /></figure><p>Now we can clearly see that TooLowException should be thrown only when doing MasterCalculations, and calculations within the domain model behave as expected. But…</p><h4>… Is not good enough.</h4><p>Apart from not everyone being able to afford ReSharper, here comes Visual Studio Team Services into play. Finally. After pushing the code into Visual Studio Team Services account and running build, a following output can be seen, again without knowing anything about the test method organization.</p><pre>2016–08–10T18:53:46.5708205Z Passed WhenSubtractingTwoFromFour_ThrowsTooLowException<br>2016–08–10T18:53:46.5718204Z Passed IfMasterAtHome_ReturnsObedience<br>2016–08–10T18:53:46.5718204Z Failed IfMasterAtWork_ReturnsObedience<br>2016–08–10T18:53:46.5718204Z Passed WhenSubtractingTwoFromFour_ReturnsTwo</pre><p>I believe that with some fiddling with build scripts in the Visual Studio Team Services, one might override default build log behavior. Unfortunately, I don’t have time for this, and I have also not found any way to change display names for test methods in the MSTest framework.</p><h3>Enter XUnit</h3><p>Seeing these issues, I immediatelly grasp for tools I know to see if the would help me. And they do help. <a href="https://xunit.github.io/">XUnit</a> is a Unit Testing framework that replaces MSTest. It’s main idea is to keep things simple while being actually usable at the same time.</p><p>First, some basics. Unit test class is a class that contains unit tests. Simple as that, no need for TestClassAttribute. Unit test is a public method decorated with FactAttribute or TheoryAttribute (simply put, theory is a parametrized unit test). And for the XUnit to work, you just need to install the following two nuget packages:</p><pre>PM&gt; Install-Package xunit</pre><pre>PM&gt; Install-Package xunit.runner.visualstudio</pre><p>And voila. After rewriting tests to use XUnit and running tests, suddenly, a wild Visual Studio Test Explorer window appears:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AsOJLftEpC0vDCgGnit9SA.png" /></figure><p>The test hierarchy can be now inferred from name. This is XUnit’s default behavior. And if we let Visual Studio Team Services to run a build and tests:</p><pre>2016-08-10T19:25:06.7380275Z Passed   UnitTestsClassic.Tests.GenericTests.MasterCalculations.SubtractionTests.WhenSubtractingTwoFromFour_ThrowsTooLowException<br>2016-08-10T19:25:06.7380275Z Passed   UnitTestsClassic.Tests.DomainTests.CorrectDataDomainTests.SubtractionTests.WhenSubtractingTwoFromFour_ReturnsTwo<br>2016-08-10T19:25:06.7380275Z Passed   UnitTestsClassic.Tests.SuperTests.SuperHeroTests.WhenSkiesClear_CallBatmanWorks<br>2016-08-10T19:25:06.7380275Z Failed   UnitTestsClassic.Tests.GenericTests.Behavior.MasterTests.IfMasterAtWork_ReturnsObedience<br>2016-08-10T19:25:06.7410279Z Passed   UnitTestsClassic.Tests.GenericTests.Behavior.MasterTests.IfMasterAtHome_ReturnsObedience</pre><p>Again, clear what has failed and succeeded. Much clearer than I would have been able to achieve with MSTest.</p><h3>Summary</h3><p>There is no substitute for readability and the time it saves. This holds true especially with large code bases. I can only imagine how you value your time, so I can only suggest to save it using the right tools for the job.</p><p>Of course, XUnit has many more advantages over the MSTest, e.g. better expected exception throw assertion, better lifecycle handling and other, while covering for the whole MSTest functionality.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6d3cf1559fd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pavel-janecka/hierarchical-unit-test-names-effortlessly-in-c-e6d3cf1559fd">Hierarchical Unit Test Names Effortlessly in C#</a> was originally published in <a href="https://medium.com/pavel-janecka">Pavel Janecka</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Art of Learning While Making the Right Decisions]]></title>
            <link>https://medium.com/pavel-janecka/the-art-of-learning-while-making-the-right-decisions-b26754e8a30c?source=rss----df2efca317f2---4</link>
            <guid isPermaLink="false">https://medium.com/p/b26754e8a30c</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Pavel Janečka]]></dc:creator>
            <pubDate>Mon, 08 Aug 2016 12:56:03 GMT</pubDate>
            <atom:updated>2016-08-07T11:37:52.582Z</atom:updated>
            <content:encoded><![CDATA[<p>It happens very often. We learn something. Then, eager to apply the newly found knowledge, we hammer every thing that we will to be a nail. I am in process of learning the Scala programming language these days, and so I have figured: “Let’s try these skills at HackerRank!” And so I did…</p><h3>1st mistake: Not Reading the Problem Description Well</h3><p>After skimming the description for the first time, I immediately jumped to conclusion — this is easy! I stated that given a number of digits, N, find the largest number that:</p><ul><li>has N digits</li><li>contains only digits 3 or 5</li><li>total count of fives in the number is divisible by 3</li><li>total count of threes in the number is divisible by 5</li></ul><p>Of course, the problem description contained one more information I missed. A vital one. Largest N that can appear is 10000. Very hard to store in an long, wouldn’t you say?</p><h3>2nd mistake: Manipulating Yourself into a Pressure</h3><p>This is a tricky part. Roughly this went through my head: “When the problem seems really easy to grasp, there must be a simple solution, to it.” And, frankly, the correct solution really is simple. But people sometimes do stupid things under pressure.</p><p>So, I pondered two approaches — string or a numerical one. Because of the pressure, I chose numerical approach, reasoning that I’ll need to do numerical operations, like comparing two numbers to get the larger one. Again, wrong.</p><h3>3nd mistake: Focusing on How, not Why</h3><p>But I was not focused on this decisions, for a bad reason. It was a mere distraction on the way to applying tail recursion, pattern matching, accumulating the partial results and so on. It never occurred to me WHY am I going down this path and where does it lead. All I cared about was HOW do I get to the end of it ASAP. There were so many concepts I held in my head and feared that if I slow down, I’ll lose them.</p><p>And being focused on HOW, not WHY, is being further confirmed by the fact that after overflowing integers had caught up with me, I sought to convert my solution to using integers… only to find out that in Scala, streams and iterators do not generate infinite lists of longs! What a strange language, I thought…</p><p>After a few more tries of applying many wrong (but very cool) approaches to the problem, I noticed something that I have neglected in the very beginning of coding through this problem: The decision about the string vs numerical approach. And then it struck me — I what if I do not need the numerical operations at all — what if there’s a way to create the largest number right away? Turns out there is such way…</p><h3>4th mistake: Not Learning from Every Opportunity</h3><p>And finally, I can tell you about one mistake that I have managed to avoid. Even though the final solution consisted of below 10 lines of code, I strengthened my knowledge of Scala’s for syntax, found out how to do permutations with repetition on a list and some more things.</p><p>But most importantly, I have found out that there is no shortcut to reading the problem description. That maybe the only person that can manipulate me into a time pressure is me. And that focusing on Why instead of How, no matter how hard that can sometimes be, can save a lot of time. And this, my dear reader, applies not only to programming, but to all kinds of learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b26754e8a30c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pavel-janecka/the-art-of-learning-while-making-the-right-decisions-b26754e8a30c">The Art of Learning While Making the Right Decisions</a> was originally published in <a href="https://medium.com/pavel-janecka">Pavel Janecka</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>