<?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 Smith Flores on Medium]]></title>
        <description><![CDATA[Stories by Smith Flores on Medium]]></description>
        <link>https://medium.com/@3344?source=rss-fef46b04fe38------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*l1rqV37uQiv5cXROTRtWrg.jpeg</url>
            <title>Stories by Smith Flores on Medium</title>
            <link>https://medium.com/@3344?source=rss-fef46b04fe38------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:34:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@3344/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[Activation functions]]></title>
            <link>https://3344.medium.com/activation-functions-1dae8fedd951?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dae8fedd951</guid>
            <category><![CDATA[activation-functions]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Mon, 16 May 2022 14:15:03 GMT</pubDate>
            <atom:updated>2022-05-16T14:15:03.551Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/816/0*LsOuo_SPh7wq4tqH.png" /></figure><p>Activation functions live inside neural network layers and modify the data they receive before passing it to the next layer. Activation functions give neural networks their power — allowing them to model complex non-linear relationships. By modifying inputs with non-linear functions neural networks can model highly complex relationships between features.</p><p>Activation functions typically have the following properties:</p><ul><li>Non-linear</li></ul><p>In linear regression we’re limited to a prediction equation that looks like a straight line. This is nice for simple datasets with a one-to-one relationship between inputs and outputs, but what if the patterns in our dataset were non-linear? (e.g. x2, sin, log). To model these relationships we need a non-linear prediction equation. Activation functions provide this non-linearity.</p><ul><li>Continuously differentiable</li></ul><p>To improve our model with gradient descent, we need our output to have a nice slope so we can compute error derivatives with respect to weights. If our neuron instead outputted 0 or 1 (perceptron), we wouldn’t know in which direction to update our weights to reduce our error.</p><ul><li>Fixed Range</li></ul><p>Activation functions typically squash the input data into a narrow range that makes training the model more stable and efficient.</p><h4>Linear</h4><p>A straight line function where activation is proportional to input ( which is the weighted sum from neuron ).</p><p>Function</p><p><em>f</em>(<em>x</em>)=<em>b</em>+<em>mx</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/0*dGLONfkNg_T9Fcrp.png" /></figure><p>Derivative</p><p><em>f</em>′’(<em>x</em>)=<em>m</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*uHZt3EEPDqHMN7Wz.png" /></figure><p>Pros</p><ul><li>It gives a range of activations, so it is not binary activation.</li><li>We can definitely connect a few neurons together and if more than 1 fires, we could take the max ( or softmax) and decide based on that.</li></ul><p>Cons</p><ul><li>For this function, derivative is a constant. That means, the gradient has no relationship with X.</li><li>It is a constant gradient and the descent is going to be on constant gradient.</li><li>If there is an error in prediction, the changes made by back propagation is constant and not depending on the change in input delta(x) !</li></ul><h4>ELU</h4><p>Exponential Linear Unit or its widely known name ELU is a function that tend to converge cost to zero faster and produce more accurate results. Different to other activation functions, ELU has a extra alpha constant which should be positive number.</p><p>ELU is very similiar to RELU except negative inputs. They are both in identity function form for non-negative inputs. On the other hand, ELU becomes smooth slowly until its output equal to -α whereas RELU sharply smoothes.</p><p>Function</p><p><em>R</em>(<em>z</em>)=<em>z</em> ; <em>z</em>&gt;0</p><p>R(z)=α.(e^z−1) ; z≤0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/0*tBlZS3QgZwREtXCY.png" /></figure><p>Derivative</p><p><em>f’</em>(<em>x</em>) = 1 ; <em>z </em>&gt; 0</p><p><em>f</em>′(<em>x</em>) = <em>αe^z</em> ; <em>z </em>&lt; 0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/0*gYsZWN_kiiVutZ8M.png" /></figure><p>Pros</p><ul><li>ELU becomes smooth slowly until its output equal to −α-\alpha−<em>α</em> whereas RELU sharply smoothes.</li><li>ELU is a strong alternative to ReLU.</li><li>Unlike to ReLU, ELU can produce negative outputs.</li></ul><p>Cons</p><ul><li>For x &gt; 0, it can blow up the activation with the output range of [0,∞].</li></ul><h4>ReLU</h4><p>A recent invention which stands for Rectified Linear Units. The formula is deceptively simple: max(0,z)max(0,z)<em>max</em>(0,<em>z</em>). Despite its name and appearance, it’s not linear and provides the same benefits as Sigmoid (i.e. the ability to learn nonlinear functions), but with better performance.</p><p>Function</p><p><em>R</em>(<em>z</em>) = <em>z</em> ; <em>z </em>&gt; 0</p><p><em>R</em>(<em>z</em>) = 0 ; <em>z </em>≤ 0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/0*MHLnNDLAx07mHz_j.png" /></figure><p>Derivative</p><p><em>f’</em>′(<em>x</em>) = 1 ; <em>z </em>&gt; 0</p><p><em>f</em>′’(<em>x</em>) = 0 ; <em>z </em>&lt; 0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/0*geNEOuH_4uUIHOz8.png" /></figure><p>Pros</p><ul><li>It avoids and rectifies vanishing gradient problem.</li><li>ReLu is less computationally expensive than tanh and sigmoid because it involves simpler mathematical operations.</li></ul><p>Cons</p><ul><li>One of its limitations is that it should only be used within hidden layers of a neural network model.</li><li>Some gradients can be fragile during training and can die. It can cause a weight update which will makes it never activate on any data point again. In other words, ReLu can result in dead neurons.</li><li>In another words, For activations in the region (x&lt;0) of ReLu, gradient will be 0 because of which the weights will not get adjusted during descent. That means, those neurons which go into that state will stop responding to variations in error/ input (simply because gradient is 0, nothing changes). This is called the dying ReLu problem.</li><li>The range of ReLu is [0,∞). This means it can blow up the activation.</li></ul><h4>LeakyReLU</h4><p>LeakyRelu is a variant of ReLU. Instead of being 000 when z&lt;0 , a leaky ReLU allows a small, non-zero, constant gradient α\alpha<em>α</em> (Normally, α=0.01). However, the consistency of the benefit across tasks is presently unclear.</p><p>Function</p><p><em>R</em>(<em>z</em>) = <em>z</em> ; <em>z </em>&gt; 0</p><p><em>R</em>(<em>z</em>) = <em>αz</em> ; <em>z </em>≤ 0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*syGxppnmwYGdi12G.png" /></figure><p>Derivative</p><p><em>f</em>′’(<em>x</em>) = 1 ; <em>z </em>&gt; 0</p><p><em>f</em>′’(<em>x</em>) = <em>α</em> ; <em>z </em>&lt; 0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*4SBzOX6Is9qp9cz9.png" /></figure><p>Pros</p><p>Leaky ReLUs are one attempt to fix the “dying ReLU” problem by having a small negative slope (of 0.01, or so).</p><p>Cons</p><p>As it possess linearity, it can’t be used for the complex Classification. It lags behind the Sigmoid and Tanh for some of the use cases.</p><h4>Sigmoid</h4><p>Sigmoid takes a real value as input and outputs another value between 0 and 1. It’s easy to work with and has all the nice properties of activation functions: it’s non-linear, continuously differentiable, monotonic, and has a fixed output range.</p><p>Function</p><p><em>S</em>(<em>z</em>)=1 / (1+<em>e^(</em>−<em>z))</em>​</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/0*q2489FaYSFM9XmQ0.png" /></figure><p>Derivative</p><p><em>S</em>′(<em>x</em>)=<em>S</em>(<em>x</em>)*(1−<em>S</em>(<em>x</em>))</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/0*hgRSGczZ4JWNnU1C.png" /></figure><p>Pros</p><ul><li>It is nonlinear in nature. Combinations of this function are also nonlinear!</li><li>It will give an analog activation unlike step function.</li><li>It has a smooth gradient too.</li><li>It’s good for a classifier.</li><li>The output of the activation function is always going to be in range (0,1) compared to (-inf, inf) of linear function. So we have our activations bound in a range. Nice, it won’t blow up the activations then.</li></ul><p>Cons</p><ul><li>Towards either end of the sigmoid function, the Y values tend to respond very less to changes in X.</li><li>It gives rise to a problem of “vanishing gradients”.</li><li>Its output isn’t zero centered. It makes the gradient updates go too far in different directions. 0 &lt; output &lt; 1, and it makes optimization harder.</li><li>Sigmoids saturate and kill gradients.</li><li>The network refuses to learn further or is drastically slow ( depending on use case and until gradient /computation gets hit by floating point value limits ).</li></ul><h4>Tanh</h4><p>Tanh squashes a real-valued number to the range [−1,1]. It’s non-linear. But unlike Sigmoid, its output is zero-centered. Therefore, in practice the tanh non-linearity is always preferred to the sigmoid nonlinearity.</p><p>Function</p><p><em>tanh</em>(<em>z</em>) = [<em>e^z</em>+<em>e^(</em>−<em>z) ] / [e^z </em>− <em>e^(</em>−<em>z) ]</em>​</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*mJZ0BJsaWOdXUItY.png" /></figure><p>Derivative</p><p><em>tanh</em>′(<em>z</em>) = 1 − <em>tanh</em>(<em>z</em>)^2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*MW7dGYBsYT08EAVm.png" /></figure><p>Pros</p><ul><li>The gradient is stronger for tanh than sigmoid ( derivatives are steeper).</li></ul><p>Cons</p><ul><li>Tanh also has the vanishing gradient problem.</li></ul><h4>Softmax</h4><p>Softmax function calculates the probabilities distribution of the event over ’n’ different events. In general way of saying, this function will calculate the probabilities of each target class over all possible target classes. Later the calculated probabilities will be helpful for determining the target class for the given inputs.</p><p>I hope you have enjoyed reading this blog and learned the importance, advantages and disadvantages of activation functions. :)</p><blockquote>“Artificial intelligence is not just learning patterns from data, but understanding human emotions and their evolution from their depth and not only meeting human requirements at the surface level, but sensitivity towards human pain, happiness, mistakes , the sufferings and the well-being of society are the parts of the new evolving AI systems”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*oI4yzXVR4yMJkd903hooyA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dae8fedd951" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is IoT]]></title>
            <link>https://3344.medium.com/what-is-iot-bde7829d1c95?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/bde7829d1c95</guid>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Mon, 03 Jan 2022 04:10:01 GMT</pubDate>
            <atom:updated>2022-01-03T04:10:01.843Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/885/0*FtEBwf_A30TxTr90.png" /></figure><p>As someone who works for an Internet of Things (IoT) software company, this is a question that I’m asked frequently. Whether it’s a friend, family member, or stranger, when the conversation turns to what I do, I inevitably find that I need to first explain what IoT is.</p><p>I’ve also found that if you just Google “what is IoT,” many of the answers are unnecessarily technical. Case in point:</p><blockquote><em>“The Internet of Things (IoT) is a system of interrelated computing devices, mechanical and digital machines, objects, animals or people that are provided with unique identifiers and the ability to transfer data over a network without requiring human-to-human or human-to-computer interaction.”<br> — An unnecessarily technical explanation of IoT</em></blockquote><p>If you just read that and thought, “ok, so what?”, you’re not alone. Most people don’t want to nor need to dive into the nitty-gritty of IoT. So in this post, I’ll provide you with a simple explanation of the Internet of Things and what it means for you. This can also serve as a resource to share with others who need an introduction to IoT (like friends, family members, or customers).</p><p>Before we jump in, note that “The Internet of Things” and “IoT” can and will be used interchangeably. And a quick tip to sound knowledgeable: avoid saying “the IoT” 😉</p><h3>A Simple, Non-Technical Explanation of the Internet of Things</h3><p>How are you reading this post right now? It might be on desktop, on mobile, maybe a tablet, but whatever device you’re using, it’s most definitely connected to the internet.</p><p>An internet connection is a wonderful thing, it give us all sorts of benefits that just weren’t possible before. If you’re old enough, think of your cellphone <em>before</em> it was a smartphone. You could call and you could text sure, but now you can read any book, watch any movie, or listen to any song all in the palm of your hand. And that’s just to name a few of the incredible things your smartphone can do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*zWgQqbuCRcxi1NcU" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/0*lkS97LQPMZCA8lu6.jpeg" /></figure><p>The point is that connecting things to the internet yields many amazing benefits. We’ve all seen these benefits with our smartphones, laptops, and tablets, but this is true for everything else too. And yes, I do mean <em>everything</em>.</p><p>The Internet of Things is actually a pretty simple concept, <strong>it means taking all the things in the world and connecting them to the internet</strong>.</p><p>I think that confusion arises not because the concept is so narrow and tightly defined, but rather because it’s so broad and loosely defined. It can be hard to nail down the concept in your head when there are so many examples and possibilities in IoT.</p><p>To help clarify, I think it’s important to understand the benefits of connecting things to the internet. Why would we even want to connect everything to the internet?</p><h3>Why IoT Matters</h3><p>When something is connected to the internet, that means that it can send information or receive information, or both. This ability to send and/or receive information makes things smart, and smart is good.</p><p>Let’s use smartphones (<strong>smart</strong>phones) again as an example. Right now you can listen to just about any song in the world, but it’s not because your phone actually has every song in the world stored on it. It’s because every song in the world is stored somewhere else, but your phone can send information (asking for that song) and then receive information (streaming that song on your phone).</p><p>To be smart, a thing doesn’t need to have super storage or a super computer inside of it. All a thing has to do is <em>connect</em> to super storage or to a super computer. Being connected is awesome.</p><p>In the Internet of Things, all the things that are being connected to the internet can be put into three categories:</p><ol><li>Things that collect information and then send it.</li><li>Things that receive information and then act on it.</li><li>Things that do both.</li></ol><p>And all three of these have enormous benefits that feed on each other.</p><h3>Collecting and Sending Information</h3><p>This means sensors. Sensors could be temperature sensors, motion sensors, moisture sensors, air quality sensors, light sensors, you name it. These sensors, along with a connection, allow us to automatically collect information from the environment which, in turn, allows us to make more intelligent decisions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*dbnTZTq-aPYKK4Wl" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/0*wmGOjySdviEuPy3A.jpeg" /></figure><p>Soil moisture sensor</p><p>On the farm, automatically getting information about the soil moisture can tell farmers exactly when their crops need to be watered. Instead of watering too much (which can be an expensive over-use of irrigation systems) or watering too little (which can be an expensive loss of crops), the farmer can ensure that crops get exactly the right amount of water. More money for farmers and more food for the world!</p><p>Just as our sight, hearing, smell, touch, and taste allow us, humans, to make sense of the world, sensors allow machines to make sense of the world.</p><h3>Receiving and Acting on Information</h3><p>We’re all very familiar with machines getting information and then acting. Your printer receives a document and it prints it. Your car receives a signal from your car keys and the doors open. The examples are endless.</p><p>Whether it’s a simple as sending the command “turn on” or as complex as sending a 3D model to a 3D printer, we know that we can tell machines what to do from far away. So what?</p><p>The real power of the Internet of Things arises when things can do both of the above. Things that collect information and send it, but also receive information and act on it.</p><h3>Doing Both</h3><p>Let’s quickly go back to the farming example. The sensors can collect information about the soil moisture to tell the farmer how much to water the crops, but you don’t actually need the farmer. Instead, the irrigation system can automatically turn on as needed, based on how much moisture is in the soil.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*t7wT5ecI5nIjk6na" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*3cBe9SrwAI6UF-mo.jpeg" /></figure><p>You can take it a step further too. If the irrigation system receives information about the weather from its internet connection, it can also know when it’s going to rain and decide not to water the crops today because they’ll be watered by the rain anyways.</p><p>And it doesn’t stop there! All this information about the soil moisture, how much the irrigation system is watering the crops, and how well the crops actually grow can be collected and sent to supercomputers that run amazing algorithms that can make sense of all this information.</p><p>And that’s just one kind of sensor. Add in other sensors like light, air quality, and temperature, and these algorithms can learn much much more. With dozens, hundreds, thousands of farms all collecting this information, these algorithms can create incredible insights into how to make crops grow the best, helping to feed the world.</p><blockquote>success is the sum of small efforts repeated day after day</blockquote><p>I hope you enjoyed this …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*oI4yzXVR4yMJkd903hooyA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bde7829d1c95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursion !]]></title>
            <link>https://3344.medium.com/recursion-837658951b9d?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/837658951b9d</guid>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Wed, 03 Nov 2021 04:09:40 GMT</pubDate>
            <atom:updated>2021-11-03T04:09:40.795Z</atom:updated>
            <content:encoded><![CDATA[<h3>Recursion !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*nw_7qYhxZo2sxHFSYrdY9Q.gif" /></figure><h3>What is recursion?</h3><p>Recursion is called a process by which a function calls itself repeatedly, until a certain condition is satisfied, if there is no specific case that terminates the recursion, an infinite loop could be created.</p><h4>Example:</h4><p>Calculate the power of a number using recursion:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*3VDydfXPtTbcK2Ph6XzFuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*WzuQ15zOoRzlaEPecHd6Gw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*rM8KVgtIQ2KMCwjQF-kgkg.png" /></figure><p>Now let’s see how this would look step by step using stack and LIFO method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*ZDUTAU-cRzkrUzDuQY47Dw.png" /></figure><h4>Final result = 25</h4><p>I hope you enjoyed reading this blog and learned what you need to know about recursion</p><blockquote>A dream doesn’t magically come true, it takes sweat, determination and hard work — Colin Powell</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*oI4yzXVR4yMJkd903hooyA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=837658951b9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python3: Mutable, Immutable… everything is object!!!]]></title>
            <link>https://3344.medium.com/python3-mutable-immutable-everything-is-object-7fe7252940de?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fe7252940de</guid>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Mon, 11 Oct 2021 08:39:07 GMT</pubDate>
            <atom:updated>2021-10-11T08:39:07.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*rN1lL-d7ANKt1SZahUyCeA.jpeg" /></figure><p>Python is an object-oriented programming language, and in Python everything is an object. Almost every object has some metadata (called <em>attributes</em>) and associated functionality (called <em>methods</em>). Even these attributes and methods of objects are themselves objects with their own type information.</p><p>Every object can be assigned to a variable or passed as an argument to a function.</p><h3>Understand ID and Type Function</h3><p>The integrated<strong> id()</strong> method contains an object’s id as just an integer. That integer normally refers to the storage position of the object. The ‘<strong>is</strong>’ operator relates the identities of two objects to each other. The integrated function, <strong>type()</strong>, returns the kind of an object. Compare two variables ‘<strong>x</strong>’ and ‘<strong>y</strong>’, having the same value, using equality operator ‘<strong>x == y</strong>’, it will output <strong>True</strong>. Using the <strong>id() function</strong>, we have compared the<strong> memory addresses</strong> of both variables, it will output <strong>False</strong> because both variables are different and located at different memory locations, although the values they contain are the same.</p><h3>Mutable vs. Immutable</h3><p><strong>Mutable</strong> entities can <strong>alter</strong> their <strong>state or substance</strong> to describe the disparity, and <strong>immutable</strong> entities can’t alter their state or substance. So when an object is created, a special<strong> object ID</strong> is allocated. At runtime, the kind of object is specified and it cannot be updated later. Built-in forms such as int, float, bool, str, tuple, and Unicode variables are immutable. Objects such as list, set, byte arrays, and dictionary of built-in categories are mutable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ESspXjkRXC4uLBuO.png" /></figure><p>Make another variable ‘<strong>z</strong>’ which points to the identical entity that ‘<strong>x</strong>’ is directing to, using assignment operator ‘<strong>=</strong>’. Using the ‘<strong>is</strong>’ operator we have found that they both, point to the same object and have the same memory addresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/0*aCIddgNw73B2Aptx.png" /></figure><h3>Immutable Variable Types</h3><p>Let’s have a look at some immutable variable types.</p><h3>Integer DataType</h3><p>Let’s define a variable ‘<strong>x</strong>’ having a value ‘<strong>10</strong>’. A built-in <strong>id() method</strong> is used to find out the location of ‘<strong>x</strong>’ in memory and <strong>type()</strong> is used to identify its type. When we try to change the value of ‘<strong>x</strong>’, it is successfully changed, although the memory address returns differently. It is because we haven’t actually changed the value of ‘<strong>x</strong>’, but we have created another object with the same name ‘<strong>x</strong>’ and assign it a different value. We have bonded the name ‘<strong>x</strong>’ to the new value. Now, whenever you call ‘<strong>x</strong>’ it will output the new value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/0*xvI5-aHy2-6BnOkS.png" /></figure><h3>String DataType</h3><p>Same for the string data type, we cannot modify the existing <strong>variable</strong> but we have to <strong>create</strong> a new one with the same name. Here we have <strong>defined</strong> a string variable ‘<strong>x</strong>’ and want to add ‘<strong>w</strong>’ to its zero indexes. It will output <strong>TypeError</strong>, showing that the string object doesn’t support update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/0*4Oq8p40YnJtretz5.png" /></figure><h3>Tuple DataType</h3><p>Have a glimpse of a tuple type <strong>variable</strong>, we have defined a <strong>tuple</strong> with 4 values. We have used the<strong> id() function</strong> to output its address. When we want to change its value at <strong>0 indexes</strong>, it gives the <strong>TypeError</strong> that tuple doesn’t support item assignment or update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/0*NEa0W9izkenVXHqG.png" /></figure><p>On the contrary, you can <strong>update</strong> the entire tuple by defining it from <strong>scratch</strong>. Now, whenever you check it, you will find a new value and a new address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/0*Usj2rAInQkKJriPY.png" /></figure><h3>Float DataType</h3><p>We have a float type variable ‘<strong>x</strong>’. Using the<strong> id() function</strong>, we have to find out its address. When we want to change its value at<strong> index 1</strong>, it gives the <strong>TypeError</strong> that float doesn’t support item modification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/0*WIkD2Cz4mu9j5TrY.png" /></figure><p>Conversely, we have updated the <strong>float</strong> by defining it again. Now, whenever we call it, we will find a new value and a new address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/0*hRKLc1HD9d56UTX1.png" /></figure><h3>Mutable Variable Types</h3><p>Now we will be looking at some mutable variable types.</p><h3>List DataType</h3><p>We have defined a <strong>list</strong> named ‘<strong>x</strong>’ and add some values to it. While <strong>run</strong>, it will display list values. When you <strong>update</strong> the list by assigning new values to <strong>index 0 and 2</strong>, it will successfully do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/0*OoNSUkMirGD2eY8q.png" /></figure><p>The above described example is a simple and basic example of modification. To check mutability to a different level, let’s take a look at the same example with little change. We have created a new name ‘<strong>y</strong>’ and bound it to the same list object. When we checked if the ‘<strong>x</strong>’ is the same as ‘<strong>y</strong>’, it returns True. On the other hand, both ‘<strong>x</strong>’ and ‘<strong>y</strong>’ have the <strong>same</strong> memory <strong>addresses</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/0*5YXOM4LBAmFRv5Uu.png" /></figure><p>Now append a new value to a<strong> list name ‘x’</strong> and check the updated output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/0*lyNo6ahQ4y4kc3vX.png" /></figure><p>Now, when you check for list <strong>name ‘y’</strong>, it will display the same list as it displays for ‘x’. That means, when we update the same object list, which has two different names ‘x’ and ‘y’. Both are the same and share the same memory addresses even after the modification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/0*tR4cgLpV0rPvGjJD.png" /></figure><h3>Dictionary DataType</h3><p>As dictionaries are commonly used variables in Python, let’s have a look at the mutability of dictionaries. We have defined a dictionary named ‘<strong>dict</strong>’ with three keys and their values. When we print it out, it will display all contents of it. You can print each dictionary value separately, as well as using their <strong>keys</strong> instead of indexes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/0*8ZSxZwNbtCcJOJVe.png" /></figure><p>We want to <strong>change</strong> the particular value by updating the<strong> key ‘Name’</strong>. It will output the updated dictionary. Dictionary keys are immutable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*h_OduH6XySyZDA-F.png" /></figure><p>Let’s define a <strong>list</strong> and <strong>tuple</strong> separately. Make sure that <strong>tuple</strong> must have a<strong> list type value</strong> in it and a list have a<strong> tuple type value</strong> in it consequently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/0*e7l1KOwLva3rf7Xf.png" /></figure><p>A <strong>tuple</strong> has a <strong>list</strong> on its <strong>0 indexes</strong> so when you change at the <strong>0 indexes</strong> of a tuple, you have to mention the <strong>index</strong> of a list where you want to change. Change occurs because the list is immutable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/0*U9FIg3lHyV-0O_zx.png" /></figure><p>On the contrary, the list variable can’t be updated because it has a <strong>tuple</strong> on <strong>0 index</strong>, which is mutable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*pfAN5fktJNUjXC5b.png" /></figure><h3>Conclusion</h3><p>We have seen variations in Python between mutable and immutable. You have to make your mind clear that everything in Python is referred to as an object. Primarily, the distinction among objects that are mutable vs. immutable.</p><p>I hope you have enjoyed reading the content))</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*oI4yzXVR4yMJkd903hooyA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fe7252940de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Class and instance attributes]]></title>
            <link>https://3344.medium.com/class-and-instance-attributes-177cd27d47de?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/177cd27d47de</guid>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Mon, 11 Oct 2021 07:46:01 GMT</pubDate>
            <atom:updated>2021-10-11T07:46:01.944Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzufWCO6Eqa4FTvLTNwsKQ.png" /></figure><p>Object Oriented Programming is not a programming language, but rather a model in which programs are organized around data or objects. OOP uses the concept of objects and classes. A class can be thought of as a ‘blueprint’ for objects. These can have their own attributes (characteristics), and methods (actions they perform). In Python everything is an object. Objects are a representation of real world objects like cars, dogs, house, etc. They all share data and behavior.</p><p>As an object oriented language, Python provides two scopes for attributes: class attributes and instance attributes. Think of a Class like a blueprint from which different objects are created with the same blueprint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*uFg3X5ZYitEFdPDl.png" /></figure><p>Each object, or in this case a car, is an instance of class car (image below). The cars can have data like number of wheels, doors, seating capacity, and behaviors: accelerate, stop, display how much fuel is left and more. Data in a class are called <strong>attributes </strong>and behaviors are called <strong>methods</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/0*qj8hzfLaZ_usXSrU.png" /></figure><p>Data → Attributes &amp; Behavior → Methods</p><p>Again, a class is like a blueprint for which other objects can be created. So with class instrument, objects like piano and guitar can be made. From guitar other objects can be made from it and they also can inherit attributes and methods from guitar and instrument if applied to them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*zWAhouXT068yi4HH.png" /></figure><h4>Class Attribute vs. Instance Attribute</h4><ul><li>An instance attribute is a Python variable belonging to one, and only one, object. This variable is only accessible in the scope of this object and it is defined inside the constructor function, __init__(self,..) of the class.</li><li>A class attribute is a Python variable that belongs to a class rather than a particular object. It is shared between all the objects of this class and it is defined outside the constructor function, __init__(self,...), of the class.</li></ul><p>The below ExampleClass is a basic Python class with two attributes: class_attr and instance_attr.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*DzmPNnaXXzvTjWcJHuAPgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y_drVJ-Qeagvw4HjcNCmRg.png" /></figure><h3>__dict__</h3><p>A __dict__ is a dictionary or maping objet used to store an object’s attributes. How does Python deal with the object and class attributes using the __dict__ ? Well, each instance is stored in a dictonary.</p><p>A class, functions as a template that defines the basic characters of a particular object. Here’s an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8kI18i-YujM3gZxosXbssA.png" /></figure><p>There are few things to note when looking at the above example.</p><ol><li>The class is made up of <strong><em>attributes</em></strong>(data) and <strong><em>methods</em></strong>(functions).</li><li>Attributes and methods are simply defined as normal variables and functions.</li><li>As noted in the corresponding docstring, the <strong>__init__() </strong>method is called the <strong><em>initializer </em></strong>. It’s equivalent to the constructor in other object oriented languages, and is the method that is first run when you create a new object, or new instance of the class.</li><li>Attributes that aply to the whole class are defined first, and are called <strong><em>class attributes.</em></strong></li><li>Attributes that aply to a specific instance of a class (an object) are called <strong><em>instance attributes</em></strong>. They are generally defined <strong>__init__()</strong>; this is not necessary, but it is recomended (since attributes defined outside of <strong>__init__()</strong> run the risk of being accessed before they are defined).</li><li>Every method , include in the class definition passes the object in question as its first parameter. The word <strong>self </strong>is used for this parameter (usage of <strong>self</strong> is actually by convention, as the word <strong>self </strong>has no inherent meaning in Python, but this is one of Python’s most respected conventions, and you should always follow it).</li><li>Some of the class’s methods have the following form: <strong>__FunctionName__(self, other stuff)</strong>. All such methods are called “Magic methods ” and are important part of classes in Python.</li></ol><blockquote>Life is a preparation for the future, and the best preparation for the future is to live as if there were none.</blockquote><blockquote>Albert Einstein</blockquote><p>I hope you have enjoyed reading the content))</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*oI4yzXVR4yMJkd903hooyA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=177cd27d47de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Libraries in C]]></title>
            <link>https://3344.medium.com/libraries-in-c-85938a71e5ac?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/85938a71e5ac</guid>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Sat, 25 Sep 2021 01:09:48 GMT</pubDate>
            <atom:updated>2021-09-25T01:09:48.267Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PPhpgptkClzPfkSB.jpg" /></figure><h3>What are libraries and why use libraries in c ?</h3><p>A library is a file containing several object files, that can be used as a single entity in a linking phase of a program. Normally the library is indexed, so it is easy to find symbols (functions, variables and so on) in them. For this reason, linking a program whose object files are ordered in libraries is faster than linking a program whose object files are separate on the disk. Also, when using a library, we have fewer files to look for and open, which even further speeds up linking.</p><h3>Types of libraries in C:</h3><p>There are two types of libraries in C.</p><h3>Static libraries</h3><p>Static libraries are just collections of object files that are linked into the program during the linking phase of compilation, and are not relevant during runtime. This last comment seems obvious, as we already know that object files are also used only during the linking phase, and are not required during runtime — only the program’s executable file is needed in order to run the program.</p><h3>Shared or dynamic libraries</h3><p>Shared libraries are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries. However, the object files from the dynamic library are not inserted into the executable file. Instead, when the program is started, a program in the system (called a dynamic loader) checks out which shared libraries were linked with the program, loads them to memory, and attaches them to the copy of the program in memory.</p><h3>How static libraries work</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*InIrJkkNrzohJd6i" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/0*zxM4ifzF1ohJXRD7.png" /></figure><h3>What is the difference between them</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*uwbV0MnuqUlEtzQl.png" /></figure><h3>Creating A Static “C” Library</h3><p>First compile all your files *.c with “gcc” and the flag “-c” it would look something like this :</p><pre>gcc -c *.c</pre><p>This will create * .o files that will serve us to create the library, for that we need to use the following command:</p><pre>ar -rc liball.a *.o</pre><p>This command creates a static library named ‘libutil.a’ and puts copie of the object file “util_file.o” .If the library file already exists, it has the object file added to it, or replaced, if they are newer than those inside the library. The &#39;c&#39; flag tells ar to create the library if it doesn&#39;t already exist. The &#39;r&#39; flag tells it to replace older object file in the library, with the new object file.</p><p>After an archive is created, or modified, there is a need to index it. This index is later used by the compiler to speed up symbol-lookup inside the library, and to make sure that the order of the symbols in the library won’t matter during compilation.The command used to create or update the index is called &#39;ranlib&#39;, and is invoked as follows:</p><pre>ranlib liball.a</pre><p><em>Note</em>: when an archive file’s index generation date (stored inside the archive file) is older than the file’s last modification date (stored in the file system), a compiler trying to use this library will complain its index is out of date, and abort. There are two ways to overcome the problem:</p><ol><li>Use &#39;ranlib&#39; to re-generate the index.</li><li>When copying the archive file to another location, use &#39;cp -p&#39;, instead of only &#39;cp&#39;. The &#39;-p&#39; flag tells &#39;cp&#39; to keep all attributes of the file, including its access permissions, owner (if &quot;cp&quot; is invoked by a superuser) and its last modification date. This will cause the compiler to think the index inside the file is still updated. This method is useful for makefiles that need to copy the library to another directory for some reason.</li></ol><h3>How to use libraries in C</h3><p>After we created our archive, we want to use it in a program. This is done by adding the library’s name to the list of object file names given to the linker, using a special flag, normally &#39;-l&#39;. Here is an example:</p><p>gcc main.o -L. -lutil -o prog</p><p>This will create a program using object file “main.o”, and any symbols it requires from the “util” static library. Note that we omitted the “lib” prefix and the “.a” suffix when mentioning the library on the link command. The linker attaches these parts back to the name of the library to create a name of a file to look for. Note also the usage of the &#39;-L&#39; flag - this flag tells the linker that libraries might be found in the given directory (&#39;.&#39;, refering to the current directory), in addition to the standard locations where the compiler looks for system libraries.</p><h4>Example:</h4><p>Create a Static library from the following * .c files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*H-sVV6p1KwRJhQGe935UlA.png" /></figure><p>First setp compiple with gcc and obtain files *.o:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*l1ILwbBnIRS0Kx969EsphA.png" /></figure><p>using the command to create lirabrie with files *.o : ar rc libutil.a util_file.o</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D6oAaiHR-AZbtrYYUkhQgQ.png" /></figure><p>this created the file libHolbertonSchool.a, after this we can use ‘ranlib’ to generate the index , And our dynamic library would already be created</p><h3>Creating A Dynamic “C” Library</h3><p>The way to create a Dynamic Library in Linux is with the gcc command using the -c to generate the object files (.o) from the source files (.c) and the -fPIC to make the code position independent. Thus, the following command makes a bunch of .o files from each .c file in the current directory (You can select which functions you want for your library).</p><pre>gcc -c -fPIC *.c</pre><p>Next, we are going to put together those objects files into one library. To do this as a Dynamic Library we also use gcc but with the -shared option. The -o is to specify the name of the file you want it to have.</p><pre>gcc -shared -o liball.so *.o</pre><p>This way you must have your library created. To verify that you did it and have the right functions as dynamic symbols you can use:</p><pre>nm -D liball.so</pre><p>Great! at this point, you have your Dynamic Library created!</p><h3>How to use it</h3><p>Now, you have to compile the library with your main.c file to link it and use it as you want. For this to work, you have to add the location of your library files into the environmental variable to know where to find the functions.</p><pre>export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH</pre><p>Then, you can compile it by typing the following:</p><pre>gcc -L . 0-main.c -l all -o example</pre><p>Note that the name we gave to the library in this example was ‘all’. Here we use the -L option to tell the program where to find the library, in this case . that refers to the current directory. The -l option is to tell the compiler to look for the library.</p><p>Example:</p><p>Create a Dynamic library from the following * .c files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*jq2buG7QipjRUqFSWlOYJA.png" /></figure><p>Compile files *.c with gcc [ gcc *.c -c -fpic ]:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*QLDCjLtbCT-OGlu3nM3M2g.png" /></figure><p>This created files *.o after this use [ gcc *.o -shared -o libHolberton.so ]:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8GLFbgLsY6sZBxJGc-Zgzg.png" /></figure><p>This will produce the file libHolberton.so and that is all , enjoy your dynamic library :)</p><p>To see your librarie use the next command :</p><p>[ nm -D — defined-only libHolberton.so ]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nHKpUQVZ_K5GVdR9yNPBiA.png" /></figure><blockquote>Only those who risk going too far can discover how far they can go — T.S. Eliot</blockquote><p>I hope this article has helped you understand about C libraries and their great importance in programming in C and C++. Grettings!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*oI4yzXVR4yMJkd903hooyA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85938a71e5ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens when you type `ls -l *.c` in the shell ?]]></title>
            <link>https://3344.medium.com/what-happens-when-you-type-ls-l-c-in-the-shell-9f71fad8c2d9?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f71fad8c2d9</guid>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Thu, 26 Aug 2021 04:58:17 GMT</pubDate>
            <atom:updated>2021-08-26T04:58:17.878Z</atom:updated>
            <content:encoded><![CDATA[<h3>What happens when you type `ls -l *.c` in the shell ?</h3><p><em>ls </em>is one of the most common commands in a Linux shell and probably the first command that you would use when learning Linux. Let’s take a look at what ls does when we enter it in a shell:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UjiCNjxeJwx5XHWHvW1ymA.png" /></figure><p>As you can see it prints all available files and folders in the current path or directory. Normally,this list is sorted alphabetically . However, you are able to sort it the way you want. The command ‘man’ ca help us access the manual page of ls within the terminal. This displays all the different options or flags that can be applied together with ls for more advanced uses.</p><p>Getting back to the question, the second part of the command is ‘*.c’ which consists of a wildcard (*) and an extension (.c). The place that an asterisk is used can take any character zero or more times. Needless to say, files that end with the extension “.c” extension are calledC files , so the output of the command simply lists all C files which are present in the current directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*7Gniz2UdGWaYcH1UJVtM3Q.png" /></figure><p>In the picture above, after entering ‘ls -l *.c’, 11 files with the extension ‘.c’ have been listed in the current directory:</p><h3>But, what really happens when we type ‘ls -l *.c’ and press enter?</h3><ul><li><strong><em>Feeding the command to the bash!</em></strong> : After <strong>ls</strong> is entered, the keyboard driver realizes that characters have been entered and pushes them to the shell. The string is passed as one single string .This is then split into tokens by excluding the white spaces. Our command has now three tokens, ‘ls’, ‘-l’ and ‘*.c’.This is placed in an array of strings. This whole process is known as <strong><em>Tokenization</em></strong>.</li></ul><ol><li>Now that the array is tokenized, we need to see if each token has an alias assigned. If an alias is found it is stored as a token after removing the spaces like before and again it is checked for aliases. Normally, an alias is stored in the following files:~/.bashrc, ~/.bash_profile, /etc/bashrc, /etc/profile.</li><li>Next, the computer checks if tokens are built-in functions or not. If the command is a built in, the shell runs the command directly, without using another program. For example, ‘cd’ is a built in; however, ‘ls’ is not a built in , so now system needs to find the executable or program for ‘ls’.</li><li><strong><em>Interpreting and finding the executable for the command :</em></strong> After that, the bash interprets the command. The first search for the command ‘ls’ is done through <strong>$PATH</strong>. $PATH is an environmental variable which holds the paths of all executable programs. The search calls a series of functions like find_user_command() ,find_user_command_in_path , find_in_path_element. Each path in the PATH variable is searched for the executable that corresponds the command ‘<strong>ls</strong>’. BASH invokes the function stat() to check if there is a matching executable in each path.</li><li><strong><em>Pulling the executable to memory : </em></strong>After all these,<strong><em> </em></strong><em>w</em>hen when the file is located at ‘/usr/bin/ls’ , BASH performs execve() command to run the file. There are plenty of other things that needs to be achieved before the binary /usr/bin/ls is executed — the program needs to be read from the disk, its binary format has to be found and the proper handling code needs to be called upon through which the binary will be read into memory.</li><li><strong><em>And eventually executing the command :</em></strong> Last but not least, the program is in memory and is about to be run when it gets a chance. Nevertheless, how are directories and files read from disk by ‘ls’ ? In order to do this, a list of functions are executed internally to access the final output.The ls utility makes use of a function to read the directory contents, which in turn invokes a system call to read the list of files in the directory by consulting the underlying filesystem’s inode entries. ls is formatted based on which file system the file has been specified to. As soon as all the entries have been retrieved, the system call returns . Finally, the shell prints the prompt again. Then the prompt is stored as an environment variable called <strong>PS1. </strong>Then the list of files is returned to the prompt .</li></ol><p>I hope you enjoyed reading this blog, and remember:</p><blockquote>Logic will take you from a to z. imagination will take you anywhere</blockquote><blockquote>— Albert Einstein</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*sl0yUBybwef7Otim1US5rg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f71fad8c2d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How integers are stored in memory using two’s complement]]></title>
            <link>https://3344.medium.com/how-integers-are-stored-in-memory-using-twos-complement-80ed2edae152?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/80ed2edae152</guid>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Fri, 13 Aug 2021 08:58:10 GMT</pubDate>
            <atom:updated>2021-08-13T08:58:10.987Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="src: https://www.log2base2.com/storage/how-integers-are-stored-in-memory.html" src="https://cdn-images-1.medium.com/max/842/1*qUiapWxLvVtxMzN0fO-pyg.png" /></figure><p>Computer machines are composed by digital memories that store information in <strong>bits </strong>(<strong>bi</strong>nary digi<strong>t</strong>). It means that a bit is an unit — the smallest one — used to quantify computer data . The bit represents a logical value, which corresponds to a two-state device. These states are often represented as 0 or 1, and could be interpreted as “on/off”, “true/false”, etc.</p><p>On the other hand, a bit is a digit of the <strong>binary numeral system</strong>. Through this numeral system, and the combination of bits, any <strong>integer </strong>belonging to the <strong>decimal numeral system</strong> can be represented. As digital information are stored in bits, computers use binary numeral system to represent all numbers — integers, octals, hexadecimals. A <strong>byte </strong>is commonly known as a group of 8 bits.</p><p>In programming languages, like <strong>C language</strong>, it is possible to declare variables in order to store numeric data in the computer memory. The number of bits that represent integers <em>(int)</em> data type can change according to the computer architecture, or processing, and the compiler. In a 16-bit machine, the size of an integer is of 2 bytes, but in a 32-bit or 64-bit machine, the size is of 4 bytes. The values range of integers are shown in the following table :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/0*eEQX4bgWVvnM9QqD.png" /></figure><p>Supposing there is a C program — compiled in 64-bits — where will be declared an integer variable with a value of 25 as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*cC9obpN3vR5oFuwHZop9rw.png" /></figure><p>OUTPUT: The value of number is: 25</p><p>This integer is stored as a binary number by the computer memory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*xAAjYK4katmdLK6L.png" /></figure><p>This way it works with an unsigned and a short integer, although the last mentioned uses 16 bits. However, there are some differences when a negative value is assigned to an integer variables.</p><h4>Negative Integers</h4><p>A binary with a static size represents an integer within a value range determined. For <strong>unsigned binary numbers</strong>, this value range goes from 0 to the value obtained when all digits are equally to “1”. With 2 and 4 bytes, the maximum integer value obtained by a binary of 2 and 4 bytes are shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*erotgWZCprNq7vZ6.png" /></figure><p>It means that their value range are determined by the following mathematical notation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ImnTv13hXdBbnqWM.png" /></figure><p>This is the way computer memory interprets unsigned integers. But for signed integers, in which a dash (“-”) is written before number when it is negative, it changes. There are some methods to represent negative numbers from a binary.</p><p>One of those methods is the 2’s complement, but to understand the 2’s complement, I will first talk about the 1’s complement which is the basis to be able to understand everything correctly :) .</p><h4>One’s complement</h4><p>It is a method that represents a negative number through of inverting the values of bits of the number magnitude. Since the value first bit (also called <em>sign bit</em>) of the positive number is 0, when the inversion is done, this first bit is equal to 1 to indicate a negative number. The sign binary number obtained from the inversion is called <em>complement</em>.</p><p>The following image is an example of the process of inversion with one’s complement:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*WxyHVBWciFNim03I.png" /></figure><p>The value range of integers obtained from one’s complement is the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*cJITGHj61cGcpnsO.png" /></figure><p>In comparison with the value range obtained with a signed binary number and its MSB, this method allows one more possible value. However, through this method a negative zero is still obtained:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*jBA74_llaczHj9Av.png" /></figure><h4>Two’s complement</h4><p>It is a method to represent negative integers, similar to one’s complement. It also inverts the magnitude of the negative number but, then, it is added one (+ 1) to the complement number . It has a <em>sign bit</em> that allows to indicate if a number is positive or negative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*s93BYHQYMCXqcHly.png" /></figure><p>This method allows addition and subtraction with positive and negative numbers. Compared with one’s complement, the subtraction with two’s complement of two numbers , which has same magnitude value, is equal to zero.</p><p>The value range of integers obtained from two’s complement is the same as the obtained from one’s complement, shown in the Fig 9. With this method, it is not obtained a negative zero (-0), since it is added one to the zero-inverted number:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*XHy5sjT6QEkHlgMC.png" /></figure><p>For the reasons explained above, this method is used by computer memory to store signed integers.</p><p>Supposing there is a C program that tries to print negative numbers with an integer variable (called <em>inum</em>) and an unsinged integer variable (called <em>unum</em>), like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*IkPHcNFLcOUUmslF2ZeSeg.png" /></figure><p><strong>Output:</strong><br>The value of inum is: -25<br>The value of unum is: 4294967271</p><p>It is known that unsigned integer variables only store positive numbers, but when a negative number is casted to this data type, the result is a positive number, even higher than its magnitude value — in this case, 25.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*PSeDpgmDy02cVG2q.png" /></figure><p>In this case, the process made by the computer consisted in determining the <strong>signed binary number</strong> of the negative integer through <strong>two’s complement method</strong>. Then, when the number was casted to an unsigned integer, the binary number was assumed as an <strong>unsigned binary number</strong>. As shown in Fig 13, the signed number binary of -25 is the same than the unsigned binary number of 4294967271.</p><blockquote>To be successful, your desire to achieve it must be greater than your fear of failure — Bill Cosby</blockquote><p>I hope you have enjoyed reading this little blog and have understood enough to be able to explain to someone else about how an integer is stored in memory and how the two’s complement works. See you later :) .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*-w0gFJ-H4zcDJrE6.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80ed2edae152" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C - Static libraries]]></title>
            <link>https://3344.medium.com/c-static-libraries-a04d8dcbf435?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/a04d8dcbf435</guid>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Sat, 17 Jul 2021 02:19:29 GMT</pubDate>
            <atom:updated>2021-07-17T02:19:29.715Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/548/0*sof-5PrflC-sHDld.jpg" /></figure><h4><strong>What are libraries and why use libraries in c ?</strong></h4><p>A library is a file containing several object files, that can be used as a single entity in a linking phase of a program. Normally the library is indexed, so it is easy to find symbols (functions, variables and so on) in them. For this reason, linking a program whose object files are ordered in libraries is faster than linking a program whose object files are separate on the disk. Also, when using a library, we have fewer files to look for and open, which even further speeds up linking.</p><h4><strong>Types of libraries in C:</strong></h4><p>There are two types of libraries in C.</p><h4><strong>Static libraries</strong></h4><p>Static libraries are just collections of object files that are linked into the program during the linking phase of compilation, and are not relevant during runtime. This last comment seems obvious, as we already know that object files are also used only during the linking phase, and are not required during runtime — only the program’s executable file is needed in order to run the program.</p><h4><strong>Shared or dynamic libraries</strong></h4><p>Shared libraries are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries. However, the object files from the dynamic library are not inserted into the executable file. Instead, when the program is started, a program in the system (called a dynamic loader) checks out which shared libraries were linked with the program, loads them to memory, and attaches them to the copy of the program in memory.</p><h4><strong>How static libraries work</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/0*33W1B6Q-hZTDGKI3.png" /></figure><h4><strong>What is the difference between them</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/0*11Vf2gJLRpSbxLqe.png" /></figure><h4>Creating A Static “C” Library</h4><p>The basic tool used to create static libraries is a program called &#39;ar&#39;, for &#39;archiver&#39;. In order to create a static library, we can use a command like this:</p><p>ar rc libutil.a util_file.o</p><p>This command creates a static library named ‘libutil.a’ and puts copie of the object file “util_file.o” .If the library file already exists, it has the object file added to it, or replaced, if they are newer than those inside the library. The &#39;c&#39; flag tells ar to create the library if it doesn&#39;t already exist. The &#39;r&#39; flag tells it to replace older object file in the library, with the new object file.</p><p>After an archive is created, or modified, there is a need to index it. This index is later used by the compiler to speed up symbol-lookup inside the library, and to make sure that the order of the symbols in the library won’t matter during compilation.The command used to create or update the index is called &#39;ranlib&#39;, and is invoked as follows:</p><p>ranlib libutil.a</p><p><em>Note</em>: when an archive file’s index generation date (stored inside the archive file) is older than the file’s last modification date (stored in the file system), a compiler trying to use this library will complain its index is out of date, and abort. There are two ways to overcome the problem:</p><ol><li>Use &#39;ranlib&#39; to re-generate the index.</li><li>When copying the archive file to another location, use &#39;cp -p&#39;, instead of only &#39;cp&#39;. The &#39;-p&#39; flag tells &#39;cp&#39; to keep all attributes of the file, including its access permissions, owner (if &quot;cp&quot; is invoked by a superuser) and its last modification date. This will cause the compiler to think the index inside the file is still updated. This method is useful for makefiles that need to copy the library to another directory for some reason.</li></ol><h4><strong>How to use libraries in C</strong></h4><p>After we created our archive, we want to use it in a program. This is done by adding the library’s name to the list of object file names given to the linker, using a special flag, normally &#39;-l&#39;. Here is an example:</p><p>gcc main.o -L. -lutil -o prog</p><p>This will create a program using object file &quot;main.o&quot;, and any symbols it requires from the &quot;util&quot; static library. Note that we omitted the &quot;lib&quot; prefix and the &quot;.a&quot; suffix when mentioning the library on the link command. The linker attaches these parts back to the name of the library to create a name of a file to look for. Note also the usage of the &#39;-L&#39; flag - this flag tells the linker that libraries might be found in the given directory (&#39;.&#39;, refering to the current directory), in addition to the standard locations where the compiler looks for system libraries.</p><blockquote>“Programming is a race between developers, trying to build bigger and better idiot-proof programs, and the universe, trying to produce bigger and better idiots. For now the Universe is winning”<br>- Rich Cook</blockquote><p>I hope this article has helped you understand about C libraries and their great importance in programming in C and C++. Grettings!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*sl0yUBybwef7Otim1US5rg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a04d8dcbf435" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compilation in “C” language with gcc]]></title>
            <link>https://3344.medium.com/compilation-in-c-language-with-gcc-69e02218319e?source=rss-fef46b04fe38------2</link>
            <guid isPermaLink="false">https://medium.com/p/69e02218319e</guid>
            <dc:creator><![CDATA[Smith Flores]]></dc:creator>
            <pubDate>Mon, 21 Jun 2021 13:38:24 GMT</pubDate>
            <atom:updated>2021-06-21T13:38:24.750Z</atom:updated>
            <content:encoded><![CDATA[<p>The GNU Compiler Collection is a set of compilers created by the GNU project. GCC originally stood for GNU C Compiler (GNU C Compiler), because it only compiled the C language … Later it was extended to compile C ++, Fortran, Ada and others.</p><p>Compilation refers to the process of converting a program from the textual source code of a programming language such as C or C ++, into machine code, the sequence of ones and zeros used to control the central processing unit (CPU) of the computer. This machine code is stored in a file known as an executable file, sometimes also called a binary file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*5hB11SWMTXE0lwXC50ZF3w.jpeg" /></figure><p>After we finish writing the code the first thing we do is compile it, it normally takes a few seconds for the compiler to compile the code and translate it to the machine language. But during this time, the Code goes through a series of steps to convert to an executable file. These compilation phases are in sequence, so they’re often called a pipeline.</p><p>The Components of the <strong>C Program Compilation Pipeline</strong> are:</p><ol><li><strong>Preprocessor</strong></li><li><strong>Compilation</strong></li><li><strong>Assembly</strong></li><li><strong>Linker</strong></li></ol><ul><li>PREPROCESSING:</li></ul><p>When writing a C program, we include libraries, define some macros, and sometimes even make some conditional compilation. All of these are referred to as preprocessor directives.</p><p>During the preprocessing step in the C program compilation pipeline, the preprocess directives are substituted with their original values.</p><p>Let’s make that clear!</p><h4>Header Files</h4><p>The source file consists of a number of header files in the C language, and it is the preprocessor’s task to include the library.</p><p>Example:</p><p>If the program contains <strong>#include</strong>, this line will be replaced by the original contents of the header file when the source file is pre-processed.</p><h4>Macros</h4><p>Macros are defined by <strong>#define</strong> syntax in the C programming language. During the preprocessing stage, the macros are replaced by their values.</p><h4>Conditional Compilation</h4><p>Often we want our compiled code to be minimal, so we can use conditional compilation. The preprocessor often operates on a conditional compilation and reduces the code by adding only those lines that fulfill the condition.</p><p>Some Conditional Compilation preprocessor directives are:</p><ul><li><strong>#undef</strong></li><li><strong>#ifdef</strong></li><li><strong>#ifndef</strong></li><li><strong>#if</strong></li><li><strong>#else</strong></li><li><strong>#elif</strong></li><li><strong>#endif</strong></li></ul><h3>Extract Preprocessed Code From GCC</h3><p>We can also take a look at the file from each part of the compilation pipeline. Let’s ask the C compiler driver to dump the translation unit without going any further.</p><p>To extract the translation unit from the source code, we can use the <strong>-E</strong> option in the GCC.</p><p>Example:</p><pre>C-Code</pre><pre>// Header File<br>#include <br><br>#define Max 10<br><br>int main()<br>{<br>    printf(&quot;Hello World&quot;); // Print Hello World<br>    printf(&quot;%d&quot;, Max);<br>    return 0;<br>}</pre><pre>Dump Translation Unit</pre><pre>$ gcc -E cprogram.c<br><br><br># 1 &quot;cprogram.c&quot;<br># 1 &quot;&quot;<br># 1 &quot;&quot;<br># 1 &quot;cprogram.c&quot;<br>.......<br>.......<br>.......<br>typedef __time64_t time_t;<br># 435 &quot;C:/msys64/mingw64/x86_64-w64-mingw32/include/corecrt.h&quot; 3<br><br>typedef struct localeinfo_struct {<br>  pthreadlocinfo locinfo;<br>  pthreadmbcinfo mbcinfo;<br>} _locale_tstruct,*_locale_t;<br><br>typedef struct tagLC_ID {<br>  unsigned short wLanguage;<br>  unsigned short wCountry;<br>  unsigned short wCodePage;<br>} LC_ID,*LPLC_ID;<br><br>.......<br>.......<br>.......<br># 1582 &quot;C:/msys64/mingw64/x86_64-w64-mingw32/include/stdio.h&quot; 2 3<br># 3 &quot;cprogram.c&quot; 2<br><br><br># 5 &quot;cprogram.c&quot;<br>int main()<br>{<br>    printf(&quot;Hello World&quot;);<br>    printf(&quot;%d&quot;, 10);<br>    return 0;<br>}</pre><p>This example illustrates how the preprocessor functions. The Preprocessor only performs basic functions, such as inclusion, by copying contents from a file or macro expansion by text substitution.</p><p>The preprocessed file has an extension of <strong>.i</strong>, and if you pass this file to the C compiler driver, the preprocessor stage will be bypassed. This happens because of the file with the .i extension is supposed to have already been preprocessed and is sent directly to the compilation stage.</p><p>COMPILATION:</p><p>As in the previous stage, we dumped the translation unit code using the <strong>-E</strong> option. Here, we can use the <strong>-S</strong> option for the GCC to obtain the assembly code. This will create a file with the <strong>.s</strong> extension, and we will see the contents of the file using the <strong>cat command</strong>.</p><pre>Extract Assembly Code from GCC</pre><pre>$ gcc -S cprogram.c<br><br>$ cat cprogram.s<br><br>	.file	&quot;cprogram.c&quot;<br>	.text<br>	.def	printf;	.scl	3;	.type	32;	.endef<br>	.seh_proc	printf<br>printf:<br>	pushq	%rbp<br>	.seh_pushreg	%rbp<br>	pushq	%rbx<br>	.seh_pushreg	%rbx<br>	subq	$56, %rsp<br>	.seh_stackalloc	56<br>	leaq	128(%rsp), %rbp<br>	.seh_setframe	%rbp, 128<br>	.seh_endprologue<br>	movq	%rcx, -48(%rbp)<br>	movq	%rdx, -40(%rbp)<br>	movq	%r8, -32(%rbp)<br>	movq	%r9, -24(%rbp)<br>	leaq	-40(%rbp), %rax<br>	movq	%rax, -96(%rbp)<br>	movq	-96(%rbp), %rbx<br>	movl	$1, %ecx<br>	movq	__imp___acrt_iob_func(%rip), %rax<br>	call	*%rax<br>	movq	%rbx, %r8<br>	movq	-48(%rbp), %rdx<br>	movq	%rax, %rcx<br>	call	__mingw_vfprintf<br>	movl	%eax, -84(%rbp)<br>	movl	-84(%rbp), %eax<br>	addq	$56, %rsp<br>	popq	%rbx<br>	popq	%rbp<br>	ret<br>	.seh_endproc<br>	.def	__main;	.scl	2;	.type	32;	.endef<br>	.section .rdata,&quot;dr&quot;<br>.LC0:<br>	.ascii &quot;Hello World\0&quot;<br>.LC1:<br>	.ascii &quot;%d\0&quot;<br>	.text<br>	.globl	main<br>	.def	main;	.scl	2;	.type	32;	.endef<br>	.seh_proc	main<br>main:<br>	pushq	%rbp<br>	.seh_pushreg	%rbp<br>	movq	%rsp, %rbp<br>	.seh_setframe	%rbp, 0<br>	subq	$32, %rsp<br>	.seh_stackalloc	32<br>	.seh_endprologue<br>	call	__main<br>	leaq	.LC0(%rip), %rcx<br>	call	printf<br>	movl	$10, %edx<br>	leaq	.LC1(%rip), %rcx<br>	call	printf<br>	movl	$0, %eax<br>	addq	$32, %rsp<br>	popq	%rbp<br>	ret<br>	.seh_endproc<br>	.ident	&quot;GCC: (Rev3, Built by MSYS2 project) 10.2.0&quot;<br>	.def	__mingw_vfprintf;	.scl	2;	.type	32;	.endef</pre><p>The Compilation phase gives us the Assembly code that is unique to the target architecture.</p><p>Even if the C language compiler is the same for two different machines with the same C program but different processors and hardware, different assembly codes would be produced.</p><p>Generating the assembly code from the C code is one of the most critical stages in the C Program Compilation Pipeline since the assembly code is a low-level language that can be translated to an object file using an assembler.</p><p>ASSEMBLY:</p><p>The Compilation stage gives us the assembly code that is the input for the next pipeline component, i.e. assembly.</p><p>In this stage, the actual instructions on the machine level are generated from the assembly code. Each architecture has its own assembler, which converts its own assembly code into its own machine code.</p><p>The assembler generates a relocatable object file from the assembly code.</p><ul><li>Create object from the assbembly file:</li></ul><p>We can use the built-in assembly tool called to translate the assembly file to an object file.</p><p>The assembler tool takes the assembly file and produces a relocatable object file.</p><pre>create object file from assembly file</pre><pre>$ as cprogram.s -o cprogram.o</pre><p>This assembler tool(as) gives us a new file with a <strong>.o extension</strong> (<strong><em>.obj</em></strong> in Microsoft Windows), which is the relocatable object file.</p><p>If you want to translate a C program directly to an object file, you can use the <strong>-c</strong> option in the GCC compiler driver.</p><p>Using <strong>-c</strong> with the GCC compiler would merge the first three processes in the pipeline compilation, i.e. pre-processing, compilation and assembling.</p><pre>create object file</pre><pre>$ gcc -c cprogram.c</pre><p>This is really helpful when you want to work with object files and repeating all of the above steps can be quite hectic for a number of files.</p><p>The contents inside the object file contain low-level code and are thus not readable to humans. In the latter portion, we will also learn about a tool that will allow us to see the contents of an object file.</p><p>Now that we know how to build object files directly from both the assembly file and the C program. It’s time to learn about the Linking Stage in the <strong>C program compilation process</strong>.</p><p>LINKING:</p><p>This is one of the most critical steps in the C compilation pipeline where the generated relocatable object files are combined/linked to create another object file that is executable in nature.</p><p>Let’s take a look at the situation.</p><p>Suppose we have a custom header file <strong>htd.h</strong>, which contains a <strong>printHTD</strong> function prototype, and a source file <strong>htd.c</strong>, which contains the function definition of the header file.</p><pre>htd.c</pre><pre>#include <br>#include &quot;htd.h&quot;</pre><pre>void printHTD()<br>{<br>    printf(&quot;Hack The Developer&quot;);<br>}</pre><pre>htd.h</pre><pre>void printHTD();</pre><p>The <strong>htd.h</strong> header file is included in the <strong>cprogram.c</strong> source file.</p><pre>cprogram.c</pre><pre>#include &quot;htd.h&quot;<br>int main()<br>{<br>    printHTD();<br>    return 0;<br>}</pre><p>As we know there are two source files, and we’ll have to generate separate object files, which will be linked by the linker later to provide us an executable object file.</p><pre>$ gcc -c cprogram.c</pre><pre>$ gcc -c htd.c</pre><p>The above command creates two separate relocatable object files. Now let’s link the object files.</p><p>We can use the <strong>ld</strong> tool, which is the default linker in Unix-like systems, to link the relocatable object files.</p><p>But the <strong>ld</strong> tool gives us an undefined reference error.</p><pre>$ ld htd.o cprogram.o -o cprogram.exe</pre><pre>C:\msys64\mingw64\bin\ld.exe: cprogram.o:cprogram.c:(.text+0x32): undefined reference to `__imp___acrt_iob_func&#39;<br>C:\msys64\mingw64\bin\ld.exe: cprogram.o:cprogram.c:(.text+0x43): undefined reference to `__mingw_vfprintf&#39;<br>C:\msys64\mingw64\bin\ld.exe: cprogram.o:cprogram.c:(.text+0x78): undefined reference to `__main&#39;</pre><p>So we are going to use the <strong>gcc</strong> for the linking process, which has an inbuilt linker that will link the relocatable object files.</p><pre>$ gcc htd.o cprogram.o -o cprogram.exe</pre><pre>$ ./cprogram.exe</pre><pre>Hack The Developer</pre><p>The linking was successful as we got the required output.</p><p>Summary in one image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*AtoBeW1vGRkYhqHtzb0LdA.png" /><figcaption>source — <a href="https://nerdyelectronics.com/">https://nerdyelectronics.com/</a></figcaption></figure><h3>Tip:</h3><p>Don’t worry if you don’t understand much about programming, we were all newbies once, don’t get frustrated, keep going, be patient and persevere in your dreams!</p><p>Hope You Like It!))</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*-5KFyQN3DIbbe1CLd248jg.jpeg" /><figcaption>Picture from anime One Piece</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69e02218319e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>