<?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>DEV Community: Davidson Sousa</title>
    <description>The latest articles on DEV Community by Davidson Sousa (@davidsonsousa).</description>
    <link>https://dev.to/davidsonsousa</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%2F160634%2F920a78fb-c690-407d-9d34-57bf74a25019.jpg</url>
      <title>DEV Community: Davidson Sousa</title>
      <link>https://dev.to/davidsonsousa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidsonsousa"/>
    <language>en</language>
    <item>
      <title>How to invert the parameters of a method using Regular Expressions</title>
      <dc:creator>Davidson Sousa</dc:creator>
      <pubDate>Tue, 21 Jul 2020 22:07:00 +0000</pubDate>
      <link>https://dev.to/davidsonsousa/how-to-invert-the-parameters-of-a-method-using-regular-expressions-28h3</link>
      <guid>https://dev.to/davidsonsousa/how-to-invert-the-parameters-of-a-method-using-regular-expressions-28h3</guid>
      <description>&lt;p&gt;Today I noticed that all &lt;code&gt;Assert.Equal()&lt;/code&gt; in our unit tests had inverted parameters. Meaning that we had &lt;code&gt;Assert.Equal(actual, expected)&lt;/code&gt; instead of having &lt;code&gt;Assert.Equal(expected, actual)&lt;/code&gt;. The result does not change when the test passes, but it can lead to mistakes or misunderstandings when &lt;code&gt;Assert.Equal()&lt;/code&gt; returns false.&lt;/p&gt;

&lt;p&gt;Changing the order of the parameters is simple but it can be both annoying and time consuming if we have a lot of method calls.&lt;/p&gt;

&lt;p&gt;What to do?&lt;/p&gt;

&lt;p&gt;Since &lt;strong&gt;Visual Studio allows Find/Replace using regular expressions&lt;/strong&gt; , we can do it easily. First, we will need to enable the regex mode in the Find/Replace:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YrRmUVOh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hn7y4f73vlhsqd2bph22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YrRmUVOh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hn7y4f73vlhsqd2bph22.png" alt="Selecting Regex on Find/Replace"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we prepare a regex like the one below and place it on &lt;em&gt;Find&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\((.*?)(, )(.*?)\);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This regex finds everything what is between the first parentheses and the semicolon, which allows you to have some method calls as parameters like &lt;code&gt;expectedPerson.GetFullName()&lt;/code&gt;, for example. Also, it separates the result in 3 groups - first parameter (&lt;code&gt;$1&lt;/code&gt;), coma and space (&lt;code&gt;$2&lt;/code&gt;), second parameter (&lt;code&gt;$3&lt;/code&gt;) - which we will have in the &lt;em&gt;Replace&lt;/em&gt; like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;($3, $1);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As mentioned previously, we had 3 groups. We could include the group &lt;code&gt;$2&lt;/code&gt; but ut it's not necessary in this case as we can "hard code" the comma and space for better understanding.&lt;/p&gt;

&lt;p&gt;Here is how the Find/Replace is going to look like with our regex and replacements:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E0v0cOCg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxbxogvu6zd1vyo80afl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E0v0cOCg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxbxogvu6zd1vyo80afl.png" alt="Find/Replace with Regex string"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here is how the selection looks in the code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tID9_4Z---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdt87qhpjpim8aar4ndz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tID9_4Z---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdt87qhpjpim8aar4ndz.png" alt="Code with regex match"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; Don't forget to change the Find/Replace scope to Selection in case you want to invert the parameters of a method otherwise you will have unintended consequences.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PeVMOhGT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qa1btpdcc7gsc3052cou.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PeVMOhGT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qa1btpdcc7gsc3052cou.png" alt="Choosing Selection on Find/Replace box"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can check &lt;a href="https://regex101.com/r/iGWMb2/2"&gt;this regex in the Regex101.com website&lt;/a&gt; if you want to play around before using it.&lt;/p&gt;

</description>
      <category>regex</category>
      <category>visualstudio</category>
    </item>
    <item>
      <title>The importance of having coding standards in a project</title>
      <dc:creator>Davidson Sousa</dc:creator>
      <pubDate>Fri, 25 Oct 2019 17:13:00 +0000</pubDate>
      <link>https://dev.to/davidsonsousa/the-importance-of-having-coding-standards-in-a-project-12b2</link>
      <guid>https://dev.to/davidsonsousa/the-importance-of-having-coding-standards-in-a-project-12b2</guid>
      <description>&lt;p&gt;If someone asks me how much time we should dedicate to the creation of standards for a project, I will say “as much as we need”. Why? Because everything in our lives is standardized. The colors of the traffic lights, the ways we drive, the places we need to go in order to use public transportation and so on. And we are satisfied with it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmzogw2v8brfalm05e444.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmzogw2v8brfalm05e444.jpg" alt="Subway"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The main problem of the lack of standards is that everyone will do the same thing, but in a different way. And that is the recipe for disaster. For example: Sizes of clothes. We are often advised to buy clothes in the same stores or from the same brands because the sizes may differ from one store/brand to another. A shirt size “L” in the store A may fit you well, while size “L” of the same model of shirt in the store B may expose your belly.&lt;/p&gt;

&lt;p&gt;And in software development standards are often neglected by teams because “we don’t have time for that” or “the client is not paying for standards” or even “if you need you can copy from someone else’s code”. This is a mistake because standards are the only thing that will make a group of different people coming from different backgrounds to work in a large codebase with consistence.&lt;/p&gt;

&lt;p&gt;If you still don’t think this is a problem, think about this: There are some people who prefer to use &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;foreach&lt;/code&gt; without curly braces (and people who prefer them with), there are people who don’t care about the length of the lines (those who enable word wrap) while others prefer to break it after a number of characters. Not to mention those who prefer &lt;a href="https://www.youtube.com/watch?v=V7PLxL8jIl8" rel="noopener noreferrer"&gt;&lt;em&gt;tabs&lt;/em&gt; instead of &lt;em&gt;spaces&lt;/em&gt; &lt;/a&gt; (or vice-versa). Just imagine how messy a file touched by all those different people in different moments of the project would look like. Tabs and spaces mixed up, inconsistence on the look of conditions, etc. What can prevent that? A simple set of rules.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fyqneaz9wb5jrzk6apdj1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fyqneaz9wb5jrzk6apdj1.png" alt="Different ways to write foreach"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If this doesn’t happen in your team, congratulations. You are lucky to work in a place where everybody codes in the same way. But I’m going to feel bad for the new employee who will join coding differently as he will be labeled as “the guy with ugly code” until he gets used to the code the team produces.&lt;/p&gt;

&lt;p&gt;There are multiple ways to enforce code consistence, but I normally stick to a simple one: The &lt;em&gt;&lt;a href="https://editorconfig.org/" rel="noopener noreferrer"&gt;.editorconfig&lt;/a&gt;&lt;/em&gt; file. If you are not familiar with it, the &lt;em&gt;.editorconfig&lt;/em&gt; is a file containing the styling rules of your code. You may want to check if your editor/IDE has support for it. It’s free and the file can work in scenarios where a project has people working in multiple technologies and operating systems. Commit to your repository along with your project and everyone will code in the same way. I could also mention &lt;a href="https://www.jetbrains.com/resharper/" rel="noopener noreferrer"&gt;ReSharper&lt;/a&gt;, but this one is paid and specific for .NET Development.&lt;/p&gt;

&lt;p&gt;I understand it’s boring and/or annoying to sit with the team and go over standards. I’d expect to do this just once, in the beginning, but leaving the door open to discuss some changes as the project progresses. After a while the changes will come to a minimum and you will even spread the standards across projects and teams. As it should be.&lt;/p&gt;

&lt;p&gt;What do you think?&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>coding</category>
      <category>standards</category>
      <category>codingstandards</category>
    </item>
    <item>
      <title>The problem of debugging a Docker project in Visual Studio</title>
      <dc:creator>Davidson Sousa</dc:creator>
      <pubDate>Sun, 25 Aug 2019 17:48:00 +0000</pubDate>
      <link>https://dev.to/davidsonsousa/the-problem-of-debugging-a-docker-project-in-visual-studio-23ff</link>
      <guid>https://dev.to/davidsonsousa/the-problem-of-debugging-a-docker-project-in-visual-studio-23ff</guid>
      <description>&lt;p&gt;I’ve been reading about &lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt; for a couple of weeks already and, few days ago, I decided to create a small proof of concept. You know, just to make sure that I understood everything well. But I ended up running into problems which resulted in a &lt;a href="https://twitter.com/DavidsonSousa/status/1162087779523801088" rel="noopener noreferrer"&gt;small thread on Twitter&lt;/a&gt; that I am expanding here.&lt;/p&gt;

&lt;p&gt;Everything started when I decided to use Visual Studio 2019 to take care of Docker for me. In case you don’t know, you can “dockerize” existing projects…&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fadd-docker-support.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fadd-docker-support.png" alt="add-docker-support.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;…or create a “dockerized” project from scratch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fenable-docker-support.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fenable-docker-support.png" alt="enable-docker-support.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I decided to do both since I was just playing around. The result was a couple of duplicated files that I ended up deleting later. Perhaps the best option is to “dockerize” a project after it’s been created. Anyway, here is the result so far:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fsolution-explorer.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fsolution-explorer.png" alt="solution-explorer.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From that point I just wanted to see if what would happen when I run the project. So, I did my usual: Start the project without debugging (Ctrl+F5). I prefer to do that because it gives me the feeling that I am running closer to a real application. Not to mention that I would not hit random breakpoints I’ve added and forgot to disable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fdebug-menu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fdebug-menu.png" alt="debug-menu.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whenever I want to debug, I simply attach the Visual Studio to the process of the project (Ctrl+Alt+P).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fdebug-menu-attach.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fdebug-menu-attach.png" alt="debug-menu-attach.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That opens a dialog where I can select the process. But since I am using Docker, I must select the connection target, which is the name of the container, and the process, which is “dotnet”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fconnection-target.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fconnection-target.png" alt="connection-target.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is one extra step here which is the type of the code. Since I am using &lt;strong&gt;Linux Containers*&lt;/strong&gt; , I will choose the only option available.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fcode-type.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fcode-type.png" alt="code-type.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That should be it. The code would be attached, and I would be able to debug. Unfortunately, I got an exception after a couple of seconds saying that the launch debug adapter failed to launch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fexception.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fexception.png" alt="exception.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the exception was also pointing to the Output Window, it was a good idea to check there too. And that was the moment I regret that I don’t really know Linux:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Foutput-window.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Foutput-window.png" alt="output-window.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The most important part of the whole text from the Output Window is written in red, at the bottom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR: Command 'unzip' not found. Install 'unzip' for this script to work.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It turns out that I didn’t have that “unzip” installed in my container. How to install? No idea. But after some investigation &lt;a href="https://github.com/dotnet/dotnet-docker/blob/master/2.2/aspnet/stretch-slim/amd64/Dockerfile" rel="noopener noreferrer"&gt;I found a &lt;em&gt;dockerfile&lt;/em&gt;&lt;/a&gt; that &lt;strong&gt;could&lt;/strong&gt; help me as it seemed to match mine. Or at least had the same principle. The most important thing for me in that file was what seemed to install “curl”. So, I copied that part and pasted into my own &lt;em&gt;dockerfile&lt;/em&gt;, just being careful to replace &lt;em&gt;unzip&lt;/em&gt; with &lt;em&gt;curl&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fdockerfile.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fdockerfile.png" alt="dockerfile.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once I’ve done that, I repeated my debugging steps: run without debug and attach. At this time it works without any problem. For someone who isn’t used to work with Docker I noticed that it takes a couple of seconds to attach when compared with a normal run. But when I detach and reattach it goes as fast as I am used to. And all breakpoints were hit.&lt;/p&gt;

&lt;p&gt;Maybe this is a small bug in the &lt;em&gt;dockerfile&lt;/em&gt; generated by Visual Studio, which means I should learn how to create my own &lt;em&gt;dockerfile&lt;/em&gt; manually until it’s fixed. Or maybe I am missing something. Another thing I noticed: The attach doesn’t work with Windows Containers and I would have to use F5 to debug it.&lt;/p&gt;

&lt;p&gt;I am still learning and there is a lot to understand there.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;*Note:&lt;/strong&gt; I am using Linux Containers because Windows Containers didn't even allow me to debug properly. My best guess is that VS and Docker still need to work on their relationship.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>visualstudio</category>
      <category>debugging</category>
    </item>
    <item>
      <title>My first impressions of Razor Components</title>
      <dc:creator>Davidson Sousa</dc:creator>
      <pubDate>Sat, 23 Mar 2019 11:03:00 +0000</pubDate>
      <link>https://dev.to/davidsonsousa/my-first-impressions-of-razor-components-40kl</link>
      <guid>https://dev.to/davidsonsousa/my-first-impressions-of-razor-components-40kl</guid>
      <description>&lt;p&gt;First of all, let me say that &lt;a href="https://twitter.com/shanselman" rel="noopener noreferrer"&gt;Scott Hanselman&lt;/a&gt; put together a great explanation of &lt;a href="https://www.hanselman.com/blog/WhatIsBlazorAndWhatIsRazorComponents.aspx" rel="noopener noreferrer"&gt;What is Blazor and what is Razor Components&lt;/a&gt;. You should check it out if you don't know what I am talking about since, here, I will only talk about my experiences so far, without getting into definitions.&lt;/p&gt;

&lt;p&gt;It was the end of last year that I started to hear about the growing support for &lt;strong&gt;Blazor&lt;/strong&gt; , which is an experimental framework which compiles C# and HTML into &lt;a href="https://webassembly.org/" rel="noopener noreferrer"&gt;Web Assembly&lt;/a&gt; (Wasm). But it was at the same period that I also heard about the Server Side Blazor – which was later renamed to &lt;strong&gt;Razor Components&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At the time I am writing this article &lt;a href="https://devblogs.microsoft.com/aspnet/blazor-0-9-0-experimental-release-now-available/" rel="noopener noreferrer"&gt;Blazor is still experimental (version 0.9.0)&lt;/a&gt; and apps made with it should not be used in production. Razor Components, on the other hand, should be released this year with the new .NET Core. And since both works almost in the same way I decided to give Razor Components a try.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tooling
&lt;/h2&gt;

&lt;p&gt;As of now I am using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SDK: .NET Core 3.0.100 Preview 3 (010431)&lt;/li&gt;
&lt;li&gt;Runtimes: .NET Core 3.0.0 Preview 3 (27503-5) / ASP.NET Core 3.0.0 Preview 3 (19153-02)&lt;/li&gt;
&lt;li&gt;IDE: Visual Studio 2019 RC.2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The SDK and runtimes can be downloaded &lt;a href="https://dotnet.microsoft.com/download/dotnet-core/3.0" rel="noopener noreferrer"&gt;here&lt;/a&gt;, while Visual Studio 2019 RC can be downloaded &lt;a href="https://visualstudio.microsoft.com/downloads/#2019rc" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The very first thing I needed to do after installing VS 2019 was to enable it to use the preview libraries. I did that by going to Options -&amp;gt; Projects and Solutions -&amp;gt; .NET Core and enabling &lt;em&gt;Use previews of .NET Core SDK&lt;/em&gt;. Only then I was able to create my first Razor Component app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fvs-preview-options.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fvs-preview-options.png" alt="Enabling .NET Core preview versions on Visual Studio 2019"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the app created there are a couple of things to be observed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The file structure, which contains only &lt;strong&gt;Components&lt;/strong&gt; , &lt;strong&gt;Pages&lt;/strong&gt; and their respective subfolders;&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;.razor&lt;/strong&gt; files, which somehow reminds me of the old ASP 3 (or PHP) files. But I will talk more about them later;&lt;/li&gt;
&lt;li&gt;The Startup.cs, Program.cs and appsettings.cs files, which are the same as seen in the regular ASP.NET Core website&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fvs-solution-explorer-razor-components.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Fvs-solution-explorer-razor-components.png" alt="vs-solution-explorer-razor-components.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The project
&lt;/h2&gt;

&lt;p&gt;As afore mentioned, the file structure is simple – containing only &lt;strong&gt;Components&lt;/strong&gt; , &lt;strong&gt;Pages&lt;/strong&gt; and their respective subfolders. The Pages folder is going to look familiar to an ASP.NET Developer as it contains _ViewImports.cshtml and Index.cshtml – both seen in previous versions of MVC. The catch here is with Index.cshtml. We must remember that Razor Components works like a SPA, which means that our Index.cshtml will contain the whole web app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Frazor-components-index-file-smaller.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Frazor-components-index-file-smaller.png" alt="razor-components-index-file-smaller.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Components folder contains multiple _ViewImports.cshtml files in their respective folders, but also multiple .razor files. These files are the “pages” of our application. They may contain both markups (HTML and Razor) and C# code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Frazor-components-counter-file.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Frazor-components-counter-file.png" alt="razor-components-counter-file.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Compilation
&lt;/h2&gt;

&lt;p&gt;One thing I’ve noticed when I was creating my small prototype is how the files are compiled into a C# class with &lt;strong&gt;.g.cs&lt;/strong&gt; extension and placed on &lt;strong&gt;/Razor&lt;/strong&gt; and &lt;strong&gt;/RazorDeclaration&lt;/strong&gt; folders, both on &lt;strong&gt;/obj/Debug/netcoreapp3.0&lt;/strong&gt;. While I’ve seen such extension before (don’t remember where) it helps us to see how the files Razor files are converted into C# classes and how the tags are setup.&lt;/p&gt;

&lt;p&gt;My theory is that the files on /RazorDeclaration folder are there to make sure they exist since the only method they have is an override of &lt;strong&gt;BuildRenderTree&lt;/strong&gt; , which is empty. As for the files on /Razor folder you can see the same method (BuildRenderTree) building the entire html page with its elements and binders. Perhaps this is a technique used in a different type of .NET project and they decided to bring it to Razor Components. I don’t know, I will need to do some research in order to understand what is really happening there.&lt;/p&gt;

&lt;p&gt;In addition, the content added into &lt;em&gt;@functions&lt;/em&gt; is also in that class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Frazor-components-g-cs-file-side-by-side.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Frazor-components-g-cs-file-side-by-side.png" alt="razor-components-g-cs-file-side-by-side.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Sort of code-behind, if you want
&lt;/h2&gt;

&lt;p&gt;If you don’t want to mix C# syntax and Razor markup, you can create a separated C# file and inherit from the &lt;strong&gt;ComponentBase&lt;/strong&gt; class. Then, in your .razor file, you should add a line to explicitly say that you are going to use that class as code-behind. The line is &lt;em&gt;@inherits YourCodeBehindClass&lt;/em&gt;. My personal convention is to end the C# class with &lt;em&gt;Base&lt;/em&gt;. That means: If my .razor file is &lt;em&gt;CreateEdit&lt;/em&gt; my C# class will be called &lt;em&gt;CreateEditBase&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Frazor-components-code-behind-side-by-side.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Fpost%2Frazor-components-code-behind-side-by-side.png" alt="razor-components-code-behind-side-by-side.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That helps to keep your code a bit more organized and create a real separation there, so you can bring other people to work on your markup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problems (so far)
&lt;/h2&gt;

&lt;p&gt;I think the most annoying problem I encountered happened when I was trying to add a .razor file to create a list of calendars. I did the usual: Added a .razor file, named it and started to work on it. When I tried to compile it, I got an error claiming that my class didn’t exist. I was only able to solve it by adding a .cshtml file, compiling the project and then renaming it to .razor.&lt;/p&gt;

&lt;p&gt;Another annoyance is the fact that you must rebuild the whole app if you want to make changes in the markup. That’s understandable when you remember that all .razor and .cshtml files are transformed into .g.cs files during compilation. Maybe in the future they will allow .razor files trigger the building, as we do now with .cs files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Any .NET Developer who worked at least a little with MVC would find easy to understand what is going on. After all, it’s still ASP.NET. Sort of. Besides, Microsoft has a very nice documentation and, soon enough, some books might start to appear.&lt;/p&gt;

&lt;p&gt;I can picture some scenarios where Razor Components could be used, such as intranets or any kind of internal web apps which are used in small scale. Still, the possibilities are endless.&lt;/p&gt;

&lt;p&gt;But there is still a lot of work to be done in order to be production ready. Once done it goes prod, I am gonna use it. And probably advocate for that.&lt;/p&gt;

</description>
      <category>blazor</category>
      <category>razorcomponents</category>
      <category>dotnetcore</category>
    </item>
    <item>
      <title>Fellow developer: The lack of empathy may be killing your career</title>
      <dc:creator>Davidson Sousa</dc:creator>
      <pubDate>Sun, 13 May 2018 19:32:00 +0000</pubDate>
      <link>https://dev.to/davidsonsousa/fellow-developer-the-lack-of-empathy-may-be-killing-your-career-4j4l</link>
      <guid>https://dev.to/davidsonsousa/fellow-developer-the-lack-of-empathy-may-be-killing-your-career-4j4l</guid>
      <description>&lt;p&gt;We, developers, are often practicing the best technology of today while trying to learn the best technology of tomorrow. The problem is that not so many of us focus on the other part of our work. Mostly understanding the client needs and improving our soft skills.&lt;/p&gt;

&lt;p&gt;If a developer is not able to understand the client and have a decent overview about its business, he will be unable to create an appropriate solution. And that sadly means he will not be so different from a monkey with a keyboard.&lt;/p&gt;

&lt;p&gt;The key for cultivating deep understanding is to create empathy and try to care about what is important for the client as we care about what is important for us but, unfortunately, the development culture is wrong.&lt;/p&gt;

&lt;p&gt;Part of the blame goes to the schools. “Oh, this school has a great Computer Science program” or “Many people working in this amazing company come from that school” are common things to hear when you are about to pick a college. The problem is that most of the schools have an excessive focus on technical subjects making some of the future professionals with almost zero people skills as they are leaving the more “human” topics aside.&lt;/p&gt;

&lt;p&gt;The other part of the blame I put on the people we look up to – Famous developers, our colleagues, seniors in our own companies and so on. When we start getting into software development for real we hear things like “clients never knows what they want” or, often, stories about developers who stayed overnight to deliver a project and are regarded as heroes.&lt;/p&gt;

&lt;p&gt;Bullshit.&lt;/p&gt;

&lt;p&gt;The real heroes in software development are those who actually try and succeed to understand what the client wants and are able to translate this into a well written code. Understand the client is not difficult, we just need to empathize with them. Just like we should empathize with everybody else.&lt;/p&gt;

&lt;p&gt;To put this into a context, imagine if you need to visit a doctor: You don’t know what you have when you go to the doctor. You describe how you feel and the doctor will make the diagnosis based on what he hears and what he checks. Then he will prescribe some medicaments or send you to a specialist. We tend to trust doctors because we know that, even if they are pressed with time, they know what they are doing.&lt;/p&gt;

&lt;p&gt;I know there are bad doctors. There are also bad developers. Just stick with me.&lt;/p&gt;

&lt;p&gt;Can you imagine how you would feel if you go to the doctor with a broken arm and the only thing they do is to give you an antibiotic? That’s more lack of interest of taking care of you than very poor diagnostic skills. In another words, he is a monkey with a stethoscope.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Farticles%2Fe1c4e9963f99592965f1205490f9d2e7--evan-sharp-feel-better.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fdavidsonsousa.net%2Fimage%2Farticles%2Fe1c4e9963f99592965f1205490f9d2e7--evan-sharp-feel-better.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I guess you know what I mean: We are the doctors and the clients are the patients. The same empathy which connects the doctors to their patients, should connect developers with clients. Only then we will be able to understand what the client wants and actually do something useful about it.&lt;/p&gt;

&lt;p&gt;Oh, and by the way, if you don't understand the needs of your client you most likely don't understand your colleagues either.&lt;/p&gt;

</description>
      <category>developer</category>
      <category>career</category>
      <category>empathy</category>
    </item>
  </channel>
</rss>
