<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sampath. V on Medium]]></title>
        <description><![CDATA[Stories by Sampath. V on Medium]]></description>
        <link>https://medium.com/@sampath300500?source=rss-e5f87a56a9f7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*h-REmVjfxVZ9_Ds-RBt8IQ.jpeg</url>
            <title>Stories by Sampath. V on Medium</title>
            <link>https://medium.com/@sampath300500?source=rss-e5f87a56a9f7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:14:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sampath300500/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Robust Infrastructure: Achieving High Availability with AWS Auto Scaling and ALB]]></title>
            <link>https://medium.com/@sampath300500/building-robust-infrastructure-achieving-high-availability-with-aws-auto-scaling-and-alb-1c8f1238244e?source=rss-e5f87a56a9f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c8f1238244e</guid>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Sampath. V]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 07:09:22 GMT</pubDate>
            <atom:updated>2023-07-20T08:31:13.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*fKP-8v6WiKgPliOW1uwMGg.png" /></figure><h4><strong>Introduction:</strong></h4><p>In today’s fast-paced digital landscape, ensuring the high availability and scalability of web applications is paramount for delivering an exceptional user experience. Cloud-based solutions have revolutionized the way we build and deploy applications, and Amazon Web Services (AWS) offers a powerful set of tools to achieve high availability. In this article, we will explore how to build a robust infrastructure using AWS Auto Scaling and Application Load Balancer (ALB) to ensure seamless performance even during traffic spikes.</p><h4><strong>What is Auto Scaling Group (ASG)?</strong></h4><p>AWS Auto Scaling Group (ASG) is a critical service provided by Amazon Web Services that enables the automatic scaling of compute resources based on application demand. With ASG, you can ensure that your application always has the right number of Amazon Elastic Compute Cloud (EC2) instances available to handle incoming traffic. This elasticity allows you to scale your infrastructure up during high-traffic periods and scale it down during periods of reduced demand, optimizing costs and performance.</p><h4><strong>What is Elastic Load Balancer (ELB)?</strong></h4><p>Elastic Load Balancer (ELB) is a fully managed load balancing service provided by AWS. It helps distribute incoming application traffic across multiple EC2 instances in a target group to ensure optimal utilization and availability of resources. ELB plays a crucial role in improving application performance, fault tolerance, and facilitating seamless scaling.</p><h4><strong>Steps to build a highly available web application with AWS Auto Scaling Group (ASG) and Elastic Load Balancer (ELB)</strong></h4><ol><li>Create an Auto Scaling Launch Template</li><li>Create an Application Load Balancer (ALB) and Configure Health Checks for ALB and Instances.</li><li>Create an AWS Auto Scaling Group (ASG) and Configure Scaling Policies.</li><li>Test and Monitor the Infrastructure.</li></ol><h4><strong>Step-1: Create an Auto Scaling Launch Template.</strong></h4><p>The EC2 Launch Template console allows us to create a reusable configuration template for our Amazon EC2 instances. We can specify the desired instance attributes, such as the AMI, instance type, storage, and security groups. This template simplifies the provisioning process and ensures consistency across instances launched by the AWS Auto Scaling Group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G9XVmCzk8A4OSCmHbrkHhg.png" /><figcaption>Create an ec2 launch template</figcaption></figure><p>We’ll be using the Amazon Linux 2 AMI and launching instances with a t2.micro instance type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*Ay4Iv1fr6qt4d_5eeEw2gQ.png" /><figcaption>ec2 instance ami</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*PKNHXf-yZbA5t5OrvGGNlg.png" /><figcaption>ec2 instance type</figcaption></figure><p>If you already have a key pair, you can proceed with the existing key pair. If not, create a new key pair.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*76KUPWb_oD5EsRAlptqn_A.png" /><figcaption>ec2 key-pair</figcaption></figure><p>Under the Network Settings, we won’t choose a specific subnet. Instead, we’ll let the AWS Auto Scaling Group handle the selection of the appropriate subnets based on its configuration.</p><p>For the Security Group, we’ll create a new one with rules to allow HTTP/HTTPS and SSH access. This will ensure that our web application can be accessed securely, and we have the necessary SSH access to manage our instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6vkDqqYxWfiO1QRufCkXag.png" /><figcaption>ec2 security group inbound rules</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*xn6gsBv4-zykxLnBwalTNw.png" /><figcaption>choosing sg for ec2</figcaption></figure><p>Under the <strong><em>Advanced Details</em></strong> section paste this script into the <strong><em>user data</em></strong></p><p>This user data script will be executed when each instance is launched, ensuring that the necessary packages are updated, the Apache HTTP server is installed, and a basic HTML file is created to serve as the content for our web server.</p><pre>#!/bin/bash<br># Use this for your user data (script from top to bottom)<br># install httpd (Linux 2 version)<br>yum update -y<br>yum install -y httpd<br>systemctl start httpd<br>systemctl enable httpd<br>echo &quot;&lt;h1&gt;Hello World from $(hostname -f)&lt;/h1&gt;&quot; &gt; /var/www/html/index.html</pre><p>Congratulations! The EC2 launch template has been created successfully, and it will serve as a blueprint for our auto-scaling group to create instances as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*sE94wufYEnjZZX-b57WQgg.png" /><figcaption>Ec2 Launch templates</figcaption></figure><h4><strong>Step-2: Create an Application Load Balancer (ALB) and Configure Health Checks for ALB and Instances.</strong></h4><p>Now, let’s proceed to create an Application Load Balancer (ALB) to distribute traffic to our instances.</p><p><strong>Listeners:</strong> ALB listeners define how the load balancer receives incoming traffic. We’ll configure a listener on port 80 (HTTP) to handle regular web traffic and optionally add a listener on port 443 (HTTPS) for secure connections.</p><p><strong>Target Groups:</strong> Target groups are used to route incoming requests from the ALB to the instances registered with the group. We’ll create a target group that includes our EC2 instances, allowing the ALB to efficiently distribute traffic to these instances based on health checks and routing rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sACvcZW3jDdEa9KUgfd3jg.png" /><figcaption><strong>Application Load Balancer (ALB)</strong></figcaption></figure><p>Before proceeding to create the Application Load Balancer (ALB), please ensure you have already created the following:</p><ol><li><strong>Security Group:</strong> Create a new security group with rules to allow HTTP/HTTPS (Ports 80 and 443) for the ALB to receive incoming traffic. Additionally, you can allow SSH (Port 22) for remote management if needed.</li><li><strong>Target Group:</strong> Create a target group to which the ALB will route incoming requests. This target group will define the instances that should receive traffic, and you can configure health checks to ensure the instances’ availability.</li></ol><p>Once you have the security group and target group ready, you can proceed to create the ALB.</p><p>Now, let’s proceed with creating the Application Load Balancer (ALB). Follow these steps:</p><ol><li>Give your ALB a name that is descriptive and easy to identify.</li><li>Ensure that the ‘Scheme’ is set to ‘Internet-facing.’ This allows the ALB to receive traffic from the internet.</li><li>Under ‘Network mapping,’ select the appropriate Virtual Private Cloud (VPC) for your application. Choose the VPC where your instances are located.</li><li>Select three subnets within the VPC for the ALB to distribute traffic across Availability Zones. This helps improve availability and fault tolerance.</li><li>For the ‘Security groups,’ choose the previously created security group that allows HTTP/HTTPS and SSH access. This ensures that the ALB can communicate with the instances securely.</li><li>For the ‘Target groups,’ select the target group that you created earlier. This will specify which instances should receive traffic from the ALB.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mb8fgz_MsYGk9PFyJPMLJA.png" /><figcaption>ALB- Target group</figcaption></figure><p>Congratulations! You have successfully created the Application Load Balancer (ALB).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uPySQKjon9RItK8GJyx0ew.png" /><figcaption>alb-output</figcaption></figure><h4><strong>Step-3: Create an AWS Auto Scaling Group (ASG) and Configure Scaling Policies.</strong></h4><p>Let’s move on to creating the Auto Scaling Group (ASG) to dynamically manage the number of instances based on traffic demand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lJzIrFlZ6Qu-0WQezaZozg.png" /><figcaption>Create — ASG</figcaption></figure><p><strong>Select Name and Instance Template:</strong> Choose a name for your Auto Scaling Group and select the launch template we created earlier. This template includes all the configurations needed for the instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*g49g_W6EsBx0UyKzbu0FGg.png" /></figure><p><strong>Select VPC and Subnets: </strong>Choose the Virtual Private Cloud (VPC) where your instances should be launched, and then select the subnets within the VPC that you want the Auto Scaling Group to scale across.</p><p><strong>Choose Existing ALB and Target Group:</strong> Select the existing Application Load Balancer (ALB) you created earlier. Then, choose the target group associated with the ALB. This will ensure that the ASG automatically registers new instances with the ALB for traffic distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*rHtwDCEuoafkGbKETl9ZLQ.png" /></figure><p><strong>Apply Health Checks: </strong>Define health checks to monitor the instances’ health. Instances failing health checks will be replaced automatically, ensuring high availability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*Meb5i1t5fyFTowBshOa-CA.png" /></figure><p><strong>Choose Instance Scaling Limits:</strong> Specify the minimum, desired, and maximum number of instances you want to maintain within the Auto Scaling Group. This allows the ASG to automatically adjust the number of instances based on demand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*-bRvDVvH9aRekIcEK83UQw.png" /></figure><p><strong>Choose Scaling Policy:</strong> Select the “Target tracking scaling policy” option for demonstration purposes. With this policy, you can set a target value for a specific metric, such as CPU utilization or request count. The ASG will then automatically adjust the number of instances to meet the target value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*a0O5u1sDxuaFAINWVALBEQ.png" /></figure><h4><strong>Step-4 Test and Monitor the Infrastructure</strong>🕵️</h4><p>To test the scalability and performance of our project, we can simulate high CPU load by using the “stress” tool. By subjecting the instances to maximum stress, we can observe how AWS Auto Scaling responds to increased demand, ensuring our infrastructure scales dynamically and efficiently to meet the workload.</p><p>To prepare for the CPU stress test, we need to install the “stress” tool using the following commands.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c06446f7c3ffb2d03967a799f97c8fd/href">https://medium.com/media/1c06446f7c3ffb2d03967a799f97c8fd/href</a></iframe><p>Once “stress” is installed, you can run the following command to load the CPU to the maximum with four threads.</p><pre>stress -c 4</pre><p>After running the stress test, you can observe and analyze the performance changes by checking the following AWS monitoring services: CloudWatch, Auto Scaling Group Activity History, EC2 Instance Monitoring</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MFb7vq4Gxvd2dt9TQy0W9A.png" /></figure><p>Finally, cross-check the Application Load Balancer (ALB) DNS to verify whether it successfully distributed the traffic across the instances during the stress test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bzlr1L6EKc8tqOynGB7whA.png" /></figure><p><strong>Success!</strong> With AWS Auto Scaling, Application Load Balancer, and proper monitoring, we have built a highly available and scalable web application. Thank you <strong>🙏 </strong>for joining this journey to optimize performance and ensure seamless user experiences in the cloud!</p><p>To stay updated with AWS insights and tech articles, follow me on LinkedIn 👉 <a href="https://www.linkedin.com/in/sampath-vijayan/">Sampath-Vijayan</a>. Happy scaling and looking forward to connecting with you there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c8f1238244e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 steps to Master the art of recursive solving]]></title>
            <link>https://medium.com/@sampath300500/5-steps-to-master-the-art-of-recursive-solving-aed675e41976?source=rss-e5f87a56a9f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/aed675e41976</guid>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[recursion]]></category>
            <dc:creator><![CDATA[Sampath. V]]></dc:creator>
            <pubDate>Sun, 20 Nov 2022 03:18:32 GMT</pubDate>
            <atom:updated>2022-11-24T02:11:37.280Z</atom:updated>
            <content:encoded><![CDATA[<h3>5 steps to Master the art of recursion</h3><p>5 simple steps to solve any recursive problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*uVKF1i4fvcHBSiP-Bx_wdg.gif" /><figcaption>Recursion</figcaption></figure><p>Despite programming languages, some concepts can seem strange and difficult to understand. Recursion is one of the trickiest topics, Many developers get nervous when they want to solve recursive problems.</p><p>But, you can <strong>train your brain</strong> to solve any recursive problem and master it.</p><p>Back in 2021, I attended my first interview with Infosys, my interviewer asked me to write a pseudo code to find the factorial of a number using recursion. Even though I have enough knowledge on other topics, I couldn’t clear the interview because of insufficient knowledge in recursion.</p><p>In this article, I will walk you through step by step approach, how to solve any recursive problem so that you will never miss any opportunity as I did.</p><p><strong><em>Shall we start?</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BVkiCIkMEtIQ6d8krHO1rg.jpeg" /><figcaption>Shall we start?</figcaption></figure><h4>Steps to solve any recursive problem:</h4><p>To demonstrate the process, let’s take a simple problem. Calculate the sum of the first n natural numbers. For example, the sum of the first 5 numbers is 15, for 10 is 55, and so on.</p><p>Although I will use <a href="https://www.python.org/"><strong><em>Python</em></strong></a> to demonstrate the steps, these steps can be applied to any programming language.</p><h4>1. Solve the problem with loops first.</h4><p>Solving problems using <a href="https://docs.python.org/3/tutorial/controlflow.html#for-statements"><strong>loops</strong></a> is as easy as pie. The code looks something like this when you use for loop.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0662c1d811daa34b587e0aa7aeb9236e/href">https://medium.com/media/0662c1d811daa34b587e0aa7aeb9236e/href</a></iframe><p>First, we need to initialize a variable sum with zero and run a loop with the range starting from 1 to n+1 then add a sum with num in each step. finally, display the output.</p><h4>2. Introduce the function.</h4><p>Solving problems using loops will help us to understand the pattern.</p><p><strong><em>Now let’s ask ourselves a question how can we convert this iterative code to function code?</em></strong></p><p>The answer to this question is, only one parameter which is nothing but a variable n.</p><p>let’s create a function that takes the variable n as a parameter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cae07b721fe54ec663b1efc043c8f3a/href">https://medium.com/media/2cae07b721fe54ec663b1efc043c8f3a/href</a></iframe><h4>3. Find and solve a subproblem</h4><p>Sub-problem, A problem whose solution contributes to the solution of a larger problem.</p><p>Our original problem is to find the sum of the first natural numbers. So, our subproblem is to sum all numbers up to a value smaller than n.</p><p>It can be,</p><pre>natural_sum(n-1)<br>natural_sum(n-2)<br>natural_sum(n-3)<br>...<br>natural_sum(1)</pre><p>But, picking a subproblem as close to the original is always the best option. In this case, since our problem solves for n, then the best subproblem should solve for n-1.</p><p>Our function call will look like this with n-1 as a parameter.</p><pre>natural_sum(n-1)</pre><h4>4. Use a subproblem solution to solve the main problem.</h4><p>Now, we calculated the sum until n-1.</p><p><strong><em>So what next?</em></strong></p><p>Let’s get back to the original problem. our main problem is to calculate the sum of the first natural numbers.</p><p>We have already calculated the sum until n-1, So we just need to add the natural_sum(n-1) solution and n.</p><pre>def natural_sum(n: int) -&gt; int:<br>    ...<br>    ...<br>    return n + natural_sum(n-1)</pre><p>Finally, we connect the subproblem with the main problem.</p><blockquote><strong><em>but wait!</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*hE_ICCAQjduVTQa9Lckzkw.gif" /><figcaption>IT AIN’T OVER YET!</figcaption></figure><h4>5. Define base case.</h4><p>As this natural_sum() function calls itself, it will run forever and gives you the Recursion error.</p><blockquote><strong><em>RecursionError: maximum recursion depth exceeded</em></strong></blockquote><p>We need to stop the recursion with the base case.</p><p>To pick the right base case,</p><blockquote>Think of it is a minimal problem instance that needs no extra efforts.</blockquote><p>In our problem 1 and below is the minimal problem instance, So why further delay? put that in the if statement.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d18da00e13a21957eb5669014642d2f/href">https://medium.com/media/3d18da00e13a21957eb5669014642d2f/href</a></iframe><p>And, yes! we got our recursive solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WfrsWQXh-F2Wt7UNPHaLQ.jpeg" /><figcaption>It’s done</figcaption></figure><h4>Tying everything together</h4><p>Recursion is one of the trickiest topics in programming languages, many developers find it difficult to understand it.</p><p>But, By following the simple five steps, you can solve any recursion problem with ease:</p><ul><li>Solve the problem with loops first.</li><li>Introduce the function.</li><li>Find and solve a subproblem.</li><li>Use the subproblem’s solution to solve the main problem.</li><li>Define base case.</li></ul><p>That’s a wrap — thanks for reading!</p><p><em>If you enjoyed this, </em><strong>5 steps to Master the art of recursion</strong><em>, feel free to get in touch with me </em><a href="https://medium.com/u/e5f87a56a9f7"><em>Sampath. V</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aed675e41976" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 compelling reasons to use python Dataclasses]]></title>
            <link>https://medium.com/@sampath300500/10-compelling-reasons-to-use-python-dataclasses-d7f106f69c93?source=rss-e5f87a56a9f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7f106f69c93</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python-dataclass]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-engineer]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sampath. V]]></dc:creator>
            <pubDate>Sat, 05 Nov 2022 06:29:39 GMT</pubDate>
            <atom:updated>2022-11-05T13:35:47.974Z</atom:updated>
            <content:encoded><![CDATA[<h4>🔓 Unlock more functionality with less boilerplate code</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6hY6nzwgJ4LioHH_ckPtQQ.png" /><figcaption>Source image from <a href="https://www.canva.com/">https://www.canva.com/</a></figcaption></figure><p>Python introduced the dataclasses in version <strong>3.7(</strong><a href="https://peps.python.org/pep-0557/"><strong>PEP 557</strong></a><strong>)</strong>. As the name indicates, dataclasses contain data, allowing us to unlock more functionality in classes.</p><h3><strong>Over view:</strong></h3><p>Traditionally, we use <strong>special methods</strong> to <strong>initialize</strong> the class attributes and perform operations between those attributes. But, This gives a headache to the developers when they spend a consequent amount of time writing special methods with many attributes.</p><blockquote><strong>Dataclasses</strong> reduce these problems by adding more functionality to the normal class while supplying less code.</blockquote><p>Ok, let’s understand why Dataclasses is better than normal class</p><h3><strong>1. </strong>🤏<strong>Define your class with less code</strong></h3><p>When we define the class with the<strong> __init__</strong> method, it looks something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ca1ca2d0427f37f3ac1d8a2664d13b1/href">https://medium.com/media/2ca1ca2d0427f37f3ac1d8a2664d13b1/href</a></iframe><p>but when you define a class with dataclasses you use <strong>@dataclass</strong> <a href="https://peps.python.org/pep-0318/">decorator</a> just above the class declaration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6eab937733c2b180f4c17acf39c7f5a2/href">https://medium.com/media/6eab937733c2b180f4c17acf39c7f5a2/href</a></iframe><p>Notable points in the above code:</p><ol><li>Less boilerplate code.</li><li>We define each attribute with a type hint <strong>E.g, name: str</strong> that says the name attribute should be a string type.</li></ol><h3><strong>2. </strong>👏<strong>Facilitate</strong> default values</h3><p>you can provide default values to the fields where you need them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0d73f18e3f176415322cc1dbeaff678/href">https://medium.com/media/b0d73f18e3f176415322cc1dbeaff678/href</a></iframe><p>Never forget, fields without default values always comes first. if you change the order it will raise an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*xvrs-DZvSAJYSSks2Kyqxg.jpeg" /><figcaption>Source image from a local machine</figcaption></figure><h3>3. ✨represent readable objects</h3><p>python dataclasses supports <strong>__repr__</strong> so it gives better readability when you print the object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/520fa578deccef5120d428b456e5826f/href">https://medium.com/media/520fa578deccef5120d428b456e5826f/href</a></iframe><h3><strong>4. </strong>💪<strong>Create immutable objects</strong></h3><p>you can create <strong>read-only</strong> objects, All you have to do is set the<strong> frozen</strong> argument to <strong>True</strong> in <a href="http://twitter.com/dataclass">@dataclass</a> decorator.</p><p>This will prevent the attributes from being modified by anyone.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0649fc5d73dfe7de685c362db013f9d5/href">https://medium.com/media/0649fc5d73dfe7de685c362db013f9d5/href</a></iframe><p>if you try to set a new value to the attribute, it will raise an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*kIdOuoHE2bvmV0PV2ZQkIA.jpeg" /></figure><h3>5. ➡️Easy to convert tuple or dictionary</h3><p>With help of <strong>astuple()</strong> and <strong>asdict()</strong> functions, we can easily convert dataclass instances to tuple and dictionary.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bcd7883e4eb230af0da36c82054753e/href">https://medium.com/media/3bcd7883e4eb230af0da36c82054753e/href</a></iframe><h3>6. 💁🏼‍♂️Effortless comparison</h3><p>if you check the equality between two objects that have the same values in the standard class declaration, it will give you the False.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6db464bc32dd870433a7a7977a5b7c57/href">https://medium.com/media/6db464bc32dd870433a7a7977a5b7c57/href</a></iframe><p>These two objects have the same values but our answer is False, this is because we have not implemented the <strong>__eq__ </strong>method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93494b8a696b9f511f31578a38331ef2/href">https://medium.com/media/93494b8a696b9f511f31578a38331ef2/href</a></iframe><p>These same two objects give True when we declare the class with @dataclass as it supports the __eq__ method.</p><h3>7. 💫Custom attribute behavior</h3><p>if you don&#39;t want to initialize an attribute when the class is instantiated that is possible using the field function.</p><p>By using the field function and setting <strong>init</strong> and <strong>repr</strong> arguments to <strong>False</strong> you can create a Student class without initializing the Percentage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/985b26fbf265548ed7830328977efe41/href">https://medium.com/media/985b26fbf265548ed7830328977efe41/href</a></iframe><p>The percentage attribute doesn’t exist yet. If you try to access it, this will throw <strong>AttributeError.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rkKy6Z_cuYtYDMQ_cJBRUg.jpeg" /><figcaption>Source image from a local machine</figcaption></figure><h3>8. ☑️The __post_init__</h3><p>dataclasses has a special method called __post_init__.</p><p>This method will help us to initialize an attribute that depends on the value of another attribute. As its name implies, Python calls the __post_init__ method after the __init__ method.</p><p>Going back to the previous example, we can see how this method initializes the percentage attribute.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ea9e68aba4b0a64ff6ce18984a9d17d/href">https://medium.com/media/7ea9e68aba4b0a64ff6ce18984a9d17d/href</a></iframe><p>👉 Note that the <strong>repr</strong> argument inside the field function has been set to True to make it visible when the object is printed.</p><h3>9. ⚖️Compare objects</h3><p>By default, a dataclass implements the __eq__ method.</p><p>To allow different types of comparisons like <strong>__lt__, __lte__, __gt__,</strong> <strong>__gte__,</strong> you can set the order argument of the <a href="http://twitter.com/dataclass">@dataclass</a> decorator to True.</p><p>By doing this, the dataclass will compare the objects by every field until it finds a value that’s not equal.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8972d4780cd82f7e11fe595268a46622/href">https://medium.com/media/8972d4780cd82f7e11fe595268a46622/href</a></iframe><h3>10. 🤝Support mutable default values</h3><p>In some cases, you may need to create a class with a default mutable attribute.</p><p>By using <strong>default_factory</strong> you can create mutable default attributes. let’s give individual marks in the list to the Student class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/823b4924a22e7ccd3b156a904816d89e/href">https://medium.com/media/823b4924a22e7ccd3b156a904816d89e/href</a></iframe><p>👉 Note here that <strong>default_factory </strong>only takes <strong>zero-argument callable</strong> which is why we used the <strong>lambda</strong> function.</p><p>Dataclasses allow us to work efficiently with classes.</p><p>Specifically, this module helps to:</p><ul><li>write less code.</li><li>represent objects in a readable format.</li><li>create immutable objects.</li><li>provide astuple() and asdict() functions to convert an object of a dataclass to a tuple and dictionary.</li><li>Provide custom attribute behavior.</li><li>Use __post_init__ method to initialize attributes that depend on other attributes.</li><li>implement custom ordering and comparisons.</li><li>Create default mutable attributes.</li></ul><p><strong>Thanks for reading 🙏</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7f106f69c93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Never underestimate the value of data]]></title>
            <link>https://medium.com/@sampath300500/never-underestimate-the-value-of-data-584198613797?source=rss-e5f87a56a9f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/584198613797</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-analyst]]></category>
            <dc:creator><![CDATA[Sampath. V]]></dc:creator>
            <pubDate>Sun, 16 Oct 2022 11:28:45 GMT</pubDate>
            <atom:updated>2022-10-17T13:24:30.289Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*XWk_pJLlDVBmFtPf7jraBg.png" /><figcaption>Source image from google</figcaption></figure><p>One fine day two farmers were harvesting their crops in the field. “1st farmer”, says “I put all my energy into this”, ”2nd farmer”, says “I invest a lot in this”, and both “by selling these crops in the market we can earn more”.</p><p>suddenly they found a small box inside the rocks and soil. they both thought this box could have gold coins in it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*i2nZ_gjY2Lvs6YzJ7K-9BA.jpeg" /><figcaption>Source image from google</figcaption></figure><p>they tried but were unable to open the box, by that time a technician goes that way with his tools. so they called a technician to open the box. the technician tried and opened the box.</p><p>they were both disheartened when they found there is nothing else than a paper in it. but, the technician started reading the paper, then he said: “this is not just a paper this is a roadmap to the gold treasure”.</p><p>Unexpected right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*7R7gakLc0oPYAMuRdOFRdw.png" /><figcaption>Source image from google</figcaption></figure><p>now read this story once again but this time change “1st farmer” to “business owner”, “2nd farmer” to “investor” and “technician” to “Data professionals”.</p><p>through business, you can generate tons of data but if you failed to get insights from it, it’s useless!</p><p>I hope it brings you value 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=584198613797" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>