<?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 Prince Garg on Medium]]></title>
        <description><![CDATA[Stories by Prince Garg on Medium]]></description>
        <link>https://medium.com/@gargprince?source=rss-20558959b8b8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u6iYh85Vd9erDC5lSWG_UA.jpeg</url>
            <title>Stories by Prince Garg on Medium</title>
            <link>https://medium.com/@gargprince?source=rss-20558959b8b8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 07:28:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gargprince/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[Adding Gotchas of JavaScript in your Vocabulary]]></title>
            <link>https://medium.com/@gargprince/adding-gotchas-of-javascript-in-your-vocabulary-f32b9beb4e0f?source=rss-20558959b8b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f32b9beb4e0f</guid>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Prince Garg]]></dc:creator>
            <pubDate>Mon, 22 Apr 2019 09:14:41 GMT</pubDate>
            <atom:updated>2019-04-22T10:04:09.949Z</atom:updated>
            <content:encoded><![CDATA[<h3>Adding Gotchas of JavaScript into your Vocabulary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GTTZA_R5xPdFZlk_q9lKGQ.jpeg" /><figcaption>image by <a href="https://www.freepik.com/nikitabuida">nikitabuida</a></figcaption></figure><p>If you have some experience with javascript, you probably faced some situations where you wrote some logic, it is straight and simple but somehow it’s not working as it possibly would have worked according to you.</p><p>Today, I would like to discuss such situations where I faced such issues and knock them down by looking at the details.</p><p>So, Let’s Get Started…</p><h3>1. Passing Objects</h3><p>I personally follow a rule- <em>We only save the reference to an object in a variable</em>. Yes, we don’t save any object inside a variable ( declared or parameterized ). What I meant by <em>reference </em>here is- when we call the variable, it will point to the original object to perform the operation. And when we try to pass the object to another variable or to another function( as a parameter ), we are actually passing a reference to the original object. And this can lead to mutation.</p><p>Example- declaring a variable-</p><pre>var obj = { &quot;name&quot;: &quot;Prince Garg&quot;, &quot;age&quot;: 23 };<br>var objCopy= obj;<br>objCopy.age= 24;</pre><pre>console.log(obj); // { &quot;name&quot;: &quot;Prince Garg&quot;, &quot;age&quot;: 24 } -<em>OOPS</em></pre><p>And, variable as a parameter-</p><pre>function someFunction( paramObj ) {<br>   paramObj.age= 24<br>}<br>var obj = { &quot;name&quot;: &quot;Prince Garg&quot;, &quot;age&quot;: 23 };</pre><pre>someFunction(obj);<br>console.log(obj); // { &quot;name&quot;: &quot;Prince Garg&quot;, &quot;age&quot;: 24 } -<em>OOPS</em></pre><p>Mutation can lead to disasters. So, avoiding these situations is a good idea. When you want to pass an object from one variable to another variable or to a function, use <em>Object.assign({}, obj)</em>. It will help you avoiding mutation and you never have to worry about unexpected modifications to the object.</p><p>Consider the modified examples-</p><p>Declared variable-</p><pre>var obj = { &quot;name&quot;: &quot;Prince Garg&quot;, &quot;age&quot;: 23 };<br>var objCopy= Object.assign({}, obj);<br>objCopy.age= 24;</pre><pre>console.log(obj); // { &quot;name&quot;: &quot;Prince Garg&quot;, &quot;age&quot;: 23 } -Yeyee</pre><p>And, variable as a parameter-</p><pre>function someFunction( paramObj ) {<br>   paramObj.age= 24<br>}<br>var obj = { &quot;name&quot;: &quot;Prince Garg&quot;, &quot;age&quot;: 23 };</pre><pre>someFunction( Object.assign({}, obj) );<br>console.log(obj); // { &quot;name&quot;: &quot;Prince Garg&quot;, &quot;age&quot;: 23 } -Awesome</pre><p><strong>But What if we get the object from .find() or array[index] ?</strong></p><p>Assume we have an array of objects and we want to save one of its object inside a variable. We can use <em>.find() </em>or<em> array[index] </em>directly<em> </em>to get the object and store it inside a variable. But guess what, it’s again the reference to the object that will be stored in that variable. And if you modify anything with that variable which contains the object, it will mutate the original object. Again, use <em>Object.assign()</em> and just get rid of unexpected mutation.</p><h3>2. Using Logical Operators</h3><p>Ok I know you will shout at me and say, how the hell in the world of javascript logical operators can give you a hard time?</p><p>Consider,</p><pre>var string1= &quot;somevalue1&quot;;<br>var string2= &quot;somevalue2&quot;;<br>var booleanTrue= true;<br>var booleanFalse= false;</pre><pre>var checkString= string1 &amp;&amp; string2; // &quot;somevalue2&quot;<br>var checkBoolean= booleanTrue || booleanFalse; // true</pre><pre>if(checkString === checkBoolean) console.log(&quot;Yeyee...&quot;);<br>else console.log(&quot;OOPS!&quot;);<br>// OOPS , (<em>WHY</em>?)</pre><p>Here some interesting thing is happening. I need your attention here, in javascript “<em>&amp;&amp;” </em>operator returns last value (“somevalue2”) if all values are truthy otherwise false. And “||” operator returns first truthy value (true). On the other hand, “||” operator will return the last falsy value if no value is true.</p><blockquote>Falsy values are numeric zero(0), NaN, false, undefined and empty string(“”). Truthy values are all the values that are not falsy.</blockquote><p>Thus, checkString will not contain a boolean value, instead, it contains a truthy value(“somevalue2”) in the checkString variable. And for checkBoolean? Yep, you guessed it, it will have value “true”. Why? Because the rule of “||” operator applies here. So when we check for their equality with “===” operator we are checking a string(“somevalue2”) and a boolean (true). They are not of the same type and value we got an “OOPS!” here.</p><p>To get expected result( i.e. “Yeyee…” ), we can use <em>Boolean( &lt;expression&gt; ). </em>It converts truthy value to Boolean <em>true</em> and falsy value to Boolean <em>false</em>. Or we can also use not( ! ) operator twice to get a boolean value. I prefer using <em>Boolean()</em> function, it makes our code more readable.</p><p>Consider,</p><pre>var string1= &quot;somevalue1&quot;;<br>var string2= &quot;somevalue2&quot;;<br>var booleanTrue= true;<br>var booleanFalse= false;</pre><pre>var checkString= Boolean( string1 &amp;&amp; string2 ); // true<br>var checkBoolean= booleanTrue || booleanFalse; // true</pre><pre>if(checkString === checkBoolean) console.log(&quot;Yeyee...&quot;);<br>else console.log(&quot;OOPS!&quot;);<br>// Yeyee... (We got it!)</pre><h3>3. “==” vs “===” operators</h3><p>“===” uses strict equality comparison algorithm. In simple words, no coercion is allowed. It only returns <em>true</em> if values &amp; types are equal and <em>false</em> otherwise. On the other hand, “==” is a special operator but it can also create problems if not understood properly. It uses coercion while converting values if types are not the same and compare values. Coercion is a vast topic, so we will only keep our focus on coercion related to “==” operator.</p><p>We only need to understand some rules to take advantage of the coercive nature of “==” and here is a great article to understand it.</p><p><a href="https://medium.freecodecamp.org/js-type-coercion-explained-27ba3d9a2839">JavaScript type coercion explained</a></p><p>P.S. thanks Alexey.</p><p>Above the table is simple, When comparing same types then the same algorithm that is used for “===” is used. When comparing numbers to a string, the string will be converted to the number and then compared.</p><p>When we compare the string to an object, something special happens. Each object( <em>array, function, object</em> ) have its own ToPrimitive() function. ToPrimitive() converts object to a primitive value( string, boolean, number ). It provides a simple value, after converting a complex data structure for comparison purpose. When we compare an object to any primitive value, the object will call its ToPrimitive() and then the comparison is performed.</p><p>If you ask me when to use “===” and “==”. My answer will be-</p><ol><li>Ask yourself first, if you are pretty sure that types of comparing values would be same then always use “===” otherwise you can use “==”.</li><li>When comparing Object to Object, first convert them to string either by using JSON.stringify() or concatenating with an empty string(“”) will work just fine then compare. Below is the reason behind it-</li></ol><blockquote>Primitives like strings, booleans and numbers are compared by their value, while objects like arrays, dates, and plain objects are compared by their reference. That comparison by reference basically checks to see if the objects given refer to the same location in memory.</blockquote><p>Conclusion:</p><p>Just remember a few things while working with Javascript, if you want to avoid mutation use Object.assign(). Use Boolean() to get result of &amp;&amp; and || in the boolean true or false. Understand coercion when using “==” or you will always be great with “===”.</p><p>Always remember,<br>You are awesome</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f32b9beb4e0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplifying Concepts Of Stellar Network]]></title>
            <link>https://medium.com/@gargprince/simplifying-concepts-of-stellar-network-6cb98c188a18?source=rss-20558959b8b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cb98c188a18</guid>
            <category><![CDATA[ledger]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[lumen]]></category>
            <category><![CDATA[network]]></category>
            <category><![CDATA[stellar]]></category>
            <dc:creator><![CDATA[Prince Garg]]></dc:creator>
            <pubDate>Tue, 01 Jan 2019 11:48:39 GMT</pubDate>
            <atom:updated>2019-01-01T11:48:39.455Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*CFWbvX_ZxwtwC0_LQjtSxQ.png" /></figure><p>Knowing about basics always helps in the better understanding of the more complicated processes. It also enriches communication and let the other person know that you know your business well. With this blog, I want to share some basic concepts that will help anybody who wants to understand them in simple language. I will try to keep it as simple as possible, <em>Pinky Promise…</em></p><p><strong>Let’s start with the golden question- What is Stellar?</strong><br>Stellar is a network of decentralized servers spread all over the world that power a distributed ledger. Each server is running on Stellar-Core software. In simple words, multiple computers connected all over the world installed with software called Stellar-Core which helps in the server to server communication, validation and data synching.</p><p>The native cryptocurrency of the stellar network is Lumen(XLM). The smallest unit of the lumen is stroop. 1 XLM is equal to10,000,000 stroops.</p><p><strong>Consensus</strong><br>The process in which these servers communicate with each other and ledgers are created, validated and synced is referred to as <em>consensus</em> and it happens every 2–5 seconds.</p><p><strong>Stellar-Core<br></strong>Stellar-Core is the heart of the network. Stellar-Core validates the transactions and applies changes in the ledger. Stellar-Core is written in C++ language.</p><h4>Ledger and its compositions</h4><p><strong>Ledger</strong><br>When we know that we have new data to process, we know that there is a new ledger coming in. Ledgers are created and validated by stellar consensus protocol. A ledger is composed of a set of transactions that happens during the creation of the ledger and previous ledger’s hash. Previous ledger’s hash is used to verify that the transition is the one, it supposed to be. Ledger records every transaction in the system that is synced with every stellar server presents in every part of the world. The ledgers are saved and retrieved from a SQL database.</p><h4>Below are the components by which a ledger is made up of:</h4><p><strong>Transactions</strong><br>Transactions contain a set of operations and a set of signatures that authorize that transaction. Fee for each transaction is 100 stroops. Transactions either succeeds or fails atomically (no modification will be done unless the complete procedure is done), this avoids conflicts in the network.</p><p><strong>Operations</strong><br>Operations are of different types like the creation of an account, funding of an account, making payment from one account to another, changing the options of account etc. A single operation would produce multiple effects.</p><p><strong>Effects</strong><br>Effects represent a single discrete change to one account. The effect is the finest grain to the change in the network. Examples, a credited effect in payer account and a debited effect in payee account.</p><p><strong>Horizon<br></strong>Horizon is the interface between Stellar-Core and client application. It interacts with the Stellar-Core via RPC calls and serves the data through the APIs. Horizon is written in Go programming language. The restful API gives the output in a JSON object. Like normal API service, it checks if the requirements are met. If you are sane enough to pass all the required parameters, you will have your data. Otherwise, it will shout at you with some error.</p><p>For better understanding the process between client, horizon, and Stellar-Core, I am presenting it in the form of a conversation:</p><p><em>Client: </em>Hey horizon, how are you? Can you send the status for GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW account, please?</p><p><em>Horizon: </em>Hi there, I am great. Sure, I will do the needful.</p><p><em>Horizon: </em>Hey Stellar-Core, hope you are doing great. Can you please give me the status for this account real quick.</p><p><em>Stellar-Core: </em>Yeah, looking for it. Okay, I found it and here you go.</p><p><em>Horizon: </em>Oh thanks Stellar-Core.</p><p><em>Horizon: </em>Sorry for the delay client. This is what I found.</p><p><em>Client: </em>Thanks horizon. You are always helpful.</p><p>I know some of the stuff can still confuse you. If you have doubts, feel free to ask through comments or twitter profile. If you like this story, please appreciate it with claps or comments.</p><p>And always remember,<br>You Are Awesome</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cb98c188a18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using EJS with Node JS]]></title>
            <link>https://medium.com/@gargprince/using-ejs-with-node-js-61a134352e1e?source=rss-20558959b8b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/61a134352e1e</guid>
            <category><![CDATA[ejs]]></category>
            <category><![CDATA[express-ejs]]></category>
            <category><![CDATA[learn]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[frontend-using-nodejs]]></category>
            <dc:creator><![CDATA[Prince Garg]]></dc:creator>
            <pubDate>Wed, 06 Dec 2017 07:42:04 GMT</pubDate>
            <atom:updated>2017-12-06T07:42:04.078Z</atom:updated>
            <content:encoded><![CDATA[<p>As a developer we face challenges everyday. I am a backend developer and recently my boss wanted me to build a web app and told me to get my hands on front-end too. I was like “You are kidding right” ? I know learning new technologies is fun and one has to push himself to move forward. But I was not expecting this coming.</p><p>Anyways, There are various front-end technologies out their ( Angular JS and react JS to name a few ). But it requires both time and effort to have a command on them. You can also use AJAX to call your APIs and manipulate DOM everytime (Don’t do it, it’s obnoxious). But I suggest a better way it’s called “EJS”. EJS helps to generate HTML with the help of javascript. If you have used PHP before you can easily grab it because of the similarity in embedding tags in HTML. If you didn’t- <em>hey, I am writing for you brother.</em></p><p>Before we start I would like to include that, this blog is totally based upon my experience. <em>Yeah I’m honest</em>…</p><p>So, Lets Get Started…</p><p>First thing first, we need package.json file with below code-</p><pre>{<br>    &quot;name&quot;: &quot;express-ejs&quot;,<br>    &quot;main&quot;: &quot;server.js&quot;,<br>    &quot;dependencies&quot;: {<br>        &quot;ejs&quot;: &quot;^2.5.7&quot;,<br>        &quot;express&quot;: &quot;^4.16.2&quot;<br>    }<br>}</pre><p>Now open terminal(OSX and ubuntu) or cmd(windows), go to the directory where our project contains package.json file and run-</p><pre>npm install</pre><p>Second, our folder structure-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/1*87abcx6sZwY3EJg_1hWn3A.png" /></figure><p>Third, we need to configure server.js file (you can use any name for your file).</p><pre>1 var express = require(&#39;express&#39;);<br>2 var app     = express();<br>3 var ejs     = require(&#39;ejs&#39;);</pre><pre>4 app.set(&#39;view engine&#39;, &#39;ejs&#39;);</pre><pre>5 app.set(&#39;views&#39;,__dirname+&#39;/frontend&#39;);</pre><pre>6 app.use(&#39;/css&#39;, express.static(__dirname+&#39;/frontend/css&#39;));</pre><pre>7 app.listen(8080); // 8080 is a port on which node server runs</pre><p>Above lines are required in the server.js file to use EJS.<br>Line-4 tells which view engine to use. Here, It will use EJS rules while<em> </em>creating HTML.</p><p>At Line-5 we are just telling express “<em>Hey express, look all of my template files(.ejs) at this path</em>”. Here, in the second parameter, “__dirname” is a global variable which tells current location of our server.js file.</p><p>At Line-6 we are creating the route for our static files. We are telling “EJS” when you find any path that starts with “/css” (<em>first parameter)</em>, find the following file in the “<em>/frontend/css” </em>folder (<em>second parameter</em>). I know it may confuse you, but it will make more sense later I promise.</p><p>Last, our route to use EJS template -</p><pre>app.get(&#39;/index&#39;, function(req, res) {<br>    res.render(&quot;index&quot;, { name: prince, hobbies: [&#39;making coffee&#39;, &#39;talking&#39;] });<br>});</pre><p>Here, we are using <em>res.render()</em> to render HTML template that contains two parameters-<br>1. Filename (index.ejs) that we want to render.<br>2. Object, having key-values that we want to use locally in our template environment.</p><p>EJS first makes HTML on the server and then sends it to the client as a view.</p><p><em>Pheu…</em></p><h3>Sharpening your weapon with some basics…</h3><p>I want you to remember only two simple tags that are very important while working with EJS. Consider,</p><pre>1. &lt;%   %&gt;<br>2. &lt;%=  %&gt;</pre><p>We use first tag pattern to write javascript code. All conditions, loops, initializations, expressions etc. goes straight here. Remember, JS and HTML codes are different and EJS helps to make HTML with the combination of both of them.</p><p>We use second tag pattern to print something inside HTML dynamically. It could be a variable we passed as our “<em>render()” </em>object parameter or a variable we created with “<em>&lt;% %&gt;”</em> tag.</p><p>Now let’s play with our index.ejs</p><ol><li>“<em>if</em>” condition</li></ol><pre>&lt;html&gt;<br>    &lt;body&gt;<br>        &lt;%<br>            if(name === &quot;prince&quot;) {<br>                var message= &quot;Its Good to see you...&quot;;<br>        %&gt;<br>                &lt;%= message %&gt;<br>        &lt;%<br>            }<br>        %&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*DZKrTKK5SAL48BkJXVcg8A.png" /></figure><p>Pay close attention to how we’re using both the tags inside our HTML to check if the condition is true, initialize variable and assign value inside “<em>&lt;% %&gt;”</em> tag. Then, print “message” using “<em>&lt;%= %&gt;”</em> tag and close “if” condition using “<em>&lt;% %&gt;”</em> tag at the end. Again, all your logics inside “<em>&lt;% %&gt;”</em> tag and printing by “<em>&lt;%= %&gt;”</em> tag.<br>Peace of cake…</p><p>2. Loops</p><pre>&lt;html&gt;<br>    &lt;body&gt;<br>        &lt;%<br>            if(name === &quot;prince&quot;) {<br>                hobbies.forEach( function(hobby) {<br>        %&gt;<br>                    &lt;input type=&quot;checkbox&quot;<br>                        &lt;% if(hobby === &quot;talking&quot;) { %&gt; <br>                    checked<br>                        &lt;% } %&gt;<br>                    /&gt; &lt;%= hobby %&gt;<br>         &lt;%<br>                });<br>            }<br>         %&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*ym0-Ch07olqdLGVMwXQchA.png" /></figure><p>Now we are taking advantage of the awesomeness of EJS by dynamically creating form input checkbox of hobbies by a for loop and mark it checked if the condition is true. You can also use “while” loop as well to accomplish the same task. So, what do think? I know it gets a bit ugly sometimes but it sure makes easy to get what you need.</p><p>3. Using environment variables inside &lt;script&gt; tag</p><p>Here comes some craziness, there may be some cases where you have to put value inside your scripts. Happened to me when I wanted to give a date value from my DB to my jQuery plugin in a specific format.<br>Behold,</p><pre>&lt;script&gt;<br>   alert(&quot;&lt;%= name %&gt;&quot;);<br>&lt;/script&gt;</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ghfymcoiFcgwKKMQobj0aw.png" /></figure><p>Easy right? We just used our basics that’s all.</p><p>4. include-<em>ing</em></p><p>To include repeatable parts in our current template we use <em>include</em>.<br>Consider, our new index.ejs with a link to our “style.css” stylesheet-</p><pre>&lt;html&gt;<br>    &lt;body&gt;<br>        &lt;head&gt;<br>            &lt;meta charset=&quot;UTF-8&quot;&gt;<br>            &lt;title&gt;Awesome EJS&lt;/title&gt;<br>            &lt;link href=&quot;/css/style.css&quot; rel=&quot;stylesheet&quot; /&gt;<br>        &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;%<br>            if(name === &quot;prince&quot;) {<br>                var message= &quot;Its Good to see you...&quot;;<br>        %&gt;<br>                &lt;%= message %&gt;<br>        &lt;%<br>            }<br>        %&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>To demonstrate the working of<em> “include”</em>, we made a file- “header.ejs” and put our header information inside it. Separating code is a good practice, it will not only make our code look clean but also gives us the flexibility to maintain and reuse our code.</p><p>Our “header.ejs” file-</p><pre>&lt;meta charset=&quot;UTF-8&quot;&gt;<br>&lt;title&gt;Awesome EJS&lt;/title&gt;</pre><pre>&lt;link href=&quot;/css/style.css&quot; rel=&quot;stylesheet&quot; /&gt;</pre><p>And our new “index.ejs” using <em>include-</em></p><pre>&lt;html&gt;<br>    &lt;body&gt;<br>        &lt;head&gt;<br>             &lt;% include header %&gt;<br>        &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;%<br>            if(name === &quot;prince&quot;) {<br>                var message= &quot;Its Good to see you...&quot;;<br>        %&gt;<br>                &lt;%= message %&gt;<br>        &lt;%<br>            }<br>        %&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Looks Great!. Now when there will be multiple templates file including our “header.ejs” file and you require using another css file in every template, you don’t have to copy-paste link tag in your templates. You just have to make a <em>&lt;link&gt; </em>tag<em> </em>inside “header.ejs” file and it will be included in all of your templates automatically.</p><p>Hope I could help you with this blog. Claps are the appreciations. I always look forward to hearing from you.</p><p>And always remember,<br>You are Awesome</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61a134352e1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Best Practices For New Developers]]></title>
            <link>https://medium.com/@gargprince/simple-best-practices-for-new-developers-fdc35e6e575d?source=rss-20558959b8b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdc35e6e575d</guid>
            <category><![CDATA[better-code]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Prince Garg]]></dc:creator>
            <pubDate>Tue, 21 Nov 2017 18:44:01 GMT</pubDate>
            <atom:updated>2017-11-21T18:44:01.717Z</atom:updated>
            <content:encoded><![CDATA[<p>I know what it feels like when people doubt you about solving some problem but you solve them with your skills. Woohooo! But now I want you to ask yourself- “Is solving a problem(anyhow) can only make you a better developer or solving it in a way that your future self and other readers can understand it without no or minimum effort?”. Quite a question Huh.</p><p>Psst… “be with me, I can help you”.</p><p>But before we start, I would really like to include that these are the effective techniques that I personally use while coding and they remained constant even after switching few languages. Here, I have used simple Java-script code for the examples in this blog. But you will not find any difficulty in understanding them because of the language difference.</p><p>So, Let’s Get Started…</p><ol><li>Variable Names:</li></ol><p>We use variables to store values and I know values are very important to perform some task. But variable names are equally important for your future self and anyone else’s understanding of the code. Consider,</p><pre>var name= &quot;Deadpool&quot;, n= 2;</pre><p>Now think, “Is value in name variable for the movie or a superhero” And “What is n about”. And now all you got are questions. To find answers, you got no option but read the code to find out about it. Always name your variables that can express their value. Thus, prevents anyone from guessing why the variable is all about. Carefully naming your variables always paid off. <br><em>Not in money Smarty… Your Time…</em></p><p>And with some touch ups to our variables, Behold…</p><pre>var movie= &quot;Deadpool&quot;, part= 2;</pre><p>2. Functions:</p><p>We all use functions to separate some logic and reuse them in various parts of our program. Ideally, a function should perform only one task. I am not saying that it’s a bad idea to let function handle more than one task. Maybe in your case its what you want. But it can make your function hard to read and creates more dependency on that function. We should create a function to focus on a particular task. Thus, helps in generating fewer errors and give you a way to reuse them. Trust me, this will make your code look clean and easy to maintain.</p><blockquote>Best Practice for variable names can also be used for function names.</blockquote><p>3. <em>if</em> Condition:</p><p>Conditions are used to execute some code when something is true or false. We use logical operators to check whether the output either true or false. Here is a quick question- “Have you experienced an overflow while checking in the if condition?” To me, it happens almost everyday.</p><pre>if( var1 &amp;&amp; var2 || !var3 &amp;&amp; var4 || var5 &amp;&amp; var6 &amp;&amp; !var7 &amp;&amp; var8 &amp;&amp; var9 &amp;&amp; ... )<br>{ ... }</pre><p>Now you will be like- “oh.. man, you should get a hang of that by now”. But what if I tell you that, there is a better way to make it more clean and understandable. <em>I think I got your attention now…</em></p><pre>var is_able_to_pass= var1 &amp;&amp; var2 || !var3 &amp;&amp; var4 || var5 &amp;&amp; var6 &amp;&amp; !var7 &amp;&amp; var8 &amp;&amp; var9;</pre><pre>if(is_able_to_pass)<br>{ ... }</pre><p>Here, the output value (i.e. true or false) is stored in a meaningful named variable and then this variable is used to check for “if” condition. This is now more readable and clean. Even better, now you can reason about what this “if condition” is all about by looking at our newly created variable. A <em>win-win…</em></p><p>4. Enumeration</p><p>Using different types of roles, users, statuses, actions, etc. are common tasks in an application. It’s very easy to define and use them on the go. As your application grows, it becomes very hard to keep a track of each of them. You can consider a situation to give a list of “status” used in your project. Oh boy, now you have to search in every file in your project for the different types of statuses. Even worse you might not remember where you used them in your project after a few days. A simple way to avoid such situations from sucking your precious time is “Enumeration” ( enum in c ).<br>According to Wikipedia-</p><blockquote>An <strong>enumeration</strong> is a complete, ordered listing of all the items in a collection. The term is commonly used in mathematics and computer science to refer to a listing of all of the elements of a set.</blockquote><p>Some languages don’t have “enum” as a type. But no one is stopping you to create a key-value pair( Object in javascript ) or a list of such types and use it in your project. Much clean, increase readability, it will also decrease chances to write wrong spelling because you will get an exception.</p><p>5. Copy &amp; Paste Code</p><p>We all want immediate solutions that can just magically solve our problem/s. Some searching, some copy &amp; paste and if it works, <em>Hurray! Nailed it totally…<br></em>It is not a wrong idea to copy &amp; paste the solution. Nobody wants to reinvent the wheel right. But trying to read and understand the working solution and author’s approach to solve the problem is a good practice. Who knows, if that piece of code can tell you about a built-in feature in the language that you were not aware of till now, but now you know it. If you find something new, feel free to search it to gain more information about it such as, optional parameters.</p><p>Above are some simple practices that I personally use everyday and I hope they will benefit you too. I know, these are very basic but I will keep writing about principles, patterns and advance practices to keep your code clean.</p><p>Always remember,<br>You Are Awesome…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdc35e6e575d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>