<?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: Dalbir Singh</title>
    <description>The latest articles on DEV Community by Dalbir Singh (@dalbirsingh).</description>
    <link>https://dev.to/dalbirsingh</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%2F325272%2F4e990785-7e28-4a81-8fc9-72da7b9ce001.png</url>
      <title>DEV Community: Dalbir Singh</title>
      <link>https://dev.to/dalbirsingh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dalbirsingh"/>
    <language>en</language>
    <item>
      <title>Clean Code – Part 2</title>
      <dc:creator>Dalbir Singh</dc:creator>
      <pubDate>Wed, 02 Sep 2020 18:32:53 +0000</pubDate>
      <link>https://dev.to/dalbirsingh/clean-code-part-2-56o</link>
      <guid>https://dev.to/dalbirsingh/clean-code-part-2-56o</guid>
      <description>&lt;p&gt;It’s time for the second installment of ‘Clean Code’. If you missed the first one you can find it here:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;div class="ltag__link__content"&gt;
    &lt;div class="missing"&gt;
      &lt;h2&gt;Article No Longer Available&lt;/h2&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;





&lt;h2&gt;
  
  
  Principle of Proximity
&lt;/h2&gt;

&lt;p&gt;This principle is based on &lt;em&gt;‘tell me what I need to know - when I need to know‘&lt;/em&gt;. I see new developers often caught up adding many unrelated variables to the top of their methods.&lt;/p&gt;

&lt;p&gt;Adding properties and backing variables to the top of a class definition is fine. However, when it comes to method implementations, following the same approach can lead to readability issues.&lt;/p&gt;

&lt;p&gt;Take for instance the code below. It contains a method which generates an invoice document and then emails it to the customer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;smtpHost&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AppSettingsHelper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetSmtpHost&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AppSettingsHelper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetFromMailAddress&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Your bill is ready."&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AppSettingsHelper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetToMailAddress&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;billableItems&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_billingService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBillForUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//&lt;/span&gt;
&lt;span class="c1"&gt;// long lines of code here to generate a pdf file with &lt;/span&gt;
&lt;span class="c1"&gt;// the invoice details...&lt;/span&gt;
&lt;span class="c1"&gt;//&lt;/span&gt;
&lt;span class="c1"&gt;// var invoice = ...&lt;/span&gt;
&lt;span class="c1"&gt;//&lt;/span&gt;

&lt;span class="c1"&gt;// send email with invoice as attachment&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ms&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MemoryStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;attachment&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Attachment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Invoice.xml"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;$"Hi, here is your invoice blah blah... "&lt;/span&gt;

&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SmtpClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SmtpClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;smtpHost&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MailMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   
  &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Attachments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attachment&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine yourself or another developer coming back to this code six months later. There are a lot of variables to comprehend, and most of those are largely unrelated to the proceeding code.&lt;/p&gt;

&lt;p&gt;Here’s a better structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;billableItems&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_billingService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBillForUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//&lt;/span&gt;
&lt;span class="c1"&gt;// long lines of code here to generate a pdf file with &lt;/span&gt;
&lt;span class="c1"&gt;// the invoice details...&lt;/span&gt;
&lt;span class="c1"&gt;//&lt;/span&gt;
&lt;span class="c1"&gt;// var invoice = ...&lt;/span&gt;
&lt;span class="c1"&gt;//&lt;/span&gt;

&lt;span class="c1"&gt;// send email with invoice as attachment&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;smtpHost&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AppSettingsHelper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetSmtpHost&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AppSettingsHelper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetFromMailAddress&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Your bill is ready."&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AppSettingsHelper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetToMailAddress&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;$"Hi, here is your invoice blah blah... "&lt;/span&gt;

&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SmtpClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SmtpClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;smtpHost&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MailMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
  &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ms&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MemoryStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;attachment&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Attachment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Invoice.xml"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

  &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Attachments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attachment&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much better. Now when reading the code you only need to comprehend the variables relating to the proceeding code. For example, the email related variables are kept around the email creation logic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Refactoring is good – just don’t overdo it.
&lt;/h2&gt;

&lt;p&gt;The readability of the sample code above can be further improved by moving significant portions of work to their own methods. This also helps when debugging by making it much easier to pinpoint where errors may be occurring. New developers benefit too, by helping them understand &lt;em&gt;“what the code is trying to do”&lt;/em&gt; without being bogged down by noise in “how” it is doing it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;GetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;billableItems&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_billingService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBillForUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;GenerateInvoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;billableItems&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;EmailInvoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// handle exception&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When refactored correctly, code should be “easy” to read and not require so many comments. Note that overzealous refactoring can also cause harm. Extracting code to methods excessively causes inefficiency as the developer scrambles through the codebase to find bits of code.&lt;/p&gt;




&lt;h2&gt;
  
  
  Enums in place of comments
&lt;/h2&gt;

&lt;p&gt;As developers, we often fall into the trap of using raw integer values directly in code. I’ve mentioned before about storing such values in a database or configuration file, though for data values that are unlikely to change this could be overkill. In those cases, using integers in the code is the preferred choice.&lt;/p&gt;

&lt;p&gt;For example, let us imagine a ‘status’ method on an entity…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;// 0 = disabled, 1 = enabled, 2 = hybrid&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using a boolean value is not sufficient in this example as there three possible states. In this case, using integers makes sense, but this causes two problems with readability:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A reliance on comments for describing values. Not everyone writes helpful comments.&lt;/li&gt;
&lt;li&gt;Duplication of comments. Comments describing values in this way are likely to be copied and pasted across the codebase where similar code exists. Even worse, changes made later to the values may invalidate the comment description altogether.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So what’s the answer?... Create an Enum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;DeviceStatus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Disabled&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Enabled&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Hybrid&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Then we can do this:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DeviceStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Enabled&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code has been improved by creating an Enum type &lt;code&gt;DeviceStatus&lt;/code&gt;. It has three possible values that can be extended easily. Each value in the Enum has an underlying integer value. Thus in programming languages similar to C# they can be easily used in places instead hard-coding integer values.&lt;/p&gt;

&lt;p&gt;The intent of the code is more clear and reduces the need for comments.&lt;/p&gt;




&lt;h2&gt;
  
  
  Comments
&lt;/h2&gt;

&lt;p&gt;When I first started programming many years ago, I fell foul of over-commenting my code. It's a trap all new developers fall into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// declare integer variable&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// initialize to zero;&lt;/span&gt;

&lt;span class="c1"&gt;// declare string&lt;/span&gt;
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a natural tendency to do this when you're new because you are learning. Commenting like this is akin to note-taking. It might be useful short term but in the long term it just adds unnecessary noise.&lt;/p&gt;

&lt;p&gt;I prefer to comment only in a few instances. &lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;code logic that is unable to explain itself adequately.&lt;/li&gt;
&lt;li&gt;interfaces - using a &lt;code&gt;&amp;lt;summary&amp;gt;&lt;/code&gt; boilerplate on interface methods.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Customer's FTP server has intermittent network connection issues. &lt;/span&gt;
&lt;span class="c1"&gt;// Retry a few times before giving up.&lt;/span&gt;

&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;failCount&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_ftp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;failCount&lt;/span&gt;&lt;span class="p"&gt;++;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;failCount&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you aren't confused by what a piece of code is doing, but rather why it's doing it at that moment, then a comment should be added. In the example above, the code is telling us a file is being uploaded over FTP - but it may not be obvious why the &lt;code&gt;while&lt;/code&gt; loop is being used.&lt;/p&gt;

&lt;p&gt;The comment is valuable here is it explains the reasoning as to why the logic has been implemented in this way.&lt;/p&gt;




&lt;p&gt;Thank you to all who have followed and liked my posts - I will be back with more soon! 🤓&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Clean Code – Part 1</title>
      <dc:creator>Dalbir Singh</dc:creator>
      <pubDate>Mon, 24 Aug 2020 00:25:55 +0000</pubDate>
      <link>https://dev.to/dalbirsingh/clean-code-part-1-378n</link>
      <guid>https://dev.to/dalbirsingh/clean-code-part-1-378n</guid>
      <description>&lt;p&gt;Clean code is akin to keeping your home/workspace tidy. Cleaning requires effort, whereas leaving garbage doesn’t.&lt;/p&gt;

&lt;p&gt;While I’d love to mention some examples of poor code I’ve seen over the years, I too have fallen foul in the past.&lt;/p&gt;

&lt;p&gt;Clean code isn't about vanity! Large messy un-refactored code only adds to technical debt. When another developer works with the same code you’ll have to double the time for them to complete the task due to messy code. Bear in mind time and effort can quickly grow exponentially as each developer hacks and contributes to the same messy code.&lt;/p&gt;

&lt;p&gt;Below are suggestions to help keep our code clean.&lt;/p&gt;

&lt;h2&gt;
  
  
  Move hard-coded values to the database
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Instead of this…&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F190de71awtrnm92cscsp.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F190de71awtrnm92cscsp.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
do this...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq6jjcpog11w5dmale5p2.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq6jjcpog11w5dmale5p2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
It’s very easy to write constants such as tax rates and bool switches directly into your code without thinking about the long term repercussions. I’m referring to changing values.&lt;/p&gt;

&lt;p&gt;In cases like these it is far better to move these values into a database table, or at the very least the application configuration file. This way it will be much quicker and safer to make changes as opposed to opening up the code many years later and making changes, compiling and then praying its works while you upload… you get the idea.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Guard Clauses
&lt;/h2&gt;

&lt;blockquote&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv29di9kbfl398ud8q1xq.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv29di9kbfl398ud8q1xq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Guard clauses follow the fail-fast principle. In the example above I’m performing a null check on the injected &lt;code&gt;IEmailService&lt;/code&gt; reference supplied to the constructor (assume I’m using DI). If the reference is null, a related exception will be thrown during runtime.&lt;/p&gt;

&lt;p&gt;Dealing with null references is an act of life for any developer. Using guard clauses throughout your code promotes error checking and is a good habit to develop.&lt;/p&gt;

&lt;p&gt;Eagle eyed developers may have noticed I’ve compacted an IF statement to one line. You don’t have to do this, but I find it creates less noise and is more succinct.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Choosing appropriate class names
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Poor class names…&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5rxbd8kmgcr8b6ufzoow.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5rxbd8kmgcr8b6ufzoow.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Class names typically work best when they are nouns. However in more complex scenarios as shown above it is easy to fall foul of this when you need to describe two related classes.&lt;/p&gt;

&lt;p&gt;Here’s one solution to fix this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fflafkteguf3dqqvguyvx.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fflafkteguf3dqqvguyvx.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is much cleaner and concise. I’ve used inheritance by creating a base class of &lt;code&gt;Customer&lt;/code&gt; and then deriving two subclasses from it. In this instance, it allows for shorter class names since there is some context through the inheritance.&lt;/p&gt;

&lt;p&gt;As a final note, I’m not a fan of using inheritance-based models everywhere throughout a solution unless there is a valid case as illustrated above. It can add to unnecessary complexity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thanks for reading! 🙂&lt;/p&gt;

&lt;p&gt;Part 2 is available here:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;div class="ltag__link__content"&gt;
    &lt;div class="missing"&gt;
      &lt;h2&gt;Article No Longer Available&lt;/h2&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>csharp</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>webdev</category>
    </item>
    <item>
      <title>C# - Handy Features</title>
      <dc:creator>Dalbir Singh</dc:creator>
      <pubDate>Fri, 21 Aug 2020 21:28:43 +0000</pubDate>
      <link>https://dev.to/dalbirsingh/c-handy-features-58a7</link>
      <guid>https://dev.to/dalbirsingh/c-handy-features-58a7</guid>
      <description>&lt;p&gt;C# has been improved greatly over the years with useful features that have increased productivity for developers.&lt;/p&gt;

&lt;p&gt;Below I’ll explain a few of my favorite features.&lt;/p&gt;

&lt;h2&gt;
  
  
  String Interpolation
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;In many programming languages, writing a string with embedded variables can be cumbersome. The longer the string, the more noise is added affecting readability like so:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsd5asypxwm9n9r79vg7u.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsd5asypxwm9n9r79vg7u.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;C# 6.0 introduced a new string interpolation feature in which the variables can be written as expressions without the need for awkward string concatenation:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk4oi9mhf6wtx7dnzfu6g.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk4oi9mhf6wtx7dnzfu6g.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This results in the same output, but the code is much easier to read and maintain. To use this feature the string must begin with the $ symbol . String formatters may also be applied as shown in the &lt;code&gt;Score&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;As a plus – expressions will be highlighted within the whole string for better visibility in Visual Studio.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Expression-bodied function members
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;If you’ve created a few C# POCO classes over the years, I’m willing to bet many of the properties you’ve written are single read only statements.&lt;/p&gt;

&lt;p&gt;Here’s a typical example where &lt;code&gt;FullName&lt;/code&gt; is a read only property:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9zlok7ys8cbt3jfg4qbi.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9zlok7ys8cbt3jfg4qbi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;...And now here’s the same example using the &lt;code&gt;FullName&lt;/code&gt; property as an expression-bodied function member:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe9eqqfo2oexa11pczuqy.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe9eqqfo2oexa11pczuqy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The output is identical to the previous example. The code has been compacted down to one line, reducing noise.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Null-conditional operators
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Null checking is an important subject for producing stable apps. Until now, null checking has often been verbose. Here’s a typical null checking statement combined with a ternary operator:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9a9tdyltmdivn2hbm03x.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9a9tdyltmdivn2hbm03x.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With C# 6.0 null checking becomes more succinct:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0zy8zyo8s54kqx8yjcwk.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0zy8zyo8s54kqx8yjcwk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example the variable &lt;code&gt;firstName&lt;/code&gt; is assigned null if the person object is null. If the person object is not null, the value of the &lt;code&gt;FirstName&lt;/code&gt; property will be applied. This works thanks to the &lt;code&gt;?&lt;/code&gt; operator.&lt;/p&gt;

&lt;p&gt;But what if we want to supply a substituted value for null values, similar to the ternary operator approach? &lt;/p&gt;

&lt;p&gt;This can be solved by using the null coalescing operator:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5gc90m2wxr44dzhxnk3i.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5gc90m2wxr44dzhxnk3i.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, the expression always returns a string. The rules of the &lt;code&gt;?&lt;/code&gt; operator ensure that the left-hand side of the operator is evaluated only once.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy Coding 🤓&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>beginners</category>
      <category>dotnet</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Build a Web Console with ASP.NET and SignalR</title>
      <dc:creator>Dalbir Singh</dc:creator>
      <pubDate>Sun, 16 Feb 2020 14:06:11 +0000</pubDate>
      <link>https://dev.to/dalbirsingh/build-a-web-console-with-asp-net-and-signalr-45jp</link>
      <guid>https://dev.to/dalbirsingh/build-a-web-console-with-asp-net-and-signalr-45jp</guid>
      <description>&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/dalbir-burhm/embed/PoqNGKw?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What is it?
&lt;/h2&gt;

&lt;p&gt;Web consoles are often featured on AWS and Azure. They offer meaningful feedback via output messages while executing time-consuming tasks.&lt;/p&gt;

&lt;p&gt;I had to build something similar for a client recently and did some prototyping using ASP.NET with SignalR.&lt;/p&gt;

&lt;p&gt;There are many articles on the web describing how SignalR works - and some useful examples that involve creating a chat server/client. Rather than getting bogged down in the details, I think it would be helpful to see SignalR in action.&lt;/p&gt;

&lt;p&gt;I've uploaded my 'web console' prototype project to Github, which is a simpler implementation of SignalR with ASP.NET.&lt;/p&gt;

&lt;p&gt;If you work with ASP.NET and are curious about web consoles feel free to download and have a play. &lt;/p&gt;

&lt;p&gt;Documentation can be found within the &lt;em&gt;Readme&lt;/em&gt; on GitHub. 😉&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i3JOwpme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/dalbir-singh"&gt;
        dalbir-singh
      &lt;/a&gt; / &lt;a href="https://github.com/dalbir-singh/signalr-web-console"&gt;
        signalr-web-console
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A web based output console for displaying progress messages when executing tasks using ASP.NET C# and SignalR
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
signalr-web-console&lt;/h1&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/dalbir-singh/signalr-web-consoleContent/images/console.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SlyQaAto--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/dalbir-singh/signalr-web-consoleContent/images/console.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A web based output console for displaying progress messages when executing tasks using ASP.NET C# and SignalR.&lt;/p&gt;
&lt;h1&gt;
What is it?&lt;/h1&gt;
&lt;p&gt;This repository contains a simple ASP.NET web application using SignalR to send status/progress messages to the client.&lt;/p&gt;
&lt;p&gt;This feature is useful when a user triggers one or more time consuming backend processes, usually between 10-30 seconds.&lt;/p&gt;
&lt;p&gt;In addition to just displaying messages, the project includes a console for printing the messages a.k.a web console.&lt;/p&gt;
&lt;p&gt;Do note, the console is read-only  - for printing messages.&lt;/p&gt;
&lt;h1&gt;
How to run&lt;/h1&gt;
&lt;p&gt;Clone the repo, restore nuget packages (clean &amp;amp; build) and run!&lt;/p&gt;
&lt;p&gt;(ASP.NET - 4.7.2 .Net Framework)&lt;/p&gt;
&lt;h1&gt;
How does it work?&lt;/h1&gt;
&lt;p&gt;When you launch the project, a page will load with a button and a console window.&lt;/p&gt;
&lt;p&gt;When you click on the button, an AJAX request will be posted to the server and time consuming tasks will be simulated. As each task completes…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/dalbir-singh/signalr-web-console"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>devops</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Building and Testing Webhooks with RequestBin</title>
      <dc:creator>Dalbir Singh</dc:creator>
      <pubDate>Sat, 01 Feb 2020 16:22:23 +0000</pubDate>
      <link>https://dev.to/dalbirsingh/building-and-testing-webhooks-with-requestbin-ko</link>
      <guid>https://dev.to/dalbirsingh/building-and-testing-webhooks-with-requestbin-ko</guid>
      <description>&lt;p&gt;I'd like to share with you all an invaluable online tool I've used over the years for Webhook integrations. It's called &lt;strong&gt;RequestBin&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this article I will discuss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How Webhooks work (short primer)&lt;/li&gt;
&lt;li&gt;A typical Webhook example (using Paypal)&lt;/li&gt;
&lt;li&gt;Webhook Development using RequestBin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  How Webhooks work
&lt;/h4&gt;

&lt;p&gt;In most cases, when your application interacts with a third-party API it behaves as the client making the request and receiving responses. However, in some cases a third-party service may wish to post some data directly to your application at any time. &lt;/p&gt;

&lt;p&gt;To facilitate this, you'll need to setup an endpoint within your application which can accept a GET/POST HTTP request. This is known as a webhook, and once it is setup you'll need to provide the full webhook url to the third-party service so they know where to send the HTTP request to.&lt;/p&gt;

&lt;p&gt;Many third-party API services utilize Webhooks from Messaging to Payment Gateways.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  A typical Webhook Scenario: Paypal IPN Webhook
&lt;/h4&gt;

&lt;p&gt;I'm going to walk you through a typical webhook scenario using Paypal integration. &lt;/p&gt;

&lt;p&gt;Imagine in your web application you have built a shopping cart which uses PayPal for processing payments. Assume you have setup a Webhook (endpoint) within your application that will accept and handle a HTTP POST request...&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faxlkbqui0r2prcnusomq.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faxlkbqui0r2prcnusomq.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;The customer creates an order and clicks on the checkout button. They are redirected to Paypal to make payment.&lt;/li&gt;
&lt;li&gt;The customer authorizes the payment by clicking on the 'Pay' button on the Paypal website. Paypal does two things; 

&lt;ul&gt;
&lt;li&gt;Generate a IPN (HTTP POST request) to your webhook with payment status information eg.(&lt;code&gt;'OK'&lt;/code&gt;, &lt;code&gt;'DECLINED'&lt;/code&gt;), &lt;/li&gt;
&lt;li&gt;Redirect the customer back to your web application. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;When the customer is redirected back to your web application they can expect to see the result of their payment/order (Whether it was accepted).&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  IPN - Instant Purchase Notification
&lt;/h4&gt;

&lt;p&gt;Paypal has a webhook feature called IPN; &lt;a href="https://developer.paypal.com/docs/ipn/" rel="noopener noreferrer"&gt;Instant Purchase Notification&lt;/a&gt;. Put simply, after a customer makes a payment it will generate a HTTP POST request to your web application (your webhook endpoint). The body of the HTTP POST request will contain information on the payment status of that order.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F146wc5fdekr9zfyz4g0d.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F146wc5fdekr9zfyz4g0d.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Paypal configuration setting for IPN. The 'Notification URL' refers to the webhook endpoint in your web application; the IPN HTTP POST will be sent to this url.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When your webhook receives an IPN HTTP POST request, it's up to your application/back-end on what to do next with this information. Paypal IPN only has one task; to send a HTTP POST to your webhook containing payment information. Typically, once your webhook receives the IPN request you would update the order in your database with the payment status result.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Webhook Development using RequestBin
&lt;/h4&gt;

&lt;p&gt;Let's use another scenario...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Scenario:&lt;/strong&gt; You have received a new requirement to integrate a third-party internet service eg.(Payment Gateway) into your business web application.&lt;/p&gt;

&lt;p&gt;As you read the third-party integration guides you soon discover that you'll need to build a webhook endpoint that can accept HTTP POST requests from the third-party to your web application.&lt;/p&gt;

&lt;p&gt;The third party has simulation tools you can use to trigger a HTTP POST request to your webhook endpoint for testing purposes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One of the tricky aspects of building and testing webhooks is due to network connectivity eg.(Firewalls). Initially, you will build, experiment and test the webhook locally on your dev machine but that represents a problem. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How could the webhook running on your dev machine 'receive' the HTTP POST from the third-party?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;...or put another way, how could the HTTP POST request from the third-party reach your dev machine over the internet?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Depending on your environment you have a few options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If you're working from home you could enable port forwarding on your router to redirect HTTP/HTTPS traffic to your local dev machine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you're working in the office, your dev machine will be much more isolated from incoming connections via the internet. Also, while special traffic policies could be put in place to allow incoming traffic for local dev machine good luck getting the sysadmin to agree to that! 🤭&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;dev:&lt;/strong&gt; so if you could just setup a custom traffic policy allow incoming HTTP/HTTPs connections to reach the webhook on my dev machine, that would be great! 🙂&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;sysadmin:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/i1JSXl0MfeRd6/giphy-downsized.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/i1JSXl0MfeRd6/giphy-downsized.gif" alt="sysadmin: NOPE"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Neither option is desirable from a network security standpoint, especially long term.&lt;/p&gt;

&lt;p&gt;If only there was a way you could create a disposable container on the internet that collects every type of HTTP request (GET/POST/PUT) sent to it. This container could have a unique url which you can then supply to third-party services for webhook development.&lt;/p&gt;

&lt;p&gt;It would essentially be a &lt;strong&gt;bin&lt;/strong&gt; of &lt;strong&gt;requests&lt;/strong&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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5fnuqtftuoch9l85hv73.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5fnuqtftuoch9l85hv73.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://requestbin.com/" rel="noopener noreferrer"&gt;RequestBin.com&lt;/a&gt; does exactly this!&lt;/p&gt;

&lt;p&gt;I'll show you how to setup a bin, simulate sending HTTP requests to the bin and finally inspecting the requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a bin&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://requestbin.com/" rel="noopener noreferrer"&gt;RequestBin.com&lt;/a&gt; and click on the blue button 'Create Request Bin' (uncheck 'Private').&lt;/li&gt;
&lt;li&gt;A disposable bin will be generated with a unique endpoint url. You'll send HTTP requests to this url and see them arrive instantly:&lt;/li&gt;
&lt;/ol&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F873kt3pbqzw5c6djtbfz.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F873kt3pbqzw5c6djtbfz.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sending a HTTP request&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You can use any HTTP client such as &lt;a href="https://www.getpostman.com/" rel="noopener noreferrer"&gt;Postman&lt;/a&gt; to send a HTTP request to the bin.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I'll be using a HTTP Request simulator provided by &lt;a href="https://reqbin.com/" rel="noopener noreferrer"&gt;ReqBin.com&lt;/a&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2hp0uj32x0ak8ds0a78r.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2hp0uj32x0ak8ds0a78r.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You'll need to paste the endpoint url of the bin. In my case I am posting JSON so I have set the content type to &lt;code&gt;application/json&lt;/code&gt; and added a payload with order payment information (you can add whatever valid JSON you like).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you're ready hit the send button and watch the bin very closely - you should see the request immediately appear: &lt;/p&gt;&lt;/li&gt;
&lt;/ol&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkuyjhgkl28l8st03v7mx.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkuyjhgkl28l8st03v7mx.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There it is... pretty neat!&lt;/strong&gt; - With this approach, there are no messy firewall issues to contend with, it just works. You can drill down to greater details of every HTTP request such as headers.&lt;/p&gt;

&lt;p&gt;There is no substitute for testing a webhook against your actual web application, but using RequestBin can make the development much easier. You could copy the requests you receive in the bin into the Postman app and then initiate a HTTP request to the webhook hosted on your local machine for a close test.&lt;/p&gt;

&lt;p&gt;Finally, there are some other tangible benefits using these types of bins:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Investigation, R&amp;amp;D&lt;/strong&gt; - Integrating third-party services takes an enormous amount of time and resources. Because of this developers and stakeholders will be keen to test/play with sandbox integrations before fully committing to doing the work. Bins like &lt;a href="https://requestbin.com/" rel="noopener noreferrer"&gt;RequestBin.com&lt;/a&gt; enable one to quickly interact with third-party webhooks without having to write any code or setup/configure networking infrastructure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Troubleshooting&lt;/strong&gt; -  With any type of third-party integration they'll always be some technical hiccups randomly occurring. With RequestBin you have another webhook endpoint completely unrelated to your servers and their network. This can be very useful for debugging issues. For example, suppose you have discovered that there have been no requests coming into your webhooks on the production server for the last several days. &lt;strong&gt;Who's to blame - the production server or the third party?... A request bin will reveal!&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'll leave you with a list of recommended request bins, best of luck with your webhook integrations 👍&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bins/Tools&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://requestbin.com/" rel="noopener noreferrer"&gt;https://requestbin.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://requestbin.net/" rel="noopener noreferrer"&gt;https://requestbin.net/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reqbin.com/" rel="noopener noreferrer"&gt;https://reqbin.com/&lt;/a&gt; (Used for generating HTTP requests)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>testing</category>
      <category>api</category>
      <category>web</category>
    </item>
    <item>
      <title>Is XML Dead?</title>
      <dc:creator>Dalbir Singh</dc:creator>
      <pubDate>Wed, 29 Jan 2020 22:21:49 +0000</pubDate>
      <link>https://dev.to/dalbirsingh/is-xml-dead-1ill</link>
      <guid>https://dev.to/dalbirsingh/is-xml-dead-1ill</guid>
      <description>&lt;p&gt;Today I was asked to provide technical consultation for a customer involving the generation of an XML document.&lt;/p&gt;

&lt;p&gt;These days we developers play with JSON, but it is worth noting XML played some influence with JSON’s global adoption. You’ll often hear a lot talk about data models, sequences, markup and so forth in the JSON community – lessons that were learned from putting together XML standards.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;catalog&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;book&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"bk101"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;author&amp;gt;&lt;/span&gt;Gambardella, Matthew&lt;span class="nt"&gt;&amp;lt;/author&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;XML Developer's Guide&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;genre&amp;gt;&lt;/span&gt;Computer&lt;span class="nt"&gt;&amp;lt;/genre&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;/book&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;book&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"bk102"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;author&amp;gt;&lt;/span&gt;Ralls, Kim&lt;span class="nt"&gt;&amp;lt;/author&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Midnight Rain&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;genre&amp;gt;&lt;/span&gt;Fantasy&lt;span class="nt"&gt;&amp;lt;/genre&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;price&amp;gt;&lt;/span&gt;5.95&lt;span class="nt"&gt;&amp;lt;/price&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;/book&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/catalog&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s been a while since I authored an XML document – I was reminded how the data structures are easier to read and understand. That’s not to say JSON isn’t readable, its just that with XML and it’s SGML derivatives the model is easier to comprehend, initially at least.&lt;/p&gt;

&lt;p&gt;When I started thinking about how to parse XML documents again, It was then I was reminded why JSON is loved. While XML presents the data in an immediately readable format, JSON presents the data in an easily digestible format for your application code. No need, for complex XPath queries, just bind it to your internal model and your done!&lt;/p&gt;

&lt;p&gt;If JSON is the preferred choice for data transfer within applications, does XML have anything left to offer?&lt;/p&gt;

&lt;h4&gt;
  
  
  Yes – documents…
&lt;/h4&gt;

&lt;h2&gt;
  
  
  XSLT
&lt;/h2&gt;

&lt;p&gt;XSLT (&lt;em&gt;eXtensible Stylesheet Language Transformations&lt;/em&gt;) is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk0udsnomr2vy2hu4tfxv.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk0udsnomr2vy2hu4tfxv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Example of XML/XSLT:&lt;/strong&gt; In the image above you can see an example of XML and XSLT working together. The XSLT file uses XPath queries to lift information out of the XML document and render the content using templates. The output is shown below.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;XML still works best for documents. Documents by their nature have a form of structure that is represented better through XML.&lt;/p&gt;

&lt;p&gt;Combine XML with XSLT and you’re able to perform impressive transformations with nothing more than .xml and .xsl files.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, Is XML Dead?
&lt;/h2&gt;

&lt;p&gt;Not yet – XML still has its place for document-based structures. Also many financial institutions rely heavily on XML based formats for transferring information between enterprise systems that were built in the 2000s.&lt;/p&gt;

&lt;p&gt;It’s well known financial enterprises such as Banks are reluctant to ‘upgrade’ their systems unless they really need to. So XML may not be the new kid on the block, and relegated to more mundane infrastructure but it’s still alive and kicking. 🤓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What about you?&lt;/strong&gt; - Do you still use XML day to day?&lt;/p&gt;

</description>
      <category>xml</category>
      <category>json</category>
      <category>discuss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>SMSS -'Connect to Server' Hell</title>
      <dc:creator>Dalbir Singh</dc:creator>
      <pubDate>Tue, 28 Jan 2020 23:01:57 +0000</pubDate>
      <link>https://dev.to/dalbirsingh/smss-connect-to-server-hell-2dia</link>
      <guid>https://dev.to/dalbirsingh/smss-connect-to-server-hell-2dia</guid>
      <description>&lt;p&gt;If you've used Microsoft SQL Management Studio long enough you've probably encountered the connection dialog box from hell.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connection settings randomly disappearing
&lt;/h2&gt;

&lt;p&gt;No matter which version of SMSS you use, there's an inconsistent behaviour with it remembering SQL Server connections -  applies to all editions.&lt;/p&gt;

&lt;p&gt;Sometimes, your last used database server connection settings will be remembered and at other times SMSS will completely forget them. If you're using SMSS on a daily basis and accessing different server instances it can cause much frustration.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix - 'Registered Servers'
&lt;/h2&gt;

&lt;p&gt;Various solutions exist to resolve this, some with mixed results. One of them involves tweaking the entries via the registry - no thanks! 🙄&lt;/p&gt;

&lt;p&gt;The other, is much simpler using SMSS's Registered Servers feature:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First, fire up SMSS - bypass the 'connect to server' dialog box, you won't need to be connected to a database instance for this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then navigate to View -&amp;gt; Registered Servers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right click on the 'Local Server Group' folder and select 'New Server Registration'.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ljr0nifc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d8h2t6jdqz59xed517fc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ljr0nifc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d8h2t6jdqz59xed517fc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter the SQL Server instance connection details:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AaJ5rhaG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4fuibyl1wau6l0kypfze.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AaJ5rhaG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4fuibyl1wau6l0kypfze.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can repeat this process and add as many SQL Database connections as you like here.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mCIuHSsv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ehqhxx9bhh2s2t9f6jtm.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mCIuHSsv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ehqhxx9bhh2s2t9f6jtm.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once all your connections have been entered into the 'Registered Servers' feature, the connections will be available in the SMSS 'Connect to server' dialog. &lt;/p&gt;

&lt;p&gt;and that's it - no more missing connection settings 😎&lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>devops</category>
      <category>azure</category>
    </item>
  </channel>
</rss>
