<?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: SriSarvesh</title>
    <description>The latest articles on DEV Community by SriSarvesh (@srisarvesha1).</description>
    <link>https://dev.to/srisarvesha1</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%2F825209%2F25bb3cae-5413-4e84-8fa9-44b753f03cbf.png</url>
      <title>DEV Community: SriSarvesh</title>
      <link>https://dev.to/srisarvesha1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/srisarvesha1"/>
    <language>en</language>
    <item>
      <title>Clean Code [Part-1]</title>
      <dc:creator>SriSarvesh</dc:creator>
      <pubDate>Sat, 30 Dec 2023 07:29:06 +0000</pubDate>
      <link>https://dev.to/srisarvesha1/clean-code-part-1-3k7h</link>
      <guid>https://dev.to/srisarvesha1/clean-code-part-1-3k7h</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Clean code involves enhancing existing code through a process called refactoring. Whether you're writing a full code for a new feature or making changes, it's essential to iterate and refine the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A code base can survive for long period if its continuously improved and refactored. Whenever you introduce something new to the code base, the goal is to enhance the existing code in the process.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Clean Code Metrics
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; Clean code should be readable and meaningful.&lt;/li&gt;
&lt;li&gt; Should reduce the time that we take to understand whats happening.&lt;/li&gt;
&lt;li&gt; Precision is key, the code should be concise and to the point.&lt;/li&gt;
&lt;li&gt;It must steer clear of using unclear names, complex nesting, and overly large code blocks.&lt;/li&gt;
&lt;li&gt;Should follow widely accepted best practices, patterns, and principles is crucial.&lt;/li&gt;
&lt;li&gt;The code should be enjoyable, easily maintainable, and readily understandable.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Clean Code Focuses On
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;u&gt;Names&lt;/u&gt; that we give to (variables,functions,classes).&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Structure of the code&lt;/u&gt; that we have in our project like the no of lines that we leave between each line of code.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Comments&lt;/u&gt; that we make in our code.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Splitting Responsibility&lt;/u&gt; of a function or a class like what a particular function does and its purpose.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;No of parameters&lt;/u&gt; that we pass to function.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Avoiding deep nesting&lt;/u&gt; of conditional statements and loops.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Error and Exception&lt;/u&gt; handling in the code.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Naming Convention
&lt;/h2&gt;

&lt;p&gt;1.snake_case: &lt;br&gt;
In this convention multiple words are separated by underscore.And every character is in lowercase. &lt;/p&gt;

&lt;p&gt;Applied in variables,functions and methods name.&lt;br&gt;
&lt;u&gt;Language uses this convention:&lt;/u&gt; Python&lt;/p&gt;

&lt;p&gt;Ex:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; is_valid = true

 def return_response():
     return True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.camelCase:&lt;br&gt;
In this casing convention the variables will be having multiple words and the first word’s character starts with lower case,but the next word's first character will be starting with uppercase. &lt;/p&gt;

&lt;p&gt;Applied in variables,functions,methods name.&lt;br&gt;
&lt;u&gt;Language uses this convention:&lt;/u&gt; Python,Javascript&lt;/p&gt;

&lt;p&gt;Ex:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const isValid = true;

 function returnResponse(){
     return true;
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.PascalCase:&lt;br&gt;
Here in this casing convention the words in the variable starts with the uppercase letter and no space between the words.It is same as camelCase but here the first word's first letter also starts with uppercase.&lt;/p&gt;

&lt;p&gt;Applied in class name.&lt;br&gt;
&lt;u&gt;Language uses this convention&lt;/u&gt;: Python,Javascript&lt;/p&gt;

&lt;p&gt;Ex:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class AdminRole{

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  How to choose name for variables,functions,class?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When we want to store properties like name,age,email etc.We can store it in a variable with name describing whose properties and its what kind of properties it is.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ex: Here the below variable name hold's the object of customer and their personal details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const customerDetails = {
        name:"Gopi",
        age:"2",
        email:"sample@gmail.com"
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;And when we want to store boolean value for a variable or when a boolean value is being returned by a function the name should represent a question and the value or the function body should be an answer for it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ex: Here the below variable store's the boolean value that tells whether an user is available or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; let isAvailable = true;

 function  isValidUserInput(){
  The function name should describe what kind of check is being done.
 }

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;And when we want to name a class,it should represent what kind of object we will create based on the class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ex: When we want the object of different users then the class name will be. The class name's specifies what kind of user the object of the class will hold.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; class Admin{

 }

 class Customer{

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;And even when we want to create a static class that has utility methods the name should represent what kind of utility method's the class will hold.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ex:The class name below will act as a container for the various pieces of data or functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; class DateUtility{ 
   So this class will hold the the utility methods of date
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Some more naming tips:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A variable name that we give should be specific and should tell us what value is being stored.&lt;/li&gt;
&lt;li&gt;But also it should not be too specific and very long and describing each and every thing and lists too much information.&lt;/li&gt;
&lt;li&gt;And also we should avoid unclear abbreviations like 
ymdt = “20220121CET”,instead we can name it like
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dateWithTimeZone =  “20220121CET”;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Be consistent in the convention that we choose and use it fully throughout the whole code base. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So in the situation where there are variable's like getUsers(),fetchUsers(),retrieveUsers() we should use any one of the convention out of it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And when we choose a convention for fetching users like &lt;br&gt;
fetchUsers() then for other entities also we should do it like that fetchProducts().&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>development</category>
      <category>softwaredevelopment</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Redis</title>
      <dc:creator>SriSarvesh</dc:creator>
      <pubDate>Thu, 24 Nov 2022 04:30:44 +0000</pubDate>
      <link>https://dev.to/srisarvesha1/redis-108n</link>
      <guid>https://dev.to/srisarvesha1/redis-108n</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The open-source, in-memory data store is used by millions of developers as a database, cache, streaming engine, and message broker(It can be used as a queue manager for our jobs).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;But if the data that we are trying to store is bigger than memory then we need to move it to the secondary storage and then execute which makes it useless of the Redis concept.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So it is better to have data in the Redis smaller than the memory. So that we can perform all kinds of computations easily. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And also this Redis should be treated like NoSQL. And this follows a client-server architecture and we try to connect to the server(which runs as a process at port 6379(localhost) ) to perform the required things we wanna perform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And Redis comes with cli(client) using which we can perform the required operations on the server. And also there is a UI-based client which is a Redis Desktop Manager.&lt;br&gt;
Using &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;sudo snap install redis-desktop-manager&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We install the GUI-based Redis-desktop-manager.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;So after installing the GUI-based app we can connect to the local connection by giving a sample name. And then we will be able to see various databases and they are index based instead of names.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And by clicking each of those db(index) we can insert multiple key-value pairs. And for each key, there will be a value and we can set up TTL(Time to live in seconds) which means the duration for how long this key-Value will be stored in the Redis DB. ( for ex: -1 (then it will be stored for ever). And after the time is over the key value will be removed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So we have this feature because we want to cache the data only for a certain period of time. So this can be used when we want to cache the result of an External API for a certain period of time and then later we try to remove it from the cache and again perform the API call.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And also there is a concept of Publisher and subscriber concept in Redis. So where there will be a publisher and many subscribers to it and when the publisher publishes certain things then all the subscribers get the &lt;br&gt;
message/content/alerting/push messages to the people.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And also Redis provides the transaction even though we use it as a NoSQL database. And also it provides ACL(Access control list). And also a certain user can establish a connection to this database if they have a valid username and password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So we use Redis as a JOB queue for handling Asynchronous JOB where the Redis will be used as Publication and Subscriber server for sending push messages to the client (one by one)after the client has made a request to the server. And also we are going to use it as a cache.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>redis</category>
    </item>
  </channel>
</rss>
