<?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: Imran Khan</title>
    <description>The latest articles on DEV Community by Imran Khan (@imrank404).</description>
    <link>https://dev.to/imrank404</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%2F789364%2F28326381-449d-4c04-97b4-6737ee0bb626.png</url>
      <title>DEV Community: Imran Khan</title>
      <link>https://dev.to/imrank404</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imrank404"/>
    <language>en</language>
    <item>
      <title>TDD: Write Quality Code, One Test at a Time</title>
      <dc:creator>Imran Khan</dc:creator>
      <pubDate>Sun, 03 Sep 2023 18:29:02 +0000</pubDate>
      <link>https://dev.to/imrank404/tdd-write-quality-code-one-test-at-a-time-495i</link>
      <guid>https://dev.to/imrank404/tdd-write-quality-code-one-test-at-a-time-495i</guid>
      <description>&lt;h2&gt;
  
  
  Why even test code
&lt;/h2&gt;

&lt;p&gt;Building software is not like constructing a building where you build it and just forget about it. A software has to keep up with new feature requests, bug fixes, latest trends, etc. I won't be wrong when I say building and maintaining a software involves a ton of blood, sweat (but mostly tears).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.&lt;/p&gt;

— &lt;cite&gt;Weinberg's Second Law&lt;/cite&gt;

&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Benefits of testing
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Confidence

&lt;ul&gt;
&lt;li&gt;Well written code helps the team have confidence when making a change to the codebase that this change will not break the system.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Converts business logic to code

&lt;ul&gt;
&lt;li&gt;Testing is essentially automatically validating if the software produced fulfils the business requirements or not.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fd33wubrfki0l68.cloudfront.net%2F0f40a4fcf3d9f74d5cdf3f20b9a027b8d049cc0f%2Fa2948%2Fimg%2Fblog%2Ftdd%2Fintro%2Ftdd-start-with-acceptance-test.svg" width="682" height="276"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Reduce development cost

&lt;ul&gt;
&lt;li&gt;As a software grows, it gets worked on by a lot of people. Writing test ensures that every change is approved by the requirements and non-compliant code is blocked right at the source.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Detect failures before they even happen

&lt;ul&gt;
&lt;li&gt;Testing helps detect issues even before they reach the end user. This helps improve the quality assurance from the team as bad code is not shipped in the first place.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is why testing your code is more important than ever, and TDD (Test-driven Development) helps us achieve precisely that. TDD is key practice of &lt;a href="https://en.wikipedia.org/wiki/Extreme_programming" rel="noopener noreferrer"&gt;Extreme Programming&lt;/a&gt; that enables software engineers to have some degree of confidence that their code will work as expected in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does TDD work
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmethodpoet.com%2Fwp-content%2Fuploads%2F2022%2F02%2Ftdd-1024x710.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmethodpoet.com%2Fwp-content%2Fuploads%2F2022%2F02%2Ftdd-1024x710.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As stated by &lt;a href="https://en.wikipedia.org/wiki/Robert_C._Martin" rel="noopener noreferrer"&gt;Robert "Uncle Bob" Martin&lt;/a&gt;, TDD uses the Red ⇨ Green ⇨ Refactor cycle to write code. The goal is to keep the code changes as short as possible by writing the minimum amount of code while maintaining the existing functionality.&lt;/p&gt;

&lt;p&gt;Let's see the actions involved in each step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Red&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Write a failing test.&lt;/li&gt;
&lt;li&gt;No production code should be written before this step.&lt;/li&gt;
&lt;li&gt;Ideally, you should have only one failing test at a time.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Green&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Write just enough code to pass the test.&lt;/li&gt;
&lt;li&gt;Future scenarios should be avoided in this step.&lt;/li&gt;
&lt;li&gt;Prematurely optimizing your code here would introduce unnecessary complexity and might diverge your intent.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Refactor&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Criticize and refactor the code.&lt;/li&gt;
&lt;li&gt;Refactoring the code should not have any effect to the test result.&lt;/li&gt;
&lt;li&gt;As no one is good enough to write the working code and the most optimum code in the first go, optimizations should be reserved for this step.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Benefits of TDD
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Clarity of intent

&lt;ul&gt;
&lt;li&gt;As you write the purpose of the production code first, in the test in the form of a failing test, you have a clear intent of how the code should behave.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;No unused code

&lt;ul&gt;
&lt;li&gt;As the Red ⇨ Green ⇨ Refactor cycle requires you to write only as much code as necessary to pass a test, you avoid writing code for scenarios that might never happen.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Less debugging

&lt;ul&gt;
&lt;li&gt;Since ideally, all the scenarios will be tested while testing and development, there is little to no effort spent on debugging&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Easier to maintain

&lt;ul&gt;
&lt;li&gt;As all the components are tested in an isolated environment, a component's inner working can be changed completely while keeping the input and output same.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Saves cost in the long run

&lt;ul&gt;
&lt;li&gt;As TDD makes us write tests before writing any production code, these tests stand guard against breaking changes, thereby reducing possibility of bugs and enabling timely delivery of software.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Immediate feedback loop

&lt;ul&gt;
&lt;li&gt;Since you write the tests first, any code that does not contribute in fulfilling the business requirement is discarded at source. This helps you keep check of useful and useless code.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Tests document the code

&lt;ul&gt;
&lt;li&gt;Though documentation itself is a very important aspect of software engineering, tests could be a very good starting point stating how the software is expected to be used.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, with the knowledge of TDD (Test-driven Development), will you choose the blue pill and go back to continue making buggy software or will you choose the red pill and start creating better tested, extensible and maintainable software.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsuade.org%2Fcontent%2Fimages%2F2020%2F12%2Ftdd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsuade.org%2Fcontent%2Fimages%2F2020%2F12%2Ftdd.jpg" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>testing</category>
      <category>tdd</category>
      <category>webdev</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Evolution from Programmer to Software Engineer</title>
      <dc:creator>Imran Khan</dc:creator>
      <pubDate>Sun, 27 Aug 2023 18:32:16 +0000</pubDate>
      <link>https://dev.to/imrank404/evolution-from-programmer-to-software-engineer-59mo</link>
      <guid>https://dev.to/imrank404/evolution-from-programmer-to-software-engineer-59mo</guid>
      <description>&lt;p&gt;Aren't those two synonyms. No, they're not. A Software Engineer is the superset of a Programmer. Let's dive deep into how exactly they differ.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the difference
&lt;/h2&gt;

&lt;p&gt;Well, a programmer is generally someone who's good at creating stuff through the means of code. When they get a specification to create something, they start writing code with a certain use case in mind. This is not much of a problem when you are working in smaller teams or building projects of your own. However, the moment you start working on projects where a good number of teammates are involved, you'll quickly find yourself under a big pile of code because to change one thing, 5 other things need to be modified.&lt;/p&gt;

&lt;p&gt;A software engineer on the other hand, will question themself at each step of the process, ensuring that anything they change will be understood unambiguously by the next person who happens to encounter this change.&lt;/p&gt;

&lt;p&gt;There are no steps set in stone that one could follow to transition from a programmer to software engineer, but one can inculcate the following qualities/habits that are often found in good software engineers&lt;/p&gt;

&lt;h2&gt;
  
  
  Think solutions, not code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk8fcwzki69h3wqk0tczq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk8fcwzki69h3wqk0tczq.gif" alt="Think solutions, not code" width="300" height="162"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The most recurring mistake programmers do is immediately think in terms of code when presented with a problem. This approach does not scale well because there are a lot of black boxes at the early stages of any project. These black boxes might introduce features that could render your approach unusable.&lt;/p&gt;

&lt;p&gt;Hence, it is crucial to think in terms of entities, their responsibilities and the flow of information between these entities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start small
&lt;/h2&gt;

&lt;p&gt;To think solutions, start by approaching the most basic version of your problem. This will enable you to eliminate majority of the known and unknown variables alike from your solution.&lt;/p&gt;

&lt;p&gt;Tackling your problem in isolation allows you to focus on the core components of the problem. Create a solution for this version then incrementally keep on increasing the set of requirements and rinse &amp;amp; repeat.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docs come before code
&lt;/h2&gt;

&lt;p&gt;The importance of documenting a solution before attempting it is arguably the most important step in developing a project. Practices like dry running approaches and writing pseudocode are worth the overhead that they bring to the table.&lt;/p&gt;

&lt;p&gt;As any programming language has its own set of rules and limitations, changing documentation is so much easier than changing code.&lt;/p&gt;

&lt;p&gt;So next time, before you jump straight to coding a solution, try writing the approach first and you might find issues early on that might have stayed hidden for weeks.&lt;/p&gt;

&lt;p&gt;Note: This is an extension of the &lt;a href="https://en.wikipedia.org/wiki/Rubber_duck_debugging" rel="noopener noreferrer"&gt;Rubber Duck Debugging&lt;/a&gt; technique.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set goals
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffcb4znsmxvo56r015s6q.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffcb4znsmxvo56r015s6q.gif" alt="Set goals" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No, I'm not talking about setting up long term goals like a motivational speaker. Setting up goals in the short term means to just write your intent.&lt;/p&gt;

&lt;p&gt;People don't realize that just writing down the next 3 steps that you want to take resolves so much of the indecisiveness and introduces a ton of clarity to an approach.&lt;/p&gt;

&lt;p&gt;It does not matter if the approach you tried out failed. You just checkout off one method that you thought would've worked from the "approaches" list. Be willing to start with a clean slate and better understanding in case things go sideways.&lt;/p&gt;

&lt;h2&gt;
  
  
  Be your first reviewer
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2u8iel0to1uxvj64v3q.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2u8iel0to1uxvj64v3q.gif" alt="Be your first reviewer" width="213" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Always be critical of your solutions. Just because you wrote it, does not mean you should assume it would work in a certain way.&lt;/p&gt;

&lt;p&gt;Think of cases where it could fail and be open to corrections from others. It is better if you spot your mistakes before anyone else. After all, who doesn't want to ship bugless products.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose your trade-offs
&lt;/h2&gt;

&lt;p&gt;All decisions in software engineering and by extension in life come with benefits and trade-offs. You have to choose which trade-offs are you okay living with.&lt;/p&gt;

&lt;p&gt;So, if you choose a particular technology to work with, be prepared to work around its limitations. If you choose an approach to solve a problem, get ready to meet some unexpected guests down the implementation road.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqai6y77frjrx237q5ai.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqai6y77frjrx237q5ai.gif" alt="See you soon" width="480" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programmers</category>
      <category>softwareengineering</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
