<?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 Akash Shyam on Medium]]></title>
        <description><![CDATA[Stories by Akash Shyam on Medium]]></description>
        <link>https://medium.com/@akash.shyam2008?source=rss-8d6a52bf9b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rnq5h5Rjp3pd7DaDf3K7kg.jpeg</url>
            <title>Stories by Akash Shyam on Medium</title>
            <link>https://medium.com/@akash.shyam2008?source=rss-8d6a52bf9b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 06:59:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akash.shyam2008/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[15 Important JavaScript Array Methods You Should Know]]></title>
            <link>https://blog.devgenius.io/15-important-javascript-array-methods-you-should-know-5e74578191a3?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e74578191a3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Tue, 19 Apr 2022 16:21:18 GMT</pubDate>
            <atom:updated>2022-04-19T16:21:18.405Z</atom:updated>
            <content:encoded><![CDATA[<h4>Use these methods to improve your JavaScript game 😎</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*2YQlsptk36CpNKEV" /><figcaption>Photo by <a href="https://unsplash.com/@jstrippa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">James Harrison</a> on <a href="https://unsplash.com/s/photos/code?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>You will probably use arrays in every application you ever build. It has several methods, some of which are very confusing. I’ve made a list of 15 array methods you should master since they come in handy often.</p><p>An important thing about array methods is that some are mutable and some are immutable. It’s essential to keep this in mind when deciding which method to use for a particular problem.</p><p>Most of the array methods in this list take a similar callback as the argument. The first argument is the current item, the second argument is the index and the third is the entire array. Now we’ve got this out of the way, let’s get started with the list:</p><h3>1. ForEach</h3><p>Loops over each element in an array and executes a callback function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b21e86f23c4a5807a7c0687cfd26072a/href">https://medium.com/media/b21e86f23c4a5807a7c0687cfd26072a/href</a></iframe><h3>2. Map</h3><p>Loops over each element in an array and executes a callback function. Creates a new array with the return values of the callback function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e12bafca3b13832f57ffb4066a06355f/href">https://medium.com/media/e12bafca3b13832f57ffb4066a06355f/href</a></iframe><h3>3. Filter</h3><p>Loops over each element in an array and selects only those elements which are true to a condition. A new array is returned, based on the selected elements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b9ace70b96c7148a4c87d31661983ca/href">https://medium.com/media/4b9ace70b96c7148a4c87d31661983ca/href</a></iframe><h3>4. Find</h3><p>Finds the first element in the array that fulfils a condition. If none are found, undefined will be returned.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94b7df71c8b5800009cdc94d2c15bc05/href">https://medium.com/media/94b7df71c8b5800009cdc94d2c15bc05/href</a></iframe><h3>5. FindIndex</h3><p>Similar to the previous method, it returns the index of the first element that fulfils a given condition. If none are found, -1 is returned.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4781f0557fdfd203a50283f64a829331/href">https://medium.com/media/4781f0557fdfd203a50283f64a829331/href</a></iframe><h3>6. Reduce</h3><p>This is an advanced method, that can be used to combine the elements of an array. The main difference is that the callback takes an accumulator as the first argument. The return value of the callback becomes the accumulator in the next iteration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab811bb3c53f261c28cf0830206b3fe8/href">https://medium.com/media/ab811bb3c53f261c28cf0830206b3fe8/href</a></iframe><h3>7. Every</h3><p>This method takes a callback that returns a boolean value. Every() will return true if the condition is valid for ALL the elements in the array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd98df644a1df97cb5bcd677f27af9df/href">https://medium.com/media/bd98df644a1df97cb5bcd677f27af9df/href</a></iframe><h3>8. Some</h3><p>Like the previous method, this one also takes a callback that returns a boolean. Some() will return true if the condition is valid for AT LEAST one element.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dede5f1f91c2225ce62301da2ff5efe9/href">https://medium.com/media/dede5f1f91c2225ce62301da2ff5efe9/href</a></iframe><h3>9. Sort</h3><p>This is a method used to sort the elements in an array. It sorts the array in ascending order by default. It takes a callback function, with two elements — a and b. If a is less than b, then return -1, else return 1. If they are equal, return 0.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8dcbf037bc3611ef6757b54efe33ffa3/href">https://medium.com/media/8dcbf037bc3611ef6757b54efe33ffa3/href</a></iframe><blockquote>Keep in mind that unlike other array methods, sort mutates the array.</blockquote><h3>10. Flat</h3><p>Flat is used to flatten nested array into a single array. You can specify a depth up to which the array will be flattened.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf3ecf09c9654f3549f5fd65445205c4/href">https://medium.com/media/bf3ecf09c9654f3549f5fd65445205c4/href</a></iframe><h3>11. Reverse</h3><p>Reverses the order of elements in an array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45e1e65e773d6104a1de09c9edb800f0/href">https://medium.com/media/45e1e65e773d6104a1de09c9edb800f0/href</a></iframe><h3>12. Include</h3><p>This method returns true if an element is present in an array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3743e45eaa97c85c62f6fe32cb1d022e/href">https://medium.com/media/3743e45eaa97c85c62f6fe32cb1d022e/href</a></iframe><h3>13. Fill</h3><p>The fill method sets the elements of the array to a given value. I like to use this method when I want to use the map/forEach method a specific number of times.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/010849de8e92386c2efbc4407b44e7da/href">https://medium.com/media/010849de8e92386c2efbc4407b44e7da/href</a></iframe><h3>14. At</h3><p>This method returns the element of a given index. The difference between this and the traditional way of accessing(i.e. arr[1]) an element is that it supports negative indices too.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab5d324d7dd897dc59e03bb3c7aaa657/href">https://medium.com/media/ab5d324d7dd897dc59e03bb3c7aaa657/href</a></iframe><h3>15. Concat</h3><p>This method is used to combine two arrays.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18833589b09cf17e8a64e11570c65496/href">https://medium.com/media/18833589b09cf17e8a64e11570c65496/href</a></iframe><p>That’s the end of the post! If you liked it, leave a clap(or two) and follow me so as not to miss any more posts. Follow me on <a href="https://twitter.com/akashcodes">Twitter</a> for daily content on Web development, freelancing and web3. Bye for now!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e74578191a3" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/15-important-javascript-array-methods-you-should-know-5e74578191a3">15 Important JavaScript Array Methods You Should Know</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Become A Web3 Developer]]></title>
            <link>https://blog.devgenius.io/how-to-become-a-web3-developer-e1e76a23dcc7?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1e76a23dcc7</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Fri, 01 Apr 2022 08:17:58 GMT</pubDate>
            <atom:updated>2022-10-26T14:49:18.442Z</atom:updated>
            <content:encoded><![CDATA[<h4>A beginners guide to navigating the confusing world of web3</h4><p>Everyone is talking about web3, and there’s crazy money flowing into this space. An average blockchain developer makes $140k/year. Getting into this industry is the best thing you can do as a developer!</p><p>Since the web3 industry is relatively new, there are not a lot of resources, and a lot of them are not updated. I’ve compiled a list of the best resources and guides to create <strong>the ultimate roadmap to learn web3 and Solidity.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*6Ga5gcdDq2UQ7kDO" /><figcaption>Photo by <a href="https://unsplash.com/@anagani_saikiran?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Sai Kiran Anagani</a> on <a href="https://unsplash.com/s/photos/learning-coding?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>1. Blockchain Fundamentals</h3><p>The first you need to understand to become a web3 developer is the blockchain. This will help you easily architect and optimise smart contracts(we’ll talk about this more later). Let’s take a look at what the blockchain is, and how it works.</p><p>A blockchain is an immutable, public and decentralised database that is owned by the users. The data is stored in the form of blocks, hence the name “Blockchain”. To link the blocks together, each block contains its data, its hash, and the hash of the previous block.</p><blockquote>The hash is a unique string that is calculated from the data. The hash changes based on the information. You may have come across this when implementing JWT tokens in NodeJS.</blockquote><p>If someone tampers with one of the blocks, the hash changes and the next blocks become invalid since the chain is broken. The person would then have to recalculate all the blocks in the chain, which will take a very long time(10 minutes/block).</p><p>Copies of the blockchains are stored on computers all over the world, called nodes. So you’ll also need access to the majority of computers, and repeat this process. It’s pretty much impossible for a computer to do all this fast enough so the network doesn’t notice and doesn’t try to kick the fraudster off the blockchain.</p><p>Here’s a short Udemy course that delves deeper into the fundamentals of the blockchain:</p><p><a href="https://www.udemy.com/course/blockchain-and-bitcoin-fundamentals/">https://www.udemy.com/course/blockchain-and-bitcoin-fundamentals/</a></p><h3>2. Decentralised Applications</h3><p>DApps or Decentralised Applications are apps built on top of the blockchain. The main technologies used in DApps are:</p><ol><li>Frontend: JavaScript frameworks like React, Vue, Angular</li><li>Backend: Rust and Solana or Solidity and Ethereum</li></ol><p>Now, you might be thinking, what are examples where DApps are used? Here are a few industries DApps can revolutionize:</p><ol><li>Escrow — Whenever you buy/sell a house, You need to trust the buyer to pay up on time, or keep the money with a third-party company. What if the buyer doesn’t pay, or the third party runs away with the money? DApps can ensure the transfer of money securely</li><li>Records — Once something is added to the blockchain, it cannot be edited or removed. This is very handy when maintaining house records, medical records etc.</li><li>Payments — Cryptocurrencies can be used for easy and secure payments to transfer value. Although gas fees are pretty high right now, I’m sure they’ll decrease in the future.</li></ol><h3>3. Frontend Web Development Basics</h3><p>As I mentioned previously, DApps may have blockchain technology powering the backend, but the frontend is JavaScript. Here’s what you need to learn:</p><ol><li>HTML — Common HTML tags</li><li>CSS — Basic Properties, Flex, Grid</li><li>CSS Frameworks[Optional] — Bootstrap, Semantic UI, Tailwind etc</li><li>JavaScript — Variables, Functions, Classes, ES6 etc.</li><li>JavaScript Frameworks[Recommended] — React/Vue/Angular</li></ol><p>I also recommend learning web2 backend, as a fallback in case web3 doesn’t work out. Here’s what you should learn for the backend:</p><ol><li>NodeJS Fundamentals — Event loop, I/O</li><li>API Framework — Express</li><li>Databases — MongoDB, SQL, PostgreSQL</li></ol><p>Here’s an amazing course on web development by Colt Steele:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Ukj4up7AEj3s6FC9PAtrDw.jpeg" /></figure><p><a href="https://www.udemy.com/course/the-web-developer-bootcamp/">https://www.udemy.com/course/the-web-developer-bootcamp</a>/</p><h3>4. Ethereum Fundamentals</h3><p>Ethereum is a blockchain that processes smart contracts. Ethereum is by far the most popular blockchain for creating smart contracts in 2022. Solidity is the language used to develop smart contracts with it. The official documentation is a great place to start learning more about Ethereum:</p><p><a href="https://ethereum.org/en/developers/docs/">Ethereum development documentation</a></p><h3>5. Smart Contracts</h3><p>Smart contracts are immutable code on the blockchain that executes a contract. Smart contracts are similar to classes in JavaScript. These are used to power DApps.</p><p>Just understanding the concept of smart contracts isn’t enough, you should also be able to develop them. Here’s where Solidity comes in. Solidity is a high level, object(ish) oriented programming language which is made specifically to build smart contracts easily.</p><p>However, since Solidity is very new, there are very few resources to learn it. The best way to learn is by building projects and solving the problems you face by referring the documentation. Let’s look at some resources that follow a similar pattern.</p><h4>1. Buildspace</h4><p>Buildspace is a cohort-based learning platform, and it’s one of the best resources to learn Web3. You can build DApps, NFT collections, NFT browser games, DAOs and much much more with Solana, Polygon and Ethereum.</p><p>You also get a free NFT on completion of a project, which is super cool! You get access to their exclusive job boards where the biggest Web3 companies hire from.</p><p><a href="https://buildspace.so/">buildspace</a></p><h4>2. LearnWeb3DAO</h4><p>Learn Web3 DAO is another amazing resource to Web3. It has 4 different tracks — Freshman, Sophomore, Junior, Senior for developers with various skill levels. You learn to build DApps, NFT collections, ICO tokens, DAOs, DeFi protocols and much more.</p><p>Oh, and did I mention this is for the high cost of $0 / month? And that’s not it, you build projects along with 1000’s of other developers, participate in hackathons and make lifelong friends!</p><p><a href="https://www.learnweb3.io/">LearnWeb3 DAO</a></p><h4>3. CryptoZombies</h4><p>Do you like Games? You’re going to love this. CrytoZombies is a gamified programming course where you build a zombie factory using smart contracts. You should learn from one of the other resources, and practice your skills using CrytoZombies.</p><p><a href="https://cryptozombies.io/">#1 Solidity Tutorial &amp; Ethereum Blockchain Programming Course | CryptoZombies</a></p><h4>4. Nader Dabit</h4><p>Nader Dabit talks about:</p><ol><li>React</li><li>Web3</li><li>Serverless</li><li>Blockchain</li><li>DeFi</li></ol><p>You should subscribe to his youtube channel if you’re interested in web development or web3:</p><p><a href="https://www.youtube.com/c/naderdabit/featured">https://www.youtube.com/c/naderdabit/featured</a></p><h4>5. FreeCodeCamp</h4><p>FreeCodeCamp released a FREE 16-hour course on Solidity. You’ll learn all about Solidity, the blockchain and smart contracts.</p><p>This course will give you a full introduction to all of the core concepts in blockchain, smart contracts, solidity, NFTs/ERC721s, ERC20s, Coding Decentralized Finance (DeFi), python and solidity, Chainlink, Ethereum, upgradable smart contracts, and full stack blockchain development.</p><p><a href="https://www.freecodecamp.org/news/learn-solidity-blockchain-and-smart-contracts-in-a-free/">Learn Solidity, Blockchain, and Smart Contracts in a Free 16-Hour Course</a></p><h3>6. Connect Your Smart Contract With Your Frontend</h3><p>Now that you know how to develop smart contracts, you need to actually use them. There are two main libraries to do this — web3.js or ethers.js. Let’s see why ethers.js is better than web3:</p><ol><li>Much smaller size</li><li>Less buggy</li><li>Better documentation</li><li>More popular</li><li>Easier for begginers</li><li>Extra Features</li></ol><p>Here’s a great tutorial on ethers.js:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FcqdAQK7WOlE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcqdAQK7WOlE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcqdAQK7WOlE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6670bdbc7f137906f30e96153bd1bb7/href">https://medium.com/media/c6670bdbc7f137906f30e96153bd1bb7/href</a></iframe><p>I suggest learning web3.js too, since some codebases may use it. Here’s a crash course on web3.js:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Ft3wM5903ty0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dt3wM5903ty0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Ft3wM5903ty0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9074dcece55ac1ab93943c110bb62b5/href">https://medium.com/media/a9074dcece55ac1ab93943c110bb62b5/href</a></iframe><blockquote>Checkout this repo to know more — <a href="https://github.com/adrianmcli/web3-vs-ethers">https://github.com/adrianmcli/web3-vs-ethers</a></blockquote><h3>7. Alchemy</h3><p>Alchemy is a suite of developer tools to prototype, debug and ship products faster. Alchemy supports various chains like — Ethereum, Polygon, Starknet, Flow and more. It has an awesome NFT API that allows you to get your NFT collection up and running with ease. It also supports web3.0 push notifications, and it has a supercharged blockchain api too!</p><p><a href="https://www.alchemy.com/">Alchemy | Blockchain infrastructure for developers</a></p><h3>8. Remix</h3><p>Remix is a browser IDE specifically made to build Ethereum smart contracts using Solidity. There’s no setup needed, you can immediately start writing your code.</p><p>It compiles your code for you, and it helps you easily test it. Not only that, you can easily deploy your smart contract too.</p><p><a href="https://remix-project.org/">Remix - Ethereum IDE &amp; community</a></p><h3>9. Hardhat</h3><p>Although Remix is awesome, sometimes it isn’t enough and I miss my VS Code setup with all my 42 extensions. You’ll need a local Ethereum environment if you’re using VS Code. Here’s where HardHat comes into play.</p><p>Hardhat helps you easily deploy your contracts, run tests and debug Solidity code. You can deploy your contract on various networks like Ropsten, Rinkeby, Mainnet etc. Oh, and it also supports TypeScript 🤩</p><blockquote>I like to build and test the functionality of my smart contracts on Remix, and then move it to VS Code when done.</blockquote><p>Here’s a tutorial on HardHat:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9Qpi80dQsGU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9Qpi80dQsGU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F9Qpi80dQsGU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9486215a8bb9b76c8f4af4c9987b76a2/href">https://medium.com/media/9486215a8bb9b76c8f4af4c9987b76a2/href</a></iframe><h3>10. Truffle</h3><p>Truffle is my go-to development tool for smart contracts. It helps you easily compile your smart contracts and use it in your frontend code. Ganache also comes with Truffle, which simulates a blockchain, adds test accounts etc. It’s really helpful to avoid boilerplate.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZo4dYRw9WSE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZo4dYRw9WSE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZo4dYRw9WSE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4324db2db740e7a82d154d5c36fd4145/href">https://medium.com/media/4324db2db740e7a82d154d5c36fd4145/href</a></iframe><p>That’s the end of the post! If you liked it, leave a clap(or two) and follow me not to miss any more posts. Check out my <a href="http://concitio.com/">agency’s website</a> where I help SaaS companies build awesome products. Bye for now!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1e76a23dcc7" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/how-to-become-a-web3-developer-e1e76a23dcc7">How To Become A Web3 Developer</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[8 Super Useful JavaScript Tips]]></title>
            <link>https://blog.devgenius.io/8-super-useful-javascript-tips-659eb34d8f36?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/659eb34d8f36</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Sun, 02 Jan 2022 15:06:31 GMT</pubDate>
            <atom:updated>2022-01-02T15:06:31.158Z</atom:updated>
            <content:encoded><![CDATA[<h4>Use These To Improve Your JavaScript Game</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZk0Zee2kLp0fis1eoF_Hg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@gamell?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Joan Gamell</a> on <a href="https://unsplash.com/s/photos/javascript?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I’ve compiled 8 amazing JavaScript tips to improve your code and impress your teammates. Let’s get started!</p><h3>1. Shortened console.log</h3><p>Despite all the fancy JavaScript debuggers, I tend to use console.log for most of my debugging. It’s a bit tedious writing console.log every time, why don’t we shorten it to c?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8f4d8c07a9dfaa37439090cbe8d57b8/href">https://medium.com/media/c8f4d8c07a9dfaa37439090cbe8d57b8/href</a></iframe><h3>2. Check If Elements Are Equal</h3><p>We can use the every() array method for this. This method returns true if the condition returned from the callback is true for each and every element in the array. Here’s a one-liner to check if all the elements in the array are equal:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8dc67f7f4e44bca37298a0f9ce4a368/href">https://medium.com/media/f8dc67f7f4e44bca37298a0f9ce4a368/href</a></iframe><p>Let’s walk through the above code. We start with a function, which returns the result of calling the every() array method. The every method compares the current element to the first element in the array.</p><p>Since we are assuming that all elements are equal, we can always compare them to the first element. If it’s not the same, then the condition will return false, and every() will return false too.</p><h3>3. Promise Timeout</h3><p>You might be thinking, “Akash, why do we need a timeout? Aren’t promises just objects in JavaScript? So, having an unresolved promise won’t cause any fundamental problem and will get garbage collected(if there’s no code reference)”.</p><p>Well, Sort of… There’s no problem with an unresolved promise, but think about any .then or .catch callbacks depending on the promise. These will probably never get called, which leaves the program unfinished.</p><p>Let’s say the .then and .catch callbacks notify the user about the state of the program, based on the result of the promise. If it never resolves, then the user will be kept waiting, which is obviously a bad user experience.</p><p>Here’s how to create a wrapper for a promise with a timeout:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf5940ecfddc12efdac91c8f4f0712a3/href">https://medium.com/media/cf5940ecfddc12efdac91c8f4f0712a3/href</a></iframe><p>Let’s look at the code above. We have a function promiseWithTimeout(), which takes a promise, along with a timeout. We have a variable timeoutPromise, which is a promise for a setTimeout. Then, we are utilising Promise.race, which returns the result of the promise that resolves first.</p><p>Suppose we pass a timeout of 10000ms into the function. Then, if the promise passed resolves before 10000ms, then its result will be returned. Else, the promise with the timeout will be returned.</p><h3>4. Shuffle An Array</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0f67c17268e87d8e0c4d4240d336478/href">https://medium.com/media/c0f67c17268e87d8e0c4d4240d336478/href</a></iframe><p>0.5 — Math.random() may seem a bit confusing, let me explain. This results in a random number, that may be positive or negative. But, .sort() is not supposed to be used like this, which means all possible combinations may not have the same probability.</p><blockquote>This method is not the most performant, you can use shuffling algorithms to make this more efficient.</blockquote><h3>5. Pause Execution</h3><p>Do you know we can pause the execution in JavaScript? It can be done with a combination of setTimeout and JavaScript promises. Just creating a timeout won’t suffice, since the code will continue. So, we need to wrap it in a promise to stop the code from continuing execution. Here’s the one-liner:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc7ee0b29e9275477f9a4d208cdb1ebb/href">https://medium.com/media/fc7ee0b29e9275477f9a4d208cdb1ebb/href</a></iframe><h3>6. Combine Array and Object Destructuring</h3><p>You’ve probably heard of destructuring in JavaScript. You can do array and object destructuring, but did you know you can combine them? Here’s how it’s done:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee3cbe6402d71c05c192338804915fa9/href">https://medium.com/media/ee3cbe6402d71c05c192338804915fa9/href</a></iframe><h3>7. Number Separators</h3><p>I can’t tell you how many times I’ve messed up numbers in JavaScript. Numbers are super hard to read with separators. But, we have numeric separators to the rescue! This feature is a stage 4 proposal, which allows us to use _ as a separator. Let’s see how we can use it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e2b2a8cbb0225d1427c8723c28c5902/href">https://medium.com/media/2e2b2a8cbb0225d1427c8723c28c5902/href</a></iframe><h3>8. void operator</h3><p>You may have come across the void operator in other programming languages. This takes an expression… and always returns undefined. Pretty useless right? Yeah, 99% of the time you won’t need this. But in case you need it, here’s how it’s done:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52d4344359d242f9b52e132036df63b1/href">https://medium.com/media/52d4344359d242f9b52e132036df63b1/href</a></iframe><p>Thank you for taking the time to read my post. If you found it useful, be sure to let me know in the comments or by leaving claps. For more content on HTML, CSS, JavaScript, React and NodeJS, follow me here on Medium and also on <a href="https://twitter.com/akashcodes">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=659eb34d8f36" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/8-super-useful-javascript-tips-659eb34d8f36">8 Super Useful JavaScript Tips</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[4 Ways to Optimise Images in Your Website Like a Pro]]></title>
            <link>https://medium.com/bitsrc/4-ways-to-optimise-images-in-your-website-like-a-pro-f73cb66ff4ac?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f73cb66ff4ac</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 12:54:40 GMT</pubDate>
            <atom:updated>2022-03-13T15:29:55.590Z</atom:updated>
            <content:encoded><![CDATA[<h4>Users get bored before a TikTok ends, why will they wait for your site to load?</h4><p>Images are one of the most important factors in a webpage. People remember websites by brand and imagery, not text.</p><p>37% of your users will bounce if your website takes more than 5 seconds to load! It’s therefore, important that you do whatever you can to reduce load times and improve performance.</p><p>So with that in mind, let’s look at some useful techniques to optimise images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Q38fHpntAfyEage-X83rA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@glenncarstenspeters?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Glenn Carstens-Peters</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Combine image formats</h3><p>There are several types of image formats — JPG, JPEG, PNG, WEBP, AVIF etc. I suggest utilising WebP or AVIF for your images, depending on the browsers you want to support. WebP and AVIF are the most modern image formats, and they deliver high quality, with a small size.</p><p>I suggest utilising WebP or AVIF for your images, depending on the browsers you want to support.</p><p>These are the supported browsers for the WebP format. WebP is largely supported across all major browsers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M5nM6jrXth7DfZDi79SR-A.png" /><figcaption>WebP Support</figcaption></figure><p>And here is the same again for AVIF format:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npHvSgsnc8kbICfXAmUMxw.png" /><figcaption>AVIF Support</figcaption></figure><p>You could use WebP across all browsers, but then you’d be missing out on decreased load times in Chrome and Safari if you don’t use AVIF<em> (about 66.6% people use this)</em>.</p><p>We can use the picture element to show AVIF by default, and if it isn’t supported, we show the WebP format behind the scenes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ee66c7de3e9495071450eed6d96c42c/href">https://medium.com/media/6ee66c7de3e9495071450eed6d96c42c/href</a></iframe><p><strong><em>Note</em></strong><em>: If you want to combine more formats, you can add more </em><em>source elements for your formats.</em></p><h3>Lazy Loading</h3><p>Lazy loading is the process of showing an image only when it appears in the viewport.</p><p>Say there are 4 images, two on the home page, and the user has to scroll to reach the other 2 images. Initially, we load only the first two images, and when the user scrolls down, we load the other 2 images. This helps decrease the initial page load time.</p><p>There are three ways to load images lazily:</p><h4>1. Loading Attribute</h4><p>The img tag has an attribute called loading, which is super handy. All we have to do is set it to lazy! Here’s an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/309b30bc124bf178645b39eabb9ea23b/href">https://medium.com/media/309b30bc124bf178645b39eabb9ea23b/href</a></iframe><p>Unfortunately, it’s not widely supported:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a_K8FoODWBfvyKedHQGKwA.png" /><figcaption>Supported in Chrome, works only with images in FireFox</figcaption></figure><h4>2. Intersection Observer</h4><p>The Intersection Observer is a JavaScript API that triggers a callback when an element scrolls into viewport.</p><p>We can set the src of the img from JavaScript when the image is visible, which causes the browser to load the image.</p><p>Here’s an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5502e37f7f9f512739b5aeff243e0a0/href">https://medium.com/media/f5502e37f7f9f512739b5aeff243e0a0/href</a></iframe><p>I like using Intersection Observer as it is supported by all major browsers, and it is fairly easy to implement.</p><h4>3. Scroll Events</h4><p>This is implemented using the scroll, resize, orientationChange, events in the browser.</p><p>The reason we are watching for these events as they trigger a change in the layout of the images. When one of these are triggered, we look at all unloaded images, and see which ones are in the viewport. If it’s in the viewport, we set the src from the data-src attribute.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edbdf27cce617120b9792fdbf0b661cf/href">https://medium.com/media/edbdf27cce617120b9792fdbf0b661cf/href</a></iframe><p>I don’t like this method, as it’s complicated, and not very clean. But, if I had to support IE, I would utilise this method.</p><h3>Fixed Image Dimensions</h3><p>CLS or Cumulative Layout Shifts are caused due to the browser recalculating the layout once the image is loaded. The browser is unsure of the dimensions of the image before it’s loaded, so once it is loaded, the browser has to make space for the image. This increases the users waiting time, which is bad.</p><p>An easy solution to this is specifying the dimensions using the width and height attributes. This instructs the browser to reserve space for the image. When the image loads, the browser no longer has to recalculate the layout to fit the image.</p><p>Here’s an example:</p><pre>&lt;img src=&quot;img.png&quot; width=&quot;300&quot; height=&quot;300&quot;&gt;</pre><h3>Compressed Images</h3><p>This may seem obvious, but there are so many websites with bad image compression.</p><p>A useful tool I like to use <a href="https://squoosh.app/">squoosh.app</a>. It lets you compare your original image, with your new one while testing out different sizes and formats.</p><h3>Responsive Images</h3><p>About 50% of users browse the internet using the mobile. Please, make your websites responsive. It’s so irritating when an image is breaking the layout!</p><p>We can use the srcset property on the img element, to use different images for different devices. The browser does some calculations based on the viewport width and pixel density. Based on this, the browser and chooses the best size of the image.</p><p>Below demonstrates how you would implement this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d913017617cbc331400a126aecf082b4/href">https://medium.com/media/d913017617cbc331400a126aecf082b4/href</a></iframe><h4>TLDR;</h4><p>The 4 ways to optimise images are:</p><ol><li>Combining Image Formats</li><li>Lazy Loading</li><li>Image Compression</li><li>Responsive Images</li></ol><p>Thank you for taking the time to read my post. If you found it useful, be sure to let me know in the comments or by leaving claps. You can also follow me here on Medium and also on <a href="https://twitter.com/akashcodes">Twitter</a>.</p><h3>Build composable web applications</h3><p>Don’t build web monoliths. Use <a href="https://bit.dev/">Bit</a> to create and compose decoupled software components — in your favorite frameworks like React or Node. Build scalable frontends and backends with a powerful and enjoyable dev experience.</p><p>Bring your team to <a href="https://bit.cloud/">Bit Cloud</a> to host and collaborate on components together, and greatly speed up, scale, and standardize development as a team. Start with composable frontends like a Design System or Micro Frontends, or explore the composable backend. <a href="https://bit.dev/"><strong>Give it a try →</strong></a></p><figure><img alt="https://cdn-images-1.medium.com/max/800/1*ctBUj-lpq4PZpMcEF-qB7w.gif" src="https://cdn-images-1.medium.com/proxy/1*ctBUj-lpq4PZpMcEF-qB7w.gif" /></figure><h3>Learn More</h3><ul><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://blog.bitsrc.io/the-composable-enterprise-a-guide-609443ae1282">The Composable Enterprise: A Guide</a></li><li><a href="https://blog.bitsrc.io/7-tools-for-faster-frontend-development-in-2022-43b6f663c607">7 Tools for Faster Frontend Development in 2022</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f73cb66ff4ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/4-ways-to-optimise-images-in-your-website-like-a-pro-f73cb66ff4ac">4 Ways to Optimise Images in Your Website Like a Pro</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Choosing A Router In React Apps]]></title>
            <link>https://medium.com/front-end-weekly/choosing-a-router-in-react-apps-85ae72fe9d78?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/85ae72fe9d78</guid>
            <category><![CDATA[router]]></category>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 13:18:58 GMT</pubDate>
            <atom:updated>2021-08-10T13:18:58.819Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jx9lN6T08xIurdHebnSXgA.png" /></figure><p>Most of us just install react-router and use the BrowserRouter. But, have you ever stopped and wondered why BrowserRouter is called BrowserRouter and not just Router? This indicates that there are different types of routers offered by react-router.</p><p>In this article, we’ll learn about these types, understand how to use them and finally, compare them to decide which one is best for your needs.</p><p>I’ll make one think clear at the start, this is not a comparison of react router vs reach router(there are plenty of articles online about that). This post is about choosing between 4 fundamental types of routers. Let’s start with the most straightforward and most used router:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><h3>BrowserRouter</h3><p>Uses everything after the domain(eg .com, .in, .io etc) as the path. For example, if the url is localhost:3000/home, then /home is the path/route. This router uses the <a href="https://developer.mozilla.org/en-US/docs/Web/API/History">HTML 5 History API</a> to keep the UI in sync with the the path.</p><p>BrowserRouter is used for doing client side routing with URL segments. You can load a top level component for each route. This helps separate concerns in your app and makes the logic/data flow more clear. Let’s see how this can be implemented in code using react-router:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c7c6869c21c4c36105a7c73d8d5103b/href">https://medium.com/media/8c7c6869c21c4c36105a7c73d8d5103b/href</a></iframe><blockquote>We’ll look at the advantages and disadvantages when we compare the routers later.</blockquote><h3>HashRouter</h3><p>This is similar (visually) to the browser router, with the only difference being that a # is added between the domain and the path. Let’s say the url is localhost:3000/#/home, then the /home is the route. Basically, it uses everything after the # as the path. Now, we’ll see how to implement this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99690a32b0a2dcbe229559998d2bfbb6/href">https://medium.com/media/99690a32b0a2dcbe229559998d2bfbb6/href</a></iframe><p>We have an App() component in which we are returning a HashRouter with a route. If you run our little app in the browser, you will find out that react router automatically adds a # before the path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/0*W4wOqf7OJIT7y8vf.png" /></figure><blockquote>That’s pretty much it. This is the main visual difference between a browser router and a hash router. The # does not seem very relevant but trust me, it has a perfectly valid reason.</blockquote><blockquote>Important Note: <em>location.state</em> and <em>location.key</em> does not work with <em>react-router</em>’s <em>HashRouter</em>.</blockquote><h3>MemoryRouter</h3><p>It keeps the history of your “URL” in memory (does not read or write to the address bar). It’s useful in tests and non-browser environments like <a href="https://facebook.github.io/react-native/">React Native</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d42da6a34b7e58d30b21d45a0ebf22d2/href">https://medium.com/media/d42da6a34b7e58d30b21d45a0ebf22d2/href</a></iframe><blockquote>The component will change when you click on a link but the url will remain the same</blockquote><h3>StaticRouter</h3><p>This is useful in server-side rendering scenarios when the user isn’t actually clicking around, so the location never actually changes. Hence, the name: static. It’s also useful in simple tests when you just need to plug in a location and make assertions on the render output.</p><h3>Comparing Routers</h3><ul><li>Browser Router</li></ul><p>The browser router is often very complicated to deploy to servers. It uses <a href="https://developer.mozilla.org/en-US/docs/Web/API/History_API">history API</a>, so it’s unavailable for legacy browsers (IE 9 and lower and contemporaries.. but who cares about that those, we are modern folks here😎).</p><p>Client-side React application is able to maintain clean routes like <em>example.com/react/route</em> but needs to be backed by a web server. A traditional web server evaluates requests like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*uIRluzH_R1bRnLE0.png" /></figure><p>In case of a single page application, it’s just a single index.html file which requires some extra configuration on the hosting server.</p><blockquote>However, these days a lot of hosting providers assume that we use this kind of routing and simplify the process.</blockquote><p>We can also use server side rendering with this router, index.html may contain rendered components or data that are specific to current route.</p><ul><li>Hash Router</li></ul><p>Enough of browser routers, let’s talk hash routers. We can quite easily configure our server to ignore the # and server the entire html file regardless of the route. This hash will be used by our routes to show the appropriate content.</p><p>Also, HashRouter use cases aren&#39;t limited to SPA. A website may have legacy or search engine-friendly server-side routing, while React application may be a widget that maintains its state in URL like <em>example.com/server/side/route#/react/route</em>.</p><ul><li>Memory Router</li></ul><p>Memory routers will refresh/change the component but no the url. This probably will leave the user hanging and he or she might think that his computer has hanged or there is an issue with the site which is certainly not pleasant for the user.</p><p>On the other hand, this is great for environments in which the url is not shown like React Native, Testing Environments etc</p><ul><li>Static Router</li></ul><p>Static routing can be used to define an exit point from a router when no other routes are available or necessary which is called a default route. Think of this as a fallback route(404s). Static routing can be used for small networks that require only one or two routes.</p><h3>Conclusion</h3><p>The router you pick largely depends on the application, amount of resources and deployment. Use browser routers if your hosting provider automatically does most of the configuration for you or you have the resources to hire a devOps guy. I’d recommend hash routers when you want to quickly deploy without any hassle. Memory routers are helpful in test environments and react native. I added memory routers just for your information but I’m not a huge fan of it because I mainly operate in browser environments.</p><p>That’s all for now, I hope you guys liked this post! Follow me on <a href="https://twitter.com/AkashShyam11">twitter</a> where I post tips and memes(really helps to brighten your day if you are working on a tough bug). Bye for now 🤘</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85ae72fe9d78" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/choosing-a-router-in-react-apps-85ae72fe9d78">Choosing A Router In React Apps</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Improve Performance Using useLayoutEffect In React Sites?]]></title>
            <link>https://medium.com/front-end-weekly/how-to-improve-performance-using-uselayouteffect-in-react-sites-3a204888247e?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a204888247e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 13:18:50 GMT</pubDate>
            <atom:updated>2021-08-10T13:18:50.779Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HWZGRh3m4mxoEU0GUoE9Ow.png" /></figure><p>Most of us just use useEffect for everything(API calls, DOM manipulations using useRef etc). 95% of the time, the useEffect is the right choice. Both of them are very similar, but have different use cases. Let’s look at what they are and then we’ll do a compare.</p><h3>useEffect</h3><p>Most of you know what this does, but we’ll still do a quick overview to refresh your memory. This hooks lets perform side effects in functional components. It takes in a function that runs some code in the background after the component is mounted and an array of dependencies(when these change, the function will rerun).</p><pre>useEffect(() =&gt; {<br>  // Execute some code in background</pre><pre>// Cleanup function<br>  return () =&gt; {};<br>}, []);</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><h3>useLayoutEffect</h3><p>This hook is executed almost the same as the useEffect. It takes a function which runs the side effect. The return value of the function(which is a function or undefined) does cleanup. Here’s a useful metaphor to understand the system of effects and cleanup functions:</p><p>Let’s say you have booked a hotel in another city for the next week. But, due to a family emergency, you have to cancel. So, we need to inform the hotel that you can’t make it and your visit should be postponed/cancel.</p><p>In a similar fashion, the side effect is booking a hotel. The “family emergency” in this case is the component being unmounted(the cleanup function is called when this happens). Because we can’t make it, we’ll need to inform the hotel that we need to cancel which is basically the clean up function. Here’s how we can use this hook:</p><pre>useLayoutEffect(() =&gt; {<br>  // DOM manipulation</pre><pre>// Optional cleanup function<br>  return () =&gt; {};<br>}, []);</pre><h3>The Grand Comparison</h3><ul><li>useEffect</li></ul><p><strong>The catch </strong>is that useEffect runs <em>asynchronously</em> and after a render is painted to the screen. It&#39;s more performant this way and perfect for API calls, most of the time this is what you want.</p><p>However, if your effect is mutating the DOM(DOM node ref), then the user will see a flicker of content. For a split second, the page will be blank and then it will be visible again in a second. This is due to the time taken for the useEffect to mutate the DOM and then render it. Here’s a step by step process of what happens:</p><ol><li>A render is triggered in the application(dependency change)</li><li>React renders your component</li><li>React updates the screen(visually)</li><li>Then, the useEffect is called in the background.</li><li>If you mutate DOM node refs in useEffect, then a re-render is triggered, and while the effect is changing the DOM, the screen goes blank. Once the effect is done mutating the DOM, the screen is updated</li><li>Rinse and Repeat!</li></ol><ul><li>useLayoutEffect</li><li>useLayoutEffect</li></ul><p>On the other hand, this runs <em>synchronously</em> after the component is updated. Here’s how this works:</p><ol><li>A render is triggered(dependency change)</li><li>React renders your component</li><li>Next, useLayoutEffect is called</li><li>As I said, useLayoutEffect is <em>synchronous </em>so React<em> </em>waits for it to finish</li><li>The screen is updated</li><li>Repeat again!</li></ol><p>A simple rule of thumb I follow: just try using useEffect 99% of the time; if your component is flickering, try switching to useLayoutEffect.</p><blockquote>The reasoning behind this rule is because <em>useLayoutEffect</em> is synchronous which means the app won’t visually update until your effect finishes running… it could cause performance issues like stuttering if you have slow code in your effect. Along with the fact that most effects don’t <em>need</em> the world to pause while they run, regular <em>useEffect</em> is almost always the one to use.</blockquote><p>That’s all for now, I hope you guys liked this post! Follow me on <a href="https://twitter.com/akashshyam11">twitter</a> where I daily post tips, tricks and memes for developers. Bye for now 🤘</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a204888247e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/how-to-improve-performance-using-uselayouteffect-in-react-sites-3a204888247e">How To Improve Performance Using useLayoutEffect In React Sites?</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Bring the Browser DevTools and Console to VS Code]]></title>
            <link>https://javascript.plainenglish.io/how-to-bring-the-browser-devtools-and-console-to-vs-code-848edc257094?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/848edc257094</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Mon, 09 Aug 2021 14:17:28 GMT</pubDate>
            <atom:updated>2024-08-21T10:44:05.033Z</atom:updated>
            <content:encoded><![CDATA[<h4>Combine your entire setup inside your IDE</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w1Cu4txxzHJST8oWWfOVQA.png" /></figure><p>How cool would it be to have all the tools we need for frontend development right inside VS Code? The console, dev tools, terminal — all that stuff, inside VS Code, right next to the code we so dearly love.</p><p>Most developers do something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ex0Mj05slOfkeqJJhME3EA.png" /></figure><p>But now, we can leverage the power of the dev tools inside vs code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/0*Ac6OlMcQFZ0fAVNb.jpg" /></figure><p>Start by clicking on Run and Debug button or click CMD + Shift + D in the sidebar, the icon may vary as per your icon theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qn_bc0JnX_JSZ3-Vd0_Tpw.png" /></figure><blockquote><em>💡 </em>Speed up your blog creation process with <a href="https://differ.blog/differ-ai"><strong><em>DifferAI</em></strong></a>.</blockquote><blockquote>Available for <strong><em>free</em> </strong>exclusively on the <strong><em>free and open blogging platform, </em></strong><a href="https://differ.blog/"><strong><em>Differ</em></strong></a><strong>.</strong></blockquote><p><a href="https://differ.blog/differ-ai">Introducing DifferAI</a></p><p>Then, click on the Run and Debug button which opens a panel showing the available browsers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FWOElre5wkd5dIFwYJsWIw.png" /></figure><p>Then, choose Edge: Launch, Yes, you read this correctly and I’m not insane. Let’s look at why we need to choose Microsoft Edge:</p><h3>Why Microsoft Edge?</h3><p>Most developers use either Firefox or Chrome for their dev tools and console. Evidently, Microsoft isn’t too happy about that. Since Microsoft owns VS Code, obviously, VS code will be used by the tech giant to convert developers to Edge.</p><p>Before you start squirming in your seats, I’ll tell you that Edge is just repackaged chrome. Microsoft Edge uses the Chromium browser engine internally. Therefore, it has the same dev tools and console as chrome. So, give it a chance!</p><h3>The Setup</h3><p>Firstly, we need to have the <a href="https://www.microsoft.com/en-us/edge">Microsoft Edge</a> Browser on our computer. We also need to install an extension for the <a href="https://marketplace.visualstudio.com/items?itemName=ms-edgedevtools.vscode-edge-devtools#:~:text=The%20DevTools%20will%20connect%20to,without%20leaving%20Visual%20Studio%20Code.&amp;text=You%20can%20use%20the%20extension,or%20embedded%20in%20your%20editor.">dev tools</a> inside VS Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U0plR1s8541sdwG42ul5fg.png" /></figure><p>After selecting the Microsoft Edge option, a debugging panel will open. Then click on the last icon in the dev tools panel to open the dev tools:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ChesxwZIUJodhlvqg0WYw.png" /></figure><p>As you can see, the elements tab is opened. Apart from this, we can also access the network tab. You can also interact with the site by clicking on the window shown in VS code.</p><blockquote>In case you can only see the dev tools but not the website, click on the icon this icon to open the site:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*4OCjSxtbneoPdj5rJFexOw.png" /></figure><p>For some people who code using their laptop, or feel that their screen is just too cluttered, you can drag the website preview into the bar where we see the files. Check out the following screencast to see how to use the full potential of this feature:</p><p><a href="https://vimeo.com/583459634">Screen Recording 2021-08-05 at 21.44.43.mov</a></p><blockquote>You might have noticed a browser window being opened, you can minimise it but it is essential to leave it open otherwise the dev tools won’t work. This is because the window we see in vs code as the browser is like a screencast of the external window. So if you zoom in the external window, the vs code window will also zoom in.</blockquote><h3>Live Refresh</h3><p>This is a completely new feature, so we must be patient since it won’t have all the bells and whistles. However, the VS Code team has the auto-reload feature on the roadmap and I’m pretty sure we can see it in a few months.</p><p>Until then, don’t worry, I have a solution. If you notice, the URL opens the file on our computer. But, we can use hot reload using a live server. For this, we’ll use an NPM package called <a href="https://www.npmjs.com/package/reload">reload</a>. Install it by typing the following in the terminal:</p><pre>npm i reload -g</pre><p>After installing, run this in the command line:</p><pre>reload</pre><p>That’s it, you have your own live server on localhost:8080. Next, we need to tell vs code to use this server. Select Generate launch.json, which is basically like a configuration file for the debugger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i7Wjy0u1INjD-iRcAkh_uw.png" /></figure><p>The default launch.json will look like this:</p><pre>{<br> &quot;configurations&quot;: [<br>  {<br>   &quot;name&quot;: &quot;Launch Microsoft Edge and open the Edge DevTools&quot;,<br>   &quot;request&quot;: &quot;launch&quot;,<br>   &quot;type&quot;: &quot;vscode-edge-devtools.debug&quot;,<br>   &quot;url&quot;: &quot;&quot;<br>  }<br> ]<br>}</pre><p>Replace the url field with <a href="http://localhost:8080/">http://localhost:8080</a>.</p><blockquote>Create React App, Vite, Vue etc also give us live servers and we can update the URL as shown about</blockquote><p>Now, we need to restart our debugger. Click the red square to stop it. Then go to the debugger icon in the sidebar and select Launch Project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rc_znil1_vESeY0STyX21Q.png" /></figure><p>Look at the URL bar in the following image, it says localhost:8080. If we edit any file in the project, it will auto-refresh. Yay!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*11yQTHmCtChGmMBLM9BHKw.png" /></figure><h3>Where is The Console?</h3><p>Traditionally, we use console.log()s in our code during debugging. Now, we can use breakpoints. Breakpoints are essentially breaks inside our code where we can inspect the call stack, the current value of variables, etc.</p><p>For this, we’ll need to add some configurations to the launch.json. Go to the debugger icon on the sidebar and click the settings icon which will open launch.json. Update the lauch.json with this:</p><pre>{<br> &quot;configurations&quot;: [<br>  {<br>   &quot;name&quot;: &quot;Launch Edge&quot;,<br>   &quot;request&quot;: &quot;launch&quot;,<br>   &quot;type&quot;: &quot;pwa-msedge&quot;,<br>   &quot;url&quot;: &quot;<a href="http://localhost:8080/">http://localhost:8080</a>&quot;,<br>   &quot;webRoot&quot;: &quot;${workspaceFolder}&quot;<br>  },<br>  {<br>   &quot;name&quot;: &quot;Launch Microsoft Edge and open the Edge DevTools&quot;,<br>   &quot;request&quot;: &quot;launch&quot;,<br>   &quot;type&quot;: &quot;vscode-edge-devtools.debug&quot;,<br>   &quot;url&quot;: &quot;<a href="http://localhost:8080/">http://localhost:8080</a>&quot; // Provide your project&#39;s url to finish configuring<br>  }<br> ]<br>}</pre><blockquote>Remember to update the URL according to your application</blockquote><p>Now when we go to the debug icon, we have two configurations to chose from in the dropdown:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R0WwiBbM6Xnce11cCQZaGA.png" /></figure><p>We can add breakpoints by clicking at the right of where we see the no of lines. So now when the code executes and reaches the breakpoint, the code execution pauses and we can see the value of the variables, call stack, etc in the debugger panel on the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FrjSQ_PGc8vfsEHooH9Fbw.png" /></figure><p>We can see the debugger on the right, code and console on the left. If you think the website&#39;s previous inside VS Code is too tiny, move the website to another monitor and use the dev tools/console in VS Code. Talk about the holy grail of debugging!</p><h3>Should We Use This?</h3><p>I think having the dev tools and console inside vs code will make us a lot more productive. There will be a lot less back and forth between vs code and the browser. Try it out in your next project and let me know how it goes!</p><p>That’s it for now, I hope you guys liked this post. Thanks for reading and follow me on <a href="https://twitter.com/AkashShyam11">Twitter</a> where I post tips, tricks, and memes. Bye for now! 🤘</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=848edc257094" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-bring-the-browser-devtools-and-console-to-vs-code-848edc257094">How to Bring the Browser DevTools and Console to VS Code</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Yarn 3.0 — What’s New?]]></title>
            <link>https://medium.com/@akash.shyam2008/yarn-3-0-whats-new-b6296fb38928?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6296fb38928</guid>
            <category><![CDATA[yarn-package-manager]]></category>
            <category><![CDATA[yarn]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Sat, 31 Jul 2021 13:28:27 GMT</pubDate>
            <atom:updated>2021-07-31T13:28:27.076Z</atom:updated>
            <content:encoded><![CDATA[<h3>Yarn 3.0 — What’s New?</h3><p>Yarn was created by Facebook in 2016 as an alternate option to NPM(at that time, an improvement too). If you haven’t heard about Yarn, here’s some background:</p><h3>Breaking Changes</h3><p>Let’s start with the most important changes(a.k.a breaking changes) in the Yarn Infrastructure:</p><ul><li>Dropped support for Node 10</li><li>Plugins can’t access yup</li><li>The enableImmutableInstalls options will now default to true</li><li>The initVersion and initLicense configuration options have been removed. initFields should be used instead</li><li>Yarn will now generate .pnp.cjs files (instead of .pnp.js) when using PnP, regardless of what the type field inside the manifest is set to.</li><li>The virtual folder (used to disambiguate peer dependencies) is renamed to __virtual__ to $$virtual</li></ul><blockquote>As you can see, most of these changes are internal changes. You can check the rest of them <a href="https://github.com/yarnpkg/berry/blob/master/CHANGELOG.md">here</a></blockquote><h3>Performance</h3><p>A couple of changes have been made regarding some of the largest resource consumptions in Yarn. Installs have been improved (which makes Yarn faster than PnP in some scenarios, quite impressive!). Progress bars are rendered less often, which might help performances on some terminals. The catch files are now in zip instead oftgz which impacts cold install performance.</p><h3>Bug Fixes</h3><ul><li>Yarn now has a <a href="https://github.com/yarnpkg/berry/blob/master/GOVERNANCE.md">governance model</a></li><li>Peer dependencies depending on their own parent are now properly hoisted by node-modules linker</li><li>Boolean values will be properly interpreted when specified inside the configuration file via the ${ENV_VAR} syntax.</li><li>Should any of preinstall, install, postinstall fail, the remaining scripts will be skipped.</li><li>The git: protocol will now default to fetching HEAD (rather than the hardcoded master).</li><li>The SIGTERM signal will now be propagated to child processes.</li></ul><blockquote>I haven’t listed all the bugs here, check <a href="https://github.com/yarnpkg/berry/blob/master/CHANGELOG.md#bugfixes">this</a> out to learn more</blockquote><h3>ESBuild Support</h3><p>Yarn now uses esbuild to generate yarn bundles to improve compatibility with the Plug ’n’ Play installs. The result is the new <a href="https://github.com/yarnpkg/berry/tree/master/packages/esbuild-plugin-pnp">esbuild-plugin-pnp</a> module which lets you transparently build your code using the default Yarn installation mode. It’s still new so there may be some bugs. While this won’t change much for most end-users, the move to ESBuild also provided decent build speed improvements (around 6x faster).</p><h3>Future Releases</h3><p>A few features that were initially planned to be rolled out for 3.0 have been pushed back to the next minor release. Here are some of them:</p><ul><li><a href="https://github.com/nodejs/corepack">Corepack</a> Integration</li><li>ESM support under PnP mode</li><li>Built-in CLI completion</li><li>More Performance Improvements</li></ul><blockquote>Checkout the <a href="https://yarnpkg.com/getting-started/migration#step-by-step">migration guide</a> if you want to update your code!</blockquote><p>That’s all for this article guys! I hope you liked it and learned something new today. Follow me on <a href="https://twitter.com/AkashShyam11">twitter</a> and don’t forget to like this article! Bye 🤟</p><p>Credits — <a href="https://github.com/yarnpkg/berry/blob/master/CHANGELOG.md#bugfixes">changelog</a> and <a href="https://dev.to/arcanis/yarn-3-0-performances-esbuild-better-patches-e07">article of a yarn maintainer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6296fb38928" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Level Up Your Commit Messages With These Tips!]]></title>
            <link>https://gitstacks.com/level-up-your-commit-messages-with-these-tips-7e66ea34470d?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e66ea34470d</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[development-commits]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Fri, 30 Jul 2021 16:10:49 GMT</pubDate>
            <atom:updated>2021-08-05T06:30:45.278Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tlP5Ec6K9hK5wl7B2d7cXw.png" /></figure><p>At some point, we’ve all come across a commit message we don’t understand. In my opinion, every team should create a list of commit guidelines or conventions(and stick to it). You might be wondering, why is it so important to right good commit messages?</p><h3>Why Write Meaningful Commit Messages?</h3><p>Commit messages are a way of communication between the team. Let’s say there is a bug in the application in part ‘x’. The person who is trying to fix it only has to see commit messages regarding part ‘x’. A well written commit message can save a great deal of time finding the recent changes related to a bug.</p><p>Being a new member of a team and working on projects we haven’t seen before has its challenges. For example, you just joined a team and have been asked to integrate AWS S3 buckets in portion of the application. However, you have not been provided the credentials and the codebase is too large to manually search through the config files. But, the same file upload is already implemented in another part of the application and you just have to extract it into a reusable component.</p><p>You can go to the commit list and search for messages with “AWS S3”, look for the files which have changed and start refactoring! Now, let’s look at 7 tips to write better commit messages.</p><h3>1. Specify the type of comment</h3><ul><li>feat: for feature addition</li><li>fix: for bug fixes</li><li>refactor: for changing the way a code block is written without changing the final result</li><li>style: for style changes(CSS/Sass etc)</li><li>test: anything and everything about testing</li><li>docs: documentation addition/updates</li><li>chore: code maintenance</li></ul><p>Do not restrict yourself to these types, feel free to add more types of comments but be consistent across the code base.</p><h3>2. Never assume another developer understands the original problem i.e. the reason for the commit</h3><p>I recently started working on an existing codebase along with 3 developers. Me and another dev just started working on the codebase. On the second day, when I woke up to pull the latest code to my database I see this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71f1029297418e7726ffd95609a0c6a8/href">https://medium.com/media/71f1029297418e7726ffd95609a0c6a8/href</a></iframe><p>When I looked at it, I had no idea what the problem was. After about 15 minutes of chatting back and forth, I finally understood the original problem.</p><p>Just a single paragraph, that’s all I ask. One paragraph describing the problem containing 2–3 lines. It will help you too in the future, when you come back later trying to fix a bug.</p><h3>3. Limit the subject line to 50 characters</h3><p>50 characters is not a hard limit, just a rule of thumb. Keeping subject lines at this length ensures that they are readable, and forces the author to think for a moment about the most concise way to explain what’s going on. The VScode source control also gives a warning when the characters in the subject go over 50.</p><blockquote>Github will truncate commit messages(the subject line) over 72 characters</blockquote><h3>4. Separate commit heading from body with a blank line</h3><p>Leave a line between the heading and the body to ensure the reader clearly understands the separation. Also leave a blank line after each paragraph</p><h3>5. Don’t write irrelevant stuff in commit messages</h3><p>Until now, it may seem that we should always write large commit messages but there’s a limit for everything. Don’t write your entire life story in there, be short, clear and concise.</p><p>Do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/334539a0041dcf294904eea576d3a3f3/href">https://medium.com/media/334539a0041dcf294904eea576d3a3f3/href</a></iframe><blockquote>I’ve written a brief description because the example was quite simple, but don’t hesitate to give more details. But remember, be concise and clear.</blockquote><p>Do Not:</p><h3>6. Explain “What Changed” And “Why” Instead Of “How”</h3><p>State the original problem and why you had to use change it. Then, (in detail), state how the your code changes the way the application works currently. Also, if there is some improvements to be made, specify that too.</p><p>To Not Do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2ba7a46e05eeed4d487d2ce5e9c4f06/href">https://medium.com/media/f2ba7a46e05eeed4d487d2ce5e9c4f06/href</a></iframe><p>To Do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d33fa105e7d0fdeaf2310c3c828a469d/href">https://medium.com/media/d33fa105e7d0fdeaf2310c3c828a469d/href</a></iframe><blockquote>Feel free to add more details in the problem/solution. I’ve written in short, because there is no more relevant details I can add.</blockquote><h3>7. Use Emojis in your commits(GitMoji)</h3><p>Using emojis to start your messages are very helpful when scanning through a long list of commits. VSCode has a handy extension called Gitmoji that helps us to add emojis at the start of the comment.</p><p>After installing that extension from the marketplace, you can see a “smiling” emoji in the source control panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*aBDzMA5ups8T3f__GSJOYA.png" /></figure><p>After clicking on the “smiley face”, a menu will open with various emojis and their explanation written on the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XpjuGy5DA3-4gAE4ReCVVA.png" /></figure><p>Here’s how a commit with an emoji looks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43b39b896f5fcf98421943bbda703780/href">https://medium.com/media/43b39b896f5fcf98421943bbda703780/href</a></iframe><p>That’s it for this post guys. I hope you liked it. Do post other conventions you follow in the comments. Follow me for more such content on <a href="https://twitter.com/AkashShyam11">twitter</a>. Bye 🤘</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e66ea34470d" width="1" height="1" alt=""><hr><p><a href="https://gitstacks.com/level-up-your-commit-messages-with-these-tips-7e66ea34470d">Level Up Your Commit Messages With These Tips!</a> was originally published in <a href="https://gitstacks.com/">GitStacks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use These 7 Tips For Clean And Maintainable Code]]></title>
            <link>https://blog.devgenius.io/use-these-7-tips-for-clean-and-maintainable-code-d6eface6149d?source=rss-8d6a52bf9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6eface6149d</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Akash Shyam]]></dc:creator>
            <pubDate>Mon, 26 Oct 2020 12:09:59 GMT</pubDate>
            <atom:updated>2021-08-09T16:05:50.141Z</atom:updated>
            <content:encoded><![CDATA[<h4>Leverage these tips to be respected among your developer friends 😎</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*EDtJ2_hEGbryRwZA" /><figcaption>Photo by <a href="https://unsplash.com/@jeshoots?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">JESHOOTS.COM</a> on <a href="https://unsplash.com/s/photos/cleaning?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>It’s all about maintaining clean and readable code(which works of course). So, I wanted to share a few tips with you guys. Feel free to correct me or share more tips of your own in the comments to create a learning experience for all of us. Let’s get to it then:</p><h3>1. Comments, Comments and More Comments</h3><p>I’m not the ideal developer whose code is understood by everyone and I’m betting you aren’t either. Instead of explaining what exactly to do, I’m going to tell you what not to do. Let’s look at some sample code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae7eac8f8f29adbb67d7c59494fd6708/href">https://medium.com/media/ae7eac8f8f29adbb67d7c59494fd6708/href</a></iframe><p>Instead when use comments when you have complex code blocks.</p><h3>2. Meaningful Names</h3><p>You want to use those kinds of names where the reader goes, “Yes! I know exactly what this does”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/746c1515dcf9e702cd7e24669d4e70fb/href">https://medium.com/media/746c1515dcf9e702cd7e24669d4e70fb/href</a></iframe><h3>3. Don’t Ignore Console/ESLint Warnings</h3><p>This is a huge problem, so many times I’ve seen developers commit code with eslint warnings. In fact, a couple of months ago, I started working on an existing project. When I compiled the frontend, there were over 100 warnings by jsx-ally, eslint etc.</p><p>We can use <a href="https://www.npmjs.com/package/husky">husky</a> along with <a href="https://www.npmjs.com/package/lint-staged">lint-staged</a> which will not let you commit code until you clear all the warnings and errors.</p><h3>4. Don’t use &quot;as unknown” in Typescript</h3><p>Typescript is smart, but sometimes, it just isn’t smart enough! I’ve seen a lot of // @ts-ignores or as unknowns in typescript code. So, look at this example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/851434fbf18f2c1a04980c31332a863d/href">https://medium.com/media/851434fbf18f2c1a04980c31332a863d/href</a></iframe><p>Even though doing this is not advisable, at least you get some type safety.</p><h3>5. Use Babel Instead of tsc</h3><p>From version 7, Babel added support for TypeScript, which means you no longer need to use the TypeScript compiler i.e. tsc to build your project, but instead can just use Babel which simply strips your types from all TypeScript files and then emits the result as JavaScript.</p><p>This is not only much faster than tsc, especially in bigger projects, but also allows you to use the whole Babel ecosystem within your project. For example, it’s great when you want to use react or javascript features which are still in stage 3.</p><p>For back-end projects, this means you can simplify your clunky file-watching scripts and just use babel-node to watch for changes.</p><h3>6. Use SonarJS and Eslint</h3><p>Eslint has many rules that enforce best practises and conventions and will also help to prevent bugs.</p><p>(TSLint is being deprecated in favor of typescript-eslint; the TSLint plugin SonarTS has been adopted and is now part of SonarJS).</p><p>In addition to ESLint’s features, SonarJS adds some complexity checks to your code, which are helpful to just code away and then break your methods into smaller pieces.</p><h3>7. Opaque Types</h3><p>I’m not going to explain, I’ll just demonstrate this to you.</p><p>Imagine we are building a banking API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df724e3b1fd8524f4df7334fbb4bdd74/href">https://medium.com/media/df724e3b1fd8524f4df7334fbb4bdd74/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c49079eccf59322cc2eaf1842dea6bdf/href">https://medium.com/media/c49079eccf59322cc2eaf1842dea6bdf/href</a></iframe><p>Did you spot the bug? If you didn’t, look at the place where we are calling the spend() function. I&#39;ve (intentionally) passed the amount before the accountNumber but typescript does not complain.</p><p>If you are wondering why this happens, this is because AccountNumberType and PaymentAmt are assignable to each other because both of them are of type number.</p><p>There is a long standing issue in the typescript repo about this. Until the typescript team does something about this, we can use the following hack:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49c57298fee41453997dc7e0bf7f0703/href">https://medium.com/media/49c57298fee41453997dc7e0bf7f0703/href</a></iframe><p>The utility function Opaque simply defines a new type that, aside from a variable’s value, also stores a (unique) key, such as Uuid.</p><h3>Conclusion</h3><p>Thanks for reading! Follow me on <a href="https://twitter.com/AkashShyam11">twitter</a> where I post tips, tricks and memes for developer. Bye 🤟</p><p><em>Originally published at </em><a href="https://dev.to/akashshyam/7-tips-for-clean-code-3nk1"><em>https://dev.to</em></a><em> on October 26, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6eface6149d" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/use-these-7-tips-for-clean-and-maintainable-code-d6eface6149d">Use These 7 Tips For Clean And Maintainable Code</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>