<?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: Kirill Artamonov</title>
    <description>The latest articles on DEV Community by Kirill Artamonov (@artamonovkirill).</description>
    <link>https://dev.to/artamonovkirill</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%2F489497%2F2136162b-75fc-4545-91c6-683ee6001bb6.jpeg</url>
      <title>DEV Community: Kirill Artamonov</title>
      <link>https://dev.to/artamonovkirill</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/artamonovkirill"/>
    <language>en</language>
    <item>
      <title>Pitfalls of static code analysis: class, function, or method length rules</title>
      <dc:creator>Kirill Artamonov</dc:creator>
      <pubDate>Mon, 23 Nov 2020 13:50:54 +0000</pubDate>
      <link>https://dev.to/artamonovkirill/pitfalls-of-static-code-analysis-class-function-or-method-length-rules-4if7</link>
      <guid>https://dev.to/artamonovkirill/pitfalls-of-static-code-analysis-class-function-or-method-length-rules-4if7</guid>
      <description>&lt;p&gt;Lack of code quality is a re-occurring problem in many software projects, teams, and organizations. &lt;a href="https://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis"&gt;Static code analysis&lt;/a&gt; with a set of simple rules seems like a good solution to the problem.&lt;/p&gt;

&lt;p&gt;There are some pitfalls of static code analysis, and I wanted to share my thoughts about one of the rules: &lt;strong&gt;class, function, or method length restrictions&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The rule
&lt;/h3&gt;

&lt;p&gt;Whenever there's a lengthy fragment of code, there's a problem with it. Most certainly it violates the &lt;a href="https://en.wikipedia.org/wiki/Single-responsibility_principle"&gt;single-responsibility principle&lt;/a&gt;, it is hard to understand and troublesome to update.&lt;/p&gt;

&lt;p&gt;A rule that enforces a hard limit of X lines per code block is a seemingly simple and effective solution. However, it introduces behavior that I would call &lt;strong&gt;mechanical refactoring&lt;/strong&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Mechanical vs. insightful
&lt;/h3&gt;

&lt;p&gt;Mechanical refactorings are happening when something external is enforcing it: e.g., when a certain number of lines is reached and the commit or merge is blocked. They are happening not when talking to domain experts, or when there are new insights arising from working with the code, or when new abstractions are being discovered. To contrast the two types of refactoring, I'd call the latter &lt;strong&gt;insightful refactorings&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Mechanical refactorings require the answer here and now, insightful ones can grow and ripen in people's heads for days or even weeks. The quality of a mechanical refactoring is thus often less than of an insightful one. A quick low-quality mechanical refactoring today might also obstruct the view or make an insightful refactoring harder next time.&lt;/p&gt;

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

&lt;p&gt;If you think there's a problem with the software quality of your product, I'd advise focusing on the people, not on the tools like ones for static code analysis.&lt;/p&gt;

&lt;p&gt;Get your team members excited about clean code, give them time and space to think about the code and the domain, give them time and space to practice writing cleaner code, to experiment with it.&lt;/p&gt;

&lt;p&gt;That's it, happy coding!&lt;/p&gt;

</description>
      <category>cleancode</category>
      <category>staticcodeanalysis</category>
      <category>refactoring</category>
    </item>
    <item>
      <title>Regex: finding repetitions</title>
      <dc:creator>Kirill Artamonov</dc:creator>
      <pubDate>Mon, 23 Nov 2020 13:09:00 +0000</pubDate>
      <link>https://dev.to/artamonovkirill/regex-finding-repetitions-33m9</link>
      <guid>https://dev.to/artamonovkirill/regex-finding-repetitions-33m9</guid>
      <description>&lt;p&gt;Finding repeating characters in a string - whether it's a &lt;a href="https://en.wikipedia.org/wiki/Run-length_encoding"&gt;Run-length encoding&lt;/a&gt; exercise on &lt;a href="https://exercism.io"&gt;exercism.io&lt;/a&gt;, a task during a technical interview, or even a production feature like validating created users passwords - is easily implemented using a simple regular expression.&lt;/p&gt;

&lt;p&gt;The regex feature that we'll need is called "backreference". While the examples below are in JavaScript, this feature is defined as part of the &lt;a href="https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended"&gt;POSIX standard&lt;/a&gt;, so it supported in various other languages.&lt;/p&gt;

&lt;p&gt;Let's get started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;repetitions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;.&lt;/span&gt;&lt;span class="se"&gt;)\1&lt;/span&gt;&lt;span class="sr"&gt;+/g&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's test it out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;repetitions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bookkeeper&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; 
&lt;span class="c1"&gt;// expected output: Array ["oo", "kk", "ee"]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;repetitions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;длинношеее&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;// expected output: Array ["нн", "еее"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. Happy coding and regexing!&lt;/p&gt;

</description>
      <category>regex</category>
    </item>
  </channel>
</rss>
