<?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: Taslim Arif</title>
    <description>The latest articles on DEV Community by Taslim Arif (@tastaslim).</description>
    <link>https://dev.to/tastaslim</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%2F562071%2F51c32986-680a-4d69-a698-c4067932ed67.jpeg</url>
      <title>DEV Community: Taslim Arif</title>
      <link>https://dev.to/tastaslim</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tastaslim"/>
    <language>en</language>
    <item>
      <title>How to Enable Password Authentication in AWS ec2 Instances</title>
      <dc:creator>Taslim Arif</dc:creator>
      <pubDate>Thu, 08 Jun 2023 04:54:25 +0000</pubDate>
      <link>https://dev.to/tastaslim/how-to-enable-password-authentication-in-aws-ec2-instances-40m6</link>
      <guid>https://dev.to/tastaslim/how-to-enable-password-authentication-in-aws-ec2-instances-40m6</guid>
      <description>&lt;p&gt;&lt;strong&gt;The configuration to enable password authentication in AWS instance:-&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Log in to the server using ssh client of your choice using &lt;br&gt;
the private key.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; your-key.pem username@ip_address
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set up a password for the user using passwd command along &lt;br&gt;
with the username.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;passwd ec2-user &lt;span class="c"&gt;# If machine is Amazon Linux&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;passwd ubuntu &lt;span class="c"&gt;# If machine is Ubuntu&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open the sshd_config file.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vi /etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Find the Line containing "PasswordAuthentication" parameter&lt;br&gt;&lt;br&gt;
and change its value from "no" to "yes" &lt;br&gt;
&lt;strong&gt;PasswordAuthentication yes&lt;/strong&gt;&lt;br&gt;
If you want to set up "root" login, find "PermitRootLogin" &lt;br&gt;
parameter and change its value from &lt;strong&gt;prohibit-password&lt;/strong&gt; &lt;br&gt;
to "yes".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now, restart the "sshd" service using the following &lt;br&gt;
command.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;service sshd restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now you can log out and log in using the password you set &lt;br&gt;
for the user.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh ec2-user@ip_address
&lt;span class="c"&gt;# ssh ubuntu@15.1.25.40&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: Although password will be encrypted while communicating with server but it is not recommended to enable the password authentication to connect with EC2 machines using ssh. Easy and common password can be guessed easily using brute force by some malicious user.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What the heck is SSH?</title>
      <dc:creator>Taslim Arif</dc:creator>
      <pubDate>Mon, 05 Jun 2023 03:35:08 +0000</pubDate>
      <link>https://dev.to/tastaslim/what-the-heck-is-ssh-1nc6</link>
      <guid>https://dev.to/tastaslim/what-the-heck-is-ssh-1nc6</guid>
      <description>&lt;h2&gt;
  
  
  What Is SSH
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;SSH, or &lt;strong&gt;Secure Shell&lt;/strong&gt; Protocol, is a remote
administration protocol that allows users to access,
control, and modify their remote servers over the internet&lt;/li&gt;
&lt;li&gt;SSH service was created as a secure replacement for the 
unencrypted Telnet and uses cryptographic techniques to 
ensure that all communication to and from the remote server 
happens in an encrypted manner. It provides a mechanism for
authenticating a remote user, transferring inputs from the 
client to the host, and relaying the output back to the
client.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The SSH command consists of below distinct parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;user:Account which you want to access&lt;/li&gt;
&lt;li&gt;host: computer/server which you want to access (Provide 
IP Address or Domain name)&lt;/li&gt;
&lt;li&gt;Private key if password authentication is not enabled
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;      ssh &lt;span class="o"&gt;{&lt;/span&gt;user&lt;span class="o"&gt;}&lt;/span&gt;@&lt;span class="o"&gt;{&lt;/span&gt;host&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="c"&gt;# given that password policy is enabled&lt;/span&gt;
      ssh &lt;span class="nt"&gt;-i&lt;/span&gt; your_private-key.pem &lt;span class="o"&gt;{&lt;/span&gt;user&lt;span class="o"&gt;}&lt;/span&gt;@&lt;span class="o"&gt;{&lt;/span&gt;host&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="c"&gt;# If password policy is not enabled then key is required&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can check my blog on &lt;a href="https://dev.to/tastaslim/how-to-enable-password-authentication-in-aws-ec2-instances-40m6"&gt;how to enable password authentication for SSH with AWS EC2&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Different Encryption Techniques
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The significant advantage offered by SSH over telnet is the
use of encryption to ensure a secure transfer of information 
between the host and the client. There are three different 
encryption technologies used by SSH:

&lt;ol&gt;
&lt;li&gt;Symmetrical encryption&lt;/li&gt;
&lt;li&gt;Asymmetrical encryption&lt;/li&gt;
&lt;li&gt;Hashing&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the sake this tutorial, we will not discuss One way Hashing for encryption.&lt;/p&gt;




&lt;h2&gt;
  
  
  Symmetrical Encryption
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3LY27GZG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pldltwgu8h4g5belslh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3LY27GZG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pldltwgu8h4g5belslh.png" alt="Image description" width="684" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Symmetric encryption is a form of encryption where a secret key is used for both encryption and decryption of a
message by both the client and the host. Effectively, anyone possessing the key can decrypt the message being
transferred.&lt;/li&gt;
&lt;li&gt;Symmetrical encryption is often called &lt;strong&gt;shared key&lt;/strong&gt; or &lt;strong&gt;shared secret&lt;/strong&gt; encryption. There is usually only one key
that is used, or sometimes a pair of keys, where one key can easily be calculated using the other key.&lt;/li&gt;
&lt;li&gt;Symmetric keys are used to encrypt the entire communication during an SSH session. Both the client and the server
derive the secret key using an agreed method, and the resultant key is never disclosed to any third party.&lt;/li&gt;
&lt;li&gt;Symmetric key is created using &lt;strong&gt;key exchange algorithm&lt;/strong&gt; such as &lt;strong&gt;AES (Advanced Encryption Standard)&lt;/strong&gt;, &lt;strong&gt;CAST128&lt;/strong&gt;,
&lt;strong&gt;Blowfish&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Asymmetrical Encryption
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fnroyBh0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpuj3foizeumbkkhflc5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fnroyBh0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpuj3foizeumbkkhflc5.png" alt="Image description" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unlike symmetrical encryption, asymmetrical encryption uses two separate keys for encryption and decryption. These two
keys are known as the public key and the private key. Together, both these keys form a public-private key pair.&lt;/li&gt;
&lt;li&gt;A public key can be used by any individual to encrypt a message and can only be decrypted by the recipient who
possesses their particular private key, and vice versa. These consist of extensive and seemingly random combinations
of numbers and symbols, however, both public and private keys are paired using complex mathematical algorithms(&lt;strong&gt;RSA
Algorithm&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;Note that both encryption and decryption mechanisms are automatic processes – you don’t need to do anything manually.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Symmetrical Encryption Pros and Cons
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fast&lt;/li&gt;
&lt;li&gt;Efficient for large Data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hard to share the key(as key should be same at both client and server side, while sharing any hacker can steal the key
information and access your data).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ASymmetrical Encryption Pros and Cons
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Efficient for small Data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security&lt;/strong&gt;: Without both keys, a hacker can only access useless data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transparency&lt;/strong&gt;: Public keys can be openly distributed, as losing them will not devolve into a security risk.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Speed&lt;/strong&gt; : Systems need time for decryption. Users sending plenty of bulk files will have a long wait.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vulnerabilities&lt;/strong&gt;: Lose a private key, and anyone who finds it can read all messages, even if they're private. A
lost key can result in a man-in-the-middle attack too.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loss&lt;/strong&gt;: If you lose your private key, you won't be able to decrypt messages sent to you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Long-term sustainability&lt;/strong&gt;: In the future, quantum computing will break most asymmetric and symmetric approaches.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you see, the problem with symmetrical encryption is the threat to expose the key to some malicious user while sharing&lt;br&gt;
the key info with server but at the same time it is fast and efficient for large data.&lt;br&gt;
In real world, we use combination of best of both encryption algorithms.&lt;/p&gt;


&lt;h2&gt;
  
  
  How Does SSH Work With These Encryption Techniques
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The way SSH works is by making use of a client-server model to allow for authentication of two remote systems and
encryption of the data that passes between them.&lt;/li&gt;
&lt;li&gt;The client must begin the SSH connection by initiating the TCP handshake with the server, ensuring a secured symmetric
connection, verifying whether the identity displayed by the server match previous records (typically recorded in an
RSA key store file), and presenting the required user credentials to authenticate the connection.&lt;/li&gt;
&lt;li&gt;SSH operates on TCP port 22 by default (though SSH port can be changed if needed). The host (server) listens on port 22 (or any other SSH assigned port) for incoming connections. It organises the secure connection by authenticating the client and opening the correct shell environment if the verification is successful.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find the notion behind the mathematical algorithm for ASymmetrical Encryption Technique:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Pq8gNbvfaoM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Session Encryption Negotiation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When a client tries to connect to the server via TCP, the server presents the encryption protocols and respective
versions that it supports. If the client has a similar matching pair of a protocol and version, an agreement is
reached and the connection is started with the accepted protocol. The server also uses an asymmetric public key which
the client can use to verify the authenticity of the host.&lt;/li&gt;
&lt;li&gt;Once this is established, the two parties use what is known as a &lt;strong&gt;Diffie-Hellman Key Exchange Algorithm&lt;/strong&gt; to create a
symmetrical key. This algorithm allows both the client and the server to arrive at a shared encryption key which will
be used henceforth to encrypt the entire communication session.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Here is how the algorithm works at a very basic level:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Both the client and the server agree on a very large prime number, which of course does not have any factor in common.
This prime number value is also known as the seed value.&lt;/li&gt;
&lt;li&gt;Next, the two parties agree on a common encryption mechanism to generate another set of values by manipulating the
seed values in a specific algorithmic manner. These mechanisms, also known as encryption generators, perform large
operations on the seed. An example of such a generator is &lt;strong&gt;AES (Advanced Encryption Standard)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Both the parties independently generate another prime number. This is used as a secret private key for the
interaction.&lt;/li&gt;
&lt;li&gt;This newly generated private key, with the shared number and encryption algorithm (e.g. AES), is used to compute a
public key which is distributed to the other computer.&lt;/li&gt;
&lt;li&gt;The parties then use their personal private key, the other machine’s shared public key and the original prime number
to create a final shared key. This key is independently computed by both computers but will create the same encryption
key on both sides.&lt;/li&gt;
&lt;li&gt;Now that both sides have a shared key, they can symmetrically encrypt the entire SSH session. The same key can be used
to encrypt and decrypt messages (read: section on symmetrical encryption).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that the secured symmetrically encrypted session has been established, the user must be authenticated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authenticating the User
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The final stage before the user is granted SSH access to the server is authenticating his/her credentials. For this,
most SSH users use a password. The user is asked to enter the username, followed by the password.&lt;/li&gt;
&lt;li&gt;These credentials securely pass through the symmetrically encrypted tunnel, so there is no chance of them being
captured by a third party.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Although passwords are encrypted, it is still not recommended to use passwords for secure connections. This is
because many bots can simply brute force easy or default passwords and gain secure shell access to your account.
Instead, the recommended alternative is SSH Key Pairs&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;These are a set of asymmetric keys used to authenticate the user without the need of inputting any password.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you’re wondering how long it takes for a computer to calculate a hash and authenticate a user, well, it happens in&lt;br&gt;
less than a second. &lt;br&gt;
In fact, the maximum amount of time is spent in transferring data across the Internet.&lt;/p&gt;

</description>
      <category>ssh</category>
      <category>networking</category>
      <category>softwareengineering</category>
      <category>security</category>
    </item>
    <item>
      <title>Reasons behind bad Softwares (Technical Debts) and Refactoring</title>
      <dc:creator>Taslim Arif</dc:creator>
      <pubDate>Sun, 26 Sep 2021 11:35:57 +0000</pubDate>
      <link>https://dev.to/tastaslim/reasons-behind-bad-software-code-technical-debts-24f8</link>
      <guid>https://dev.to/tastaslim/reasons-behind-bad-software-code-technical-debts-24f8</guid>
      <description>&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Bad code haunts everyone sooner or later troubling the one who wrote it along with whole team.
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Every developer in the world tries to write good and efficient code. I don't think that there is anyone who writes bad code deliberately.&lt;br&gt;
Then why do we still get bad softwares? Let's look at few reasons for bad code going to production which is generally termed as &lt;strong&gt;Technical Debts&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think of a scenario where you took money from someone on interest, for that time being it solves your problem, right.&lt;br&gt;
But eventually, you have to repay that money to a person with interest. Sometimes, we delay so much in repaying money that the amount of interest gets higher than the actual money which we took from a person which makes it impossible for us to repay the money.&lt;/p&gt;

&lt;p&gt;The same is the case with software development, you write bad code, and keep on shipping it to production and since you were not focusing on improving the code, there will be a time when it becomes impossible for you to refactor/improve your code.&lt;/p&gt;




&lt;h1&gt;
  
  
  Reasons of technical debt
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Business Pressure&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes business pressure forces us to ship unfinished code to production. To make it work, we do some patches here and there and hides them. But this will come back haunting us.&lt;br&gt;
Don't do this, it is okay to get delayed sometimes instead of shipping bad code to production because in a long time it will cost more money and effort to improve it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Developers not taking technical debts seriously or don't understand the importance of it&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is one of the most common cases, I have seen while working at various companies, many developers don't take these things seriously, for them working code is sufficient.&lt;br&gt;
This becomes almost impossible to refactor and improve the code because your employer does not value it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;Lack of Documentation&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Documentation is one of the most important aspects of software development. It doesn't matter how good code have you written, if other developers can't understand, contribute or use it. We must write a good documentation explaining every aspect of your code so that others feel, it is easy to use and they don't need to ask you everytime.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Incompetence&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the developer doesn’t know how to write decent code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lack of knowledge sharing among team members&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When developers don't share their understanding of project with team members, it becomes almost impossible, specially for junior developers to work on it. They work in dark all the time and eventually create problems for themselve as well for whole team.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lack of tests&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The lack of immediate feedback encourages quick, but risky workarounds. In worst cases, these changes are implemented and deployed right into the production without any prior testing. The consequences can be catastrophic. For example, an innocent-looking hotfix might send a weird test email to thousands of customers or even worse, flush or corrupt an entire database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Working in Isolation&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can lead to the accumulation of technical debt, which is then increased when changes are merged. The more changes made in isolation(in your respective branch), the greater the total technical debt because it can cause merge conflict, it is very hard to review it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lack of compliance monitoring&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This happens when everyone working on the project writes code as they see fit. There must be a guideline to follow while writing, documenting, testing and deploying the code.&lt;/p&gt;




&lt;h1&gt;
  
  
  When to refactor your code
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Follow rules of 3 for this.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When you are writing code for the 1st time, just get it done.&lt;/li&gt;
&lt;li&gt;When you are doing something similar for the second time, keep refactoring thought in mind but anyways get it done.&lt;/li&gt;
&lt;li&gt;when you are doing something similar for the third time, start refactoring it.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Adding new feature&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While adding new feature into someone else dirty code, first refactor it and then add new features. It is very easy to understand clean code and add new features into it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When fixing bugs&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Clean your code, you will automatically find bugs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;During code review&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is last and probably the most important part of the refactoring process. After this your code will be going to production. It is always best to do code review in pairs, make sure author is present.&lt;/p&gt;




&lt;h1&gt;
  
  
  How to refactor
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Make sure after refactoring your code should be cleaner than previous on and still all features are working. If code is not cleaner, you have just wasted your time.&lt;/li&gt;
&lt;li&gt;Make sure you have a good understanding of the code you are refactoring.&lt;/li&gt;
&lt;li&gt;Make sure while refactoring, no new functionality should be added in your code. Refactoring and adding new feature are two different things. Once you complete refactoring, then you can add new features.&lt;/li&gt;
&lt;li&gt;Make sure all previous test cases are passing after refactoring.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>codequality</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Clean Code</title>
      <dc:creator>Taslim Arif</dc:creator>
      <pubDate>Sun, 26 Sep 2021 08:24:15 +0000</pubDate>
      <link>https://dev.to/tastaslim/clean-code-1ce</link>
      <guid>https://dev.to/tastaslim/clean-code-1ce</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Any fool can write code that a computer can understand. Good programmers write code that humans can understand.&lt;br&gt;&lt;br&gt;
                                  &lt;strong&gt;– Martin Fowler&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Writing clean, understandable, and maintainable code is a skill that is crucial for every developer to master.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;When I say clean code I mean:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Proper variable name, function name, class name, proper indentation, proper spacing, proper comment, and proper/unique code style throughout the team.&lt;/li&gt;
&lt;li&gt;Minimal number of lines of code, classes, functions, etc. Less code means less headache, fewer bugs, and less maintenance cost.&lt;/li&gt;
&lt;li&gt;No duplication of code. Duplication in your software shows bad software and lack of knowledge.&lt;/li&gt;
&lt;li&gt;It might seem contradictory to my previous point but too much abstraction is also bad. If your abstraction forces you to add more conditions and extra parameters in your method every time a new feature is introduced, it is a bad/wrong abstraction and you should follow the below things:

&lt;ul&gt;
&lt;li&gt;Try to find a way so that every time you introduce a 
new feature, your abstraction should not be affected.
&lt;/li&gt;
&lt;li&gt;Go back to duplication. You heard it right. Duplication 
is always better than wrong abstraction.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Well, I don't see this as a failure of abstraction. It's caused by some specific other failures.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   a. Failure of people to understand data modeling, and the 
      difference between interface and implementation. "A new 
      requirement appears for which the current abstraction 
      is almost perfect. Just because the code is the same 
      doesn't mean it should use the same abstraction. The 
      data model is wrong, not the abstraction.

   b. Failure of people to think of the entire system, when 
      making a change. The rookie mistake is to think that 
      adding one more conditional is always harmless, but, at 
      some point, you've got 3 tons of straw on that poor 
      camel's back. Adding just one more case may have been 
      the correct fix last week, but not this week.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;No magic numbers (A magic number is direct usage of a number in the code). Magic numbers are bad, not readable, hard to maintain and not reusable.&lt;/li&gt;
&lt;li&gt;Minimum/No hard coding. It is bad, not reusable, not testable, and not maintainable. &lt;/li&gt;
&lt;li&gt;Code should pass 100% of test cases(even 99% shows that you are screwed). &lt;/li&gt;
&lt;li&gt;Code is easy and cheap to maintain.&lt;/li&gt;
&lt;li&gt;Mature programmers know that the idea that everything is an object is a myth. Sometimes you really want simple data structures with procedures for your task. So you have to carefully think what to implement also thinking about the future perspective that what will be easy to update.&lt;/li&gt;
&lt;/ul&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Always write concise documentation of your code( classes, functions, properties, etc.)&lt;/strong&gt;&lt;/p&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%2Fuploads%2Farticles%2Fnqp2js1ll1zczzlvk506.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%2Fuploads%2Farticles%2Fnqp2js1ll1zczzlvk506.png" alt="Documentation"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Tips to write clean code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Variable, function, or class names should be descriptive. If it requires a comment to describe what the name does, it's a bad naming convention.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let s; // number of seconds ---&amp;gt; Bad naming convention

Good naming convention:
let numberOfSeconds, customerName, employeeName, mailMessage, mailFolder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Do not include any redundant information/ noise words in naming. Some of noise words:

&lt;ul&gt;
&lt;li&gt;Data&lt;/li&gt;
&lt;li&gt;Object&lt;/li&gt;
&lt;li&gt;Info&lt;/li&gt;
&lt;li&gt;Information&lt;/li&gt;
&lt;li&gt;Variable&lt;/li&gt;
&lt;li&gt;String
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bad naming convention:

userInfo, userData, userVariable, userObject, accountInformation, employeeString etc.

Good naming convention:
user, employee, account etc. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Be consistent&lt;/strong&gt; while naming variables of similar tasks. For example, while naming any variable which stores fetched data from an API call or Database use only one of these:
get, retrieve, fetch. Don't use more than one as they do the same task.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Say you decide to follow get convention:
getUser, getName, getFile, getAccount etc. ==&amp;gt; Good convention
getUser, retrieveAccount, fetchName ===&amp;gt; Bad convention
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Don't use magic numbers(A magic number is a direct usage of a number in the code)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bad convention:
   if(age&amp;gt;=18) "eligible for voting"

Good Convention:
   MINIMUM_AGE_FOR_VOTING=18;
   if(age&amp;gt;=MINIMUM_AGE_FOR_VOTING) "eligible for voting"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Avoid leaving code inside comments because it makes other developers scary to remove them as they don't know whether it is for comment purposes or left to use later.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Always follow the coding style defined by the programming language which you are using. Few conventions in Typescript:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variable name should be in the camel case.&lt;/li&gt;
&lt;li&gt;Function name should be in the camel case.&lt;/li&gt;
&lt;li&gt;Class name should be in pascal case.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Try to follow the DRY (Don't Repeat Yourself) principle.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Function name should be a verb.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Class and variable name should be a noun.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Prefer to use code formatters such as &lt;strong&gt;Prettier&lt;/strong&gt; for better code arrangement.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;People often ask me, what should be maximum length of variable, function or class name. Well my answer to them:&lt;br&gt;&lt;br&gt;
If there's a shorter, but yet descriptive way to name the function, variable or class then your current variable, class or function name is long.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

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

&lt;p&gt;The skill of writing clean code comes from using it again and again in software development. It is the least you should follow while writing a software code.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>codequality</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Circular Linked List:</title>
      <dc:creator>Taslim Arif</dc:creator>
      <pubDate>Sun, 19 Sep 2021 16:24:55 +0000</pubDate>
      <link>https://dev.to/tastaslim/circular-linked-list-4ned</link>
      <guid>https://dev.to/tastaslim/circular-linked-list-4ned</guid>
      <description>&lt;p&gt;If you are not familiar with the &lt;strong&gt;LinkedList&lt;/strong&gt;, I would highly recommend having a look at my blog:&lt;br&gt;&lt;br&gt;
&lt;a href="https://dev.to/tastaslim/an-introduction-to-linked-list-1bmp"&gt;Introduction to Linked List&lt;/a&gt; &lt;/p&gt;



&lt;p&gt;In this tutorial, we will learn circular linked list in-depth by dividing topics in the following manner:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Definition of circular linked list. &lt;/li&gt;
&lt;li&gt;Types of Circular linked list &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Basic Operations on circular linked list &lt;/p&gt;

&lt;p&gt;a) Searching/Traversal &lt;br&gt;
b) Insertion &lt;br&gt;
c) Deletion &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Singly linked list as a circular linked list. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Doubly linked list as a circular linked list. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Applications of circular linked list&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implementation of circular linked list. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;h1&gt;
  
  
  Definition of circular linked list
&lt;/h1&gt;

&lt;p&gt;In a circular linked list, elements are stored in random memory locations. &lt;br&gt;
Similar to a singly linked list, each node of a circular linked list (I meant singly circular linked list) contains two fields: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;data&lt;/strong&gt; stored at that particular address.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pointer&lt;/strong&gt; which contains the address of the next node. &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%2Fuploads%2Farticles%2Fjcv5p77sysmb9hdlmo47.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%2Fuploads%2Farticles%2Fjcv5p77sysmb9hdlmo47.png" alt="Circular Linked List"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unlike, singly linked list in which the last node of the contains a pointer to null to represent the termination of a linked list, in circular linked list, last node of linked list will point to the first node of the linked list. &lt;/p&gt;


&lt;h1&gt;
  
  
  Types of Circular Linked List:
&lt;/h1&gt;

&lt;p&gt;There are two types of Circular linked list. i.e. we can make a circular linked list by modifying the Singly linked list as well as Doubly linked list. &lt;/p&gt;
&lt;h3&gt;
  
  
  1. Singly circular linked list
&lt;/h3&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%2Fuploads%2Farticles%2Fg1j3d29p12kdr9pz57b5.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%2Fuploads%2Farticles%2Fg1j3d29p12kdr9pz57b5.png" alt="Singly Linked List"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above diagram is an example of a singly linked list in which the last node(&lt;strong&gt;Tail&lt;/strong&gt;) points to NULL to represent the termination of the linked list. &lt;br&gt;
To make it a singly circular linked list, you just need to modify the link of the last node. &lt;br&gt;
Instead of pointing it to NULL, We are going to link it with the first(&lt;strong&gt;head&lt;/strong&gt;) node. &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%2Fuploads%2Farticles%2Fjcv5p77sysmb9hdlmo47.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%2Fuploads%2Farticles%2Fjcv5p77sysmb9hdlmo47.png" alt="Circular Linked List"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, one question which might come into your mind is, how do we get to know termination condition, right? &lt;br&gt;
Because, if we don’t apply termination condition our program will run into an infinite loop. Confused? 😕 😕 😕 😕 😕&lt;/p&gt;

&lt;p&gt;Well, one thing you might do is, keep a track of head node and whenever we encounter it again, we say that we have traversed our whole linked list and Now it is time to terminate. &lt;br&gt;
You could have taken a temp=head-&amp;gt;next and start traversing linked list and check for whether our temp is head or not.&lt;/p&gt;

&lt;p&gt;if (temp==head) ===&amp;gt; We have traversed whole linked list. &lt;br&gt;
Well, it was just a brief explanation, we will see it via code in detail, later in this tutorial. &lt;/p&gt;


&lt;h3&gt;
  
  
  2. Doubly circular linked list
&lt;/h3&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%2Fuploads%2Farticles%2Fa597lsfrxel4dwoaxtcy.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%2Fuploads%2Farticles%2Fa597lsfrxel4dwoaxtcy.png" alt="Doubly Linked List"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above diagram is an example of doubly linked list in which the prev of head points to NULL and last node(&lt;strong&gt;Tail&lt;/strong&gt;) points to NULL to represent the termination of linked list. &lt;br&gt;
To make it a &lt;strong&gt;Doubly Circular Linked List&lt;/strong&gt;, you just need to modify the link of the last node. &lt;br&gt;
Instead of pointing next of last node (&lt;strong&gt;lastNode-&amp;gt;next&lt;/strong&gt;) to NULL, We are going to link it with first(head) node. &lt;br&gt;
Moreover, the prev of first node (&lt;strong&gt;head-&amp;gt;prev&lt;/strong&gt;) will point to the last node.&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%2Fuploads%2Farticles%2F534boa23v606q4de3mgz.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%2Fuploads%2Farticles%2F534boa23v606q4de3mgz.png" alt="Doubly circular linked list"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, keep a track of head node and whenever we encounter it again, we say that we have traversed whole linked list and now it is time to terminate. &lt;/p&gt;

&lt;p&gt;You could have taken a temp=head-&amp;gt;next and start traversing linked list and check for whether our temp is head or not.&lt;br&gt;
if temp==head -----&amp;gt; We have traversed whole linked list. &lt;/p&gt;


&lt;h1&gt;
  
  
  Operations on Circular linked list
&lt;/h1&gt;


&lt;h2&gt;
  
  
  A. Traversal
&lt;/h2&gt;

&lt;p&gt;Traversal in Circular linked list is similiar to singly or doubly linked list, we just need to take care of termination condition. In this case termination condition would be, If we reach again to our head node.&lt;/p&gt;

&lt;p&gt;To perform this task do the following:&lt;br&gt;
Take a temp node and store head -&amp;gt;next into it, now run a loop untill &lt;strong&gt;temp!=head&lt;/strong&gt; and search for given element.&lt;br&gt;
If we reach head ===&amp;gt; (temp==head): terminate loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Node *temp=head-&amp;gt;next;
while(temp!=head)
{
  if(temp-&amp;gt;data==ElementToFind) {
    cout&amp;lt;&amp;lt;"Element found"&amp;lt;&amp;lt;endl;
    break;
  }
  temp=temp-&amp;gt;next;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  B. Insertion
&lt;/h2&gt;

&lt;p&gt;Insertion in Circular linked list will be exactly same as in singly linked list except inseting node at front and at last position.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Inserting node in Between two nodes&lt;/strong&gt;&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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0drk5qwbjcor67qeo93f.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%2Fuploads%2Farticles%2F0drk5qwbjcor67qeo93f.png" alt="Inserting node in Between two nodes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Inserting node at front&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To insert a node at front, We need to know about the last node of linked list.&lt;br&gt;
Hence we will traverse the whole linked list and reach to end of 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgx07k4atv3yvai1gl6o6.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%2Fuploads%2Farticles%2Fgx07k4atv3yvai1gl6o6.png" alt="Insert at front"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a new node and link it with exisiting list as mentioned below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LastNode-&amp;gt;next=newNode;
newNode-&amp;gt;next=head;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After, linking nodes, we need to update the head of linked list as we are inserting at the front and front node represent the head of linked list.&lt;br&gt;
In our case, newNode would be our new head now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;head=newNode;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Inserting node at last&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is similiar to inserting node at front. The only difference is that we don't need to update head in this case.&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%2Fuploads%2Farticles%2Fh2fk2z4w99g19vqui6wj.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%2Fuploads%2Farticles%2Fh2fk2z4w99g19vqui6wj.png" alt="Insert at last"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  C. Deletion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Deleting in between node&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To delete in between node, find prev and next node of the node which needs to be deleted.&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%2Fuploads%2Farticles%2Fe78gxwukuqm2son5587u.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%2Fuploads%2Farticles%2Fe78gxwukuqm2son5587u.png" alt="Delete node in between"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curr = head;
while(curr!=nodetoDelete) { 
   prev = curr;
   curr = curr-&amp;gt;next;
}
prev-&amp;gt;next=curr-&amp;gt;next;
delete curr;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Deleting node at front&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To delete a Node from front, We need to know about the last node of linked list.&lt;br&gt;
Hence we will traverse the whole linked list and reach to end of 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzh3lsqwsktrer10imht4.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%2Fuploads%2Farticles%2Fzh3lsqwsktrer10imht4.png" alt="Delete node from front"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptr = head;  
while(ptr -&amp;gt;next != head) {  
       ptr = ptr-&amp;gt;next;  
}  
temp = head;
ptr -&amp;gt; next = temp-&amp;gt;next;
// update head node
head =head-&amp;gt;next;
delete temp; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Deleting last node&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is similiar to deleting node at front. The only difference is that we won't be updating head in this case.&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%2Fuploads%2Farticles%2Ffe3yqhoznncku6mfdew5.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%2Fuploads%2Farticles%2Ffe3yqhoznncku6mfdew5.png" alt="Delete last node"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptr = head;  
while(ptr -&amp;gt;next != head) {  
       preptr=ptr;  
       ptr = ptr-&amp;gt;next;  
}  
preptr-&amp;gt;next = ptr -&amp;gt; next;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  D. Advantages of Circular linked list
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In a circular linked list, there is no requirement for a NULL assignment in the code. The good thing about a circular linked list is that It never points to a NULL pointer unless fully deallocated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Circular linked lists are always good and advantageous for the end operations since the beginning and the end of circular linked list coincide with each other.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Many algorithms such as the Round Robin scheduling which uses queue can efficiently and easily eliminate processes that are queued in a circular way or fashion without encountering any dangling pointers or NULL-referential&lt;br&gt;
pointers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The biggest advantage with a circular linked list is that It also performs all regular functions of a singly/doubly linked list along with additional features.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  E. Disadvantage of circular linked list
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Insertion at all positions (first node, last node, and In-between) takes O(n) time while in singly linked list insertion at first node takes O(1) time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deletion at all positions (first Node, Last Node, and In-between) takes O(n) time while in singly linked list deletion at first node takes O(1) time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If we don’t apply the termination condition properly, our code might lead to infinite loop.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  F. Applications of Circular linked list
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If I talk about the real-life application of a circular linked list, It would be none other than our personal computers, which are capable of running multiple applications at a time. Computers process all applications in this manner that all running applications are kept in a queue which is implemented using a circular linked list and the operating system gives a fixed time(could be an example of Round Robin CPU Scheduling Process) slot know as time quantum to all for running processes. &lt;br&gt;
The operating system keeps on iterating over the&lt;br&gt;
circular linked list and keeps executing processes and removing them from waiting for queue until all the applications are executed/completed successfully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can also take an example multiplayer games in which all the players are kept in a queue which is implemented via a circular linked list and the pointer keeps on moving forward as the chance of a particular player ends.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can also take an example of the circular linked list which can also be used to create a circular queue.&lt;br&gt;
The problem with a given queue is that we need to keep two pointers one for FRONT and another for REAR in memory all the time to implement a queue.&lt;br&gt;
But with the help of a Circular linked list we can do this task easily and efficiently because, in a circular linked list, only one pointer is required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Circular linked list is also used in token rings scheduling in computer networks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Circular linked list is used to display units like shop boards that require continuous traversal of data.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  G. Implementation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
class NodeTaslim {
  public:
  int data;
  NodeTaslim *next;
  NodeTaslim() { 
    data = 0;
    next = NULL;
  }
  NodeTaslim(int x) {
    data = x;
    next = NULL;
  }
};


class CircularLinkedList {
   public:
   NodeTaslim *head;

   /* Insert at front */
   int addAtFront(int value);

   /* check list is empty or not */
   int isEmpty();

   /* Insert at end */
   int addAtEnd(int value);

   /* Search for an element in list */
   NodeTaslim *search(int k);

   /* Delete a node */
   NodeTaslim *deleteNode(int x);

   CircularLinkedList() {
     head = NULL;
   }
};

/* Find last Node of Linked List */
NodeTaslim *getLastNode(NodeTaslim *head) {
   NodeTaslim *temp = head;
   while (temp-&amp;gt;next != head) {
     temp = temp-&amp;gt;next;
   }
   return temp;
}

/* Add a Node at Front */
int CircularLinkedList ::addAtFront(int value)
{
   int i = 0;
   NodeTaslim *n = new NodeTaslim(value);
   /* Check list is empty or not */
   if (head == NULL) {
       n-&amp;gt;next = head;
       head = n;
       i++;
   }
   else {
      NodeTaslim *last = getLastNode(head);
      n-&amp;gt;next = head;
      last-&amp;gt;next = n;
      head = n;
      i++;
   }
   return i;
}

/* Add a Node at Last */
int CircularLinkedList ::addAtEnd(int value) {
   NodeTaslim *n = new NodeTaslim(value);
   if (head == NULL) {
       head = n;
       n-&amp;gt;next = NULL;
   }
   else {
       NodeTaslim *last = getLastNode(head);
       last-&amp;gt;next = n;
       n-&amp;gt;next = head;
   }
}

/* Search an Element in List */
NodeTaslim *CircularLinkedList ::search(int x) {
     NodeTaslim *ptr = head;
     while (ptr != NULL &amp;amp;&amp;amp; ptr-&amp;gt;data != x) {
           ptr = ptr-&amp;gt;next;
     }
     return ptr;
}

/* Remove Node from List */
NodeTaslim *CircularLinkedList ::deleteNode(int x) {
    NodeTaslim *n = search(x);
    NodeTaslim *ptr1 = head;
    if (ptr1 == NULL) {
      cout &amp;lt;&amp;lt; "List is empty";
      return NULL;
    }
    /*Remove first node*/
    else if (ptr1 == n) {
      ptr1-&amp;gt;next = n-&amp;gt;next;
      return n;
    }
    else {
      while (ptr1-&amp;gt;next != n) {
         ptr1 = ptr1-&amp;gt;next;
      }
      ptr1-&amp;gt;next = n-&amp;gt;next;
      return n;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>algorithms</category>
      <category>datastructures</category>
      <category>linkedlist</category>
    </item>
    <item>
      <title>An Introduction to Linked List</title>
      <dc:creator>Taslim Arif</dc:creator>
      <pubDate>Sun, 19 Sep 2021 12:40:28 +0000</pubDate>
      <link>https://dev.to/tastaslim/an-introduction-to-linked-list-1bmp</link>
      <guid>https://dev.to/tastaslim/an-introduction-to-linked-list-1bmp</guid>
      <description>&lt;p&gt;A  &lt;strong&gt;Linked List&lt;/strong&gt; is a linear data structure which consists of a group of nodes. &lt;br&gt;
Unlike an array, In a linked list, elements are stored in random memory locations.&lt;/p&gt;

&lt;p&gt;Each node contains two fields : &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;data&lt;/strong&gt; stored at that particular address.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pointer&lt;/strong&gt; which contains the address of the next node.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The last node of the linked list contains a pointer to null to represent the termination of the linked list.&lt;br&gt;
Generally, We call the first node as &lt;strong&gt;Head&lt;/strong&gt; node and the last node as the &lt;strong&gt;Tail&lt;/strong&gt; node in linked list.&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%2Fuploads%2Farticles%2Fg1j3d29p12kdr9pz57b5.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%2Fuploads%2Farticles%2Fg1j3d29p12kdr9pz57b5.png" alt="Singly Linked List"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Why linked list over array?
&lt;/h3&gt;

&lt;p&gt;An array contains the following limitations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The size of an array is fixed. We must know the size of the array at the time of its creation, hence it is impossible to change its size at runtime.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inserting a new element in an array is expensive because we need to shift elements to create room for a new element to insert.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deleting an element in an array is also expensive as it also takes the shifting of elements in an array.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  Advantages of linked lists:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Insertion and deletion operations can be implemented very easily and these are not costly as they do not require shifting of elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They are dynamic in nature. Hence, we can change their size whenever required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stacks and queues can be implemented very easily using Linked Lists.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  Disadvantages of linked lists:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Random access of an element is not possible in linked lists, we need to traverse linked list from starting to search an element into it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is relatively slow to process in comparision of an array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Since node of a linked list conatins both data and pointer to next node, hence extra memory is required to store pointer of each node.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  Types of linked lists:
&lt;/h2&gt;

&lt;p&gt;There are 3 types of linked lists:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Singly linked list&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Circular linked list&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Doubly linked list&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;strong&gt;Singly linked list&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Singly linked list contains a node that has both data part and pointer to the next node.&lt;br&gt;
The last node of the singly linked list has a pointer to null to represent the end of the linked list.&lt;br&gt;
Traversal to previous nodes is not possible in singly linked list i.e We can not traverse in the backward direction.&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%2Fuploads%2Farticles%2Fg1j3d29p12kdr9pz57b5.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%2Fuploads%2Farticles%2Fg1j3d29p12kdr9pz57b5.png" alt="Singly Linked List"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Circular linked list&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Circular linked list is similar to singly linked list but the last node of circular linked list points to first node (&lt;strong&gt;head node&lt;/strong&gt;) of linked list.&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%2Fuploads%2Farticles%2Fjcv5p77sysmb9hdlmo47.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%2Fuploads%2Farticles%2Fjcv5p77sysmb9hdlmo47.png" alt="Circular Linked List"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Doubly linked list&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Doubly linked list contains a node that has three entries: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; data &lt;/li&gt;
&lt;li&gt; pointer to next node&lt;/li&gt;
&lt;li&gt; pointer to the previous node&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We can traverse in both forward and backward directions in doubly linked list.&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%2Fuploads%2Farticles%2Fa597lsfrxel4dwoaxtcy.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%2Fuploads%2Farticles%2Fa597lsfrxel4dwoaxtcy.png" alt="Doubly Linked List"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Implementation of linked list:
&lt;/h3&gt;

&lt;p&gt;I am implementing singly linked list below for the sake of understanding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include&amp;lt;iostream&amp;gt;
using namespace std;
/* Create a class which contains 2 properties data and pointer to next node */
class Node
{
  public:
  int data;
  Node *next;

  Node(int data)
  {
   this-&amp;gt;data=data;
   this-&amp;gt;next=NULL;
  }
};

/* Take Input from the user in Linked List  and Stop when a user enters data== -1 */

Node *takeInput()
{
  int data;
  cin&amp;gt;&amp;gt;data;
  /* Intially linked list is empty, hence both head and tail nodes are NULL */
  Node *head=NULL;
  Node *tail=NULL;

  while(data!=-1)
  {
    Node *newNode = new Node(data);
    /* Inserting first element in empty linked list */
    if(head==NULL)
    {
      head=newNode;
      tail=newNode;
    }
    /* List is not empty */
    else
    {
      tail-&amp;gt;next=newNode;
      tail=tail-&amp;gt;next;
    }
    cin&amp;gt;&amp;gt;data;
  }
  return head;
}

/* Printing elements of Linked List  1-&amp;gt;2-&amp;gt;3-&amp;gt;4-&amp;gt;5-&amp;gt;NULL */
void printNode(Node *head)
{
  Node *temp=head;
  while(temp!=NULL)
  {
    cout&amp;lt;&amp;lt;temp-&amp;gt;data&amp;lt;&amp;lt;" ";
    temp=temp-&amp;gt;next;
  }
}
int main()
{
  Node *head=takeInput(); // Taking input
  printNode(head); // Printing data
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>algorithms</category>
      <category>datastructures</category>
      <category>linkedlist</category>
    </item>
  </channel>
</rss>
