<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jithin KS</title>
    <description>The latest articles on DEV Community by Jithin KS (@jithinks).</description>
    <link>https://dev.to/jithinks</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F112212%2F03d39d12-37d3-4c1c-b0ae-05f666882707.jpg</url>
      <title>DEV Community: Jithin KS</title>
      <link>https://dev.to/jithinks</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jithinks"/>
    <language>en</language>
    <item>
      <title>Understanding the Universe through Code: Planetary Motion</title>
      <dc:creator>Jithin KS</dc:creator>
      <pubDate>Fri, 15 Jan 2021 03:58:12 +0000</pubDate>
      <link>https://dev.to/jithinks/understanding-the-universe-through-code-planetary-motion-488h</link>
      <guid>https://dev.to/jithinks/understanding-the-universe-through-code-planetary-motion-488h</guid>
      <description>&lt;p&gt;We know that our planet Earth is in constant motion around the Sun.&lt;/p&gt;

&lt;p&gt;Have you ever thought about how our ancestors discovered this?&lt;/p&gt;

&lt;p&gt;I think most of us don't fully appreciate the difficulties that they encountered in making this discovery.&lt;/p&gt;

&lt;p&gt;Even though we are not feeling it, the Earth is actually moving around the Sun at a staggering speed of 30km/s.&lt;/p&gt;

&lt;p&gt;Just go out and look at the sky during the day time or at night and see if you can find any hints that will help you to reach this conclusion. It turns out that there aren't any trivial ones.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fluk2jpxmq84q8p4sw96j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fluk2jpxmq84q8p4sw96j.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It took the effort of a lot of great scientific minds, over several years, to discover this.&lt;/p&gt;

&lt;p&gt;In this article, we are going to make an effort to understand and appreciate the beauty of this discovery with the help of visualizations.&lt;/p&gt;

&lt;p&gt;Before that, let me tell you about one of the most important observations made by our ancestors that lead to this discovery.&lt;/p&gt;

&lt;p&gt;They carefully observed the motion of planets in the sky over several days and months and kept track of their positions very accurately.&lt;/p&gt;

&lt;p&gt;They found out that the planets traced out a curve which looked like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdh9wdqyr90va3b8ifrrr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdh9wdqyr90va3b8ifrrr.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Can you believe that this observation was what lead them to speculate (correctly) that the Earth and the other planets are moving around the Sun?&lt;/p&gt;

&lt;p&gt;How on earth did this "curve" that they observe in the sky lead them to this seemingly unrelated conclusion?&lt;/p&gt;

&lt;p&gt;Let us try to find this out by creating a miniature solar system visualization.&lt;/p&gt;

&lt;p&gt;And with the help of a few lines of code, we make our solar system model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw38erte8a2vxguv7my4s.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw38erte8a2vxguv7my4s.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is Earth, Mars and the Sun.&lt;/p&gt;

&lt;p&gt;Now let us shift the centre of the coordinate to the Earth. This is necessary because from our viewpoint, we feel that the Earth is stationary and the rest of the heavenly bodies are moving around us.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcsq5u6s39pu7sne44xjc.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcsq5u6s39pu7sne44xjc.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now from this viewpoint, let us look at the trajectory traced by Mars.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwuqe259ou0htc8bzb1kf.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwuqe259ou0htc8bzb1kf.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At first, it might look confusing, but observe this visualization for some time.&lt;/p&gt;

&lt;p&gt;Does the curve look familiar?&lt;/p&gt;

&lt;p&gt;The curve that we see in the sky is a small portion of the curve that we obtained now. But it looks squeezed when viewed from Earth's vantage point.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6n1cyxfzcgb64y8ip5dg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6n1cyxfzcgb64y8ip5dg.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We obtained this by shifting the centre of the coordinate system to the Earth and tracing the path of Mars. Cool isn't it?&lt;/p&gt;

&lt;p&gt;It took Johannes Kepler almost 40 years to analyse the data of the positions of the planets to finally come up with his laws that mathematically explained these ideas.&lt;/p&gt;

&lt;p&gt;If you wish to get more clarity into these ideas, please see the workbook given below and play around with the visualizations and code yourself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dl-next.herokuapp.com/workbook/5ff96ba94d6f6e0017a75a86" rel="noopener noreferrer"&gt;Workbook&lt;/a&gt; (Open in desktop)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4nb81mesrql2p84tblsl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4nb81mesrql2p84tblsl.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PS - While creating the visualizations, I've assumed that the orbits of the planets are circular. But in reality, they are elliptical. The circular orbit which is an approximation gives us a reasonably good explanation. But to be more precise, we need elliptical orbits. And of course, do not take the scales seriously.&lt;/p&gt;

&lt;p&gt;Thanks for reading !!!&lt;/p&gt;

</description>
      <category>visualization</category>
      <category>programming</category>
      <category>math</category>
      <category>physics</category>
    </item>
    <item>
      <title>Dynamic Learning: An open-source project to teach effectively using interactive visualisations</title>
      <dc:creator>Jithin KS</dc:creator>
      <pubDate>Fri, 23 Oct 2020 12:42:44 +0000</pubDate>
      <link>https://dev.to/jithinks/dynamic-learning-an-open-source-tool-to-teach-effectively-using-interactive-visualisations-450n</link>
      <guid>https://dev.to/jithinks/dynamic-learning-an-open-source-tool-to-teach-effectively-using-interactive-visualisations-450n</guid>
      <description>&lt;p&gt;Visualizations are extremely powerful aids in education. If you are familiar with youtube channels like &lt;a href="https://www.youtube.com/watch?v=WUvTyaaNkzM" rel="noopener noreferrer"&gt;3Blue1Brown&lt;/a&gt;, &lt;a href="https://www.youtube.com/watch?v=3gjJDuCAEQQ" rel="noopener noreferrer"&gt;Zach Star&lt;/a&gt;, &lt;a href="https://www.youtube.com/watch?v=tmNXKqeUtJM" rel="noopener noreferrer"&gt;Minute Physics&lt;/a&gt; or &lt;a href="https://www.youtube.com/watch?v=BBQXREXV1Rw" rel="noopener noreferrer"&gt;Physics Videos by Eugene Khutoryansky&lt;/a&gt; (If you are not already, you should probably check them out, they are really good), you can't help but be amazed by how beautifully they explain difficult STEM topics. And this is because they make use of visualizations.&lt;/p&gt;

&lt;p&gt;Now imagine a world in which every teacher could teach as beautifully as they do! That is our end-goal and the project that I'm going to describe is a small step towards that.&lt;/p&gt;

&lt;p&gt;An open-source &lt;a href="https://github.com/dynamic-learning" rel="noopener noreferrer"&gt;project/community&lt;/a&gt; comprising teachers and developers who are genuinely interested in using visualisations to aid their teaching.&lt;/p&gt;

&lt;p&gt;If you are also a person who would love to see this, read on. This project would definitely keep you interested. &lt;/p&gt;

&lt;p&gt;To begin, I asked myself the most important question:&lt;/p&gt;

&lt;h2&gt;
  
  
  How to make a tool that would best help in teaching this way?
&lt;/h2&gt;

&lt;p&gt;For explaining topics in a visual way, teachers can make use of interactive visualizations, visualizations that we can interact with to get real-time responses. The advantage of interactive visualization is it can be used either in live classes or in recorded lessons. Also, students themselves can experiment with them to learn more about the system under study.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fncetra3tymn001buyz0b.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fncetra3tymn001buyz0b.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Currently, the web is one of the best platforms for creating and sharing visualizations. There are plenty of tools available for creating them. For this project, I've chosen to primarily work with an open-source javascript graphics library called &lt;a href="https://p5js.org" rel="noopener noreferrer"&gt;p5.js&lt;/a&gt; because it is very beginner-friendly, but powerful enough for our needs. There is also an &lt;a href="https://editor.p5js.org/jithunni.ks/sketches/npDe92dP_" rel="noopener noreferrer"&gt;online web editor&lt;/a&gt; exclusively made for p5.js where we can very easily code and share visualizations.&lt;/p&gt;

&lt;p&gt;I've been thinking about this problem for quite some time now. I want to help teachers teach using visualizations and this is a list of features that I think will help them adopt this teaching methodology.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provide with a large repository of interactive visualizations from which teachers can easily browse through and find visualizations for a specific topic.&lt;/li&gt;
&lt;li&gt;The ability to easily bring about whatever modifications that teachers want to, in the visualizations to suit their needs.&lt;/li&gt;
&lt;li&gt;If the visualization that teachers need is not present in the said repository, they should be able to request the community of programmers and collaborate with them to create it. In this way, with time, we will have more and more visualizations enriching the repository.&lt;/li&gt;
&lt;li&gt;A facility where they could organize and keep visualizations for a particular topic (maybe in the form of slides) so that they don't need to create these slides every time they present the same topic. Teachers may also share their slides with other teachers.&lt;/li&gt;
&lt;li&gt;A tool where teachers can write/draw theorems/equations/diagrams and show interactive visualizations simultaneously. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Dynamic Learning fits the bill!
&lt;/h2&gt;

&lt;p&gt;Dynamic Learning is an open-source project/platform that is being developed for addressing these requirements. Let's see what it offers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A central repository called &lt;a href="https://dl-next.herokuapp.com/simulations" rel="noopener noreferrer"&gt;simulation collection&lt;/a&gt; where we provide a collection of visualizations/simulations that can be added to &lt;a href="https://dl-next.herokuapp.com/workbook/5f7b2e204f79be001765eda9" rel="noopener noreferrer"&gt;lessons&lt;/a&gt; prepared by teachers. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpaf1rkbco771rqwdtttg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpaf1rkbco771rqwdtttg.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We only have four simulations in the repo now, but an increase in users will inevitably lead to more and more simulations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Teachers will request new simulations to the programmer community and collaborate with them to develop more of them from &lt;a href="https://github.com/dynamic-learning/simulation-ideas" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fulrx6p3ysxgzrhqlxaqq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fulrx6p3ysxgzrhqlxaqq.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The simulations are developed and saved in the &lt;a href="https://editor.p5js.org/jithunni.ks/sketches/npDe92dP_" rel="noopener noreferrer"&gt;online p5 text editor&lt;/a&gt;. The advantage of this is that any time anyone can have access to the code for the visualization.&lt;/li&gt;
&lt;li&gt;Teachers can create a duplicate of the visualization if they want and customize them according to their need if they know how to code (Or they can even get the help of the programmer community for making this change).&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dl-next.herokuapp.com/workbook/5f7b2e204f79be001765eda9" rel="noopener noreferrer"&gt;The workbook creator&lt;/a&gt; can be used to organize visualizations into slides. These slides can be saved and shared with the other teachers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg6sh6xa0tcac40ftaxdt.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg6sh6xa0tcac40ftaxdt.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The workbook creator also has a draw mode using which they can draw, write and add annotations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdkb17i0ig8kcvdriinu4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdkb17i0ig8kcvdriinu4.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Teachers can create accounts and save, organize, share the lessons that they create.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The project is under active development and we need your support to improve and make it better.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can you contribute?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduce the project to someone you know who is interested in teaching using interactive visualizations or who loves to code interactive visualizations.&lt;/li&gt;
&lt;li&gt;Use Dynamic Learning in your lessons.&lt;/li&gt;
&lt;li&gt;Suggest new STEM visualizations by creating new issues &lt;a href="https://github.com/dynamic-learning/simulation-ideas/issues" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Develop new visualizations, save them in p5 online text editor and share the link, we will add them to the simulations repo.&lt;/li&gt;
&lt;li&gt;Use the application and report bugs here - &lt;a href="https://github.com/dynamic-learning/next-client/issues" rel="noopener noreferrer"&gt;front end&lt;/a&gt;, &lt;a href="https://github.com/dynamic-learning/graphql-server/issues" rel="noopener noreferrer"&gt;back end&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Suggest new features in the application.&lt;/li&gt;
&lt;li&gt;Help develop new features.&lt;/li&gt;
&lt;li&gt;Improve the code quality and add test cases in the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A lot of work has been put into making it this far. Thanks to all the contributors who helped. Thanks to &lt;a href="https://processingfoundation.org/" rel="noopener noreferrer"&gt;Processing Foundation&lt;/a&gt; for developing amazing tools like p5.js and p5.js web editor which inspired me to start the project in the first place. Hoping to find more like-minded people willing to contribute.&lt;/p&gt;

&lt;p&gt;If you are interested in contributing. Do leave a comment or contact us at &lt;a href="mailto:developers@dynamiclearning.io"&gt;developers@dynamiclearning.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PS - I've used the terminologies &lt;code&gt;interactive visualization&lt;/code&gt; and &lt;code&gt;simulation&lt;/code&gt; interchangeably. They both refer to the same thing at least in the context of this project.&lt;/p&gt;

&lt;p&gt;Some useful links-&lt;br&gt;
&lt;a href="https://dl-next.herokuapp.com/" rel="noopener noreferrer"&gt;Webapp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dl-next.herokuapp.com/workbook/5f7b2e204f79be001765eda9" rel="noopener noreferrer"&gt;Sample workbook&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dl-next.herokuapp.com/about" rel="noopener noreferrer"&gt;About the project&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/dynamic-learning" rel="noopener noreferrer"&gt;Project organization&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/dynamic-learning/next-client" rel="noopener noreferrer"&gt;Front end source code (NextJS, React)&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/dynamic-learning/graphql-server" rel="noopener noreferrer"&gt;Back end source code (NodeJS, GraphQL)&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/dynamic-learning/simulation-ideas" rel="noopener noreferrer"&gt;Simulation ideas&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/processing-foundation/improving-science-and-math-education-using-p5-js-d434beea465c" rel="noopener noreferrer"&gt;GSoC 2018 article&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/processing-foundation/visualizing-stem-education-with-dynamic-learning-4106748c6fcd" rel="noopener noreferrer"&gt;GSoC 2019 article&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dl-next.herokuapp.com/simulations" rel="noopener noreferrer"&gt;Simulation Repo&lt;/a&gt;&lt;/p&gt;

</description>
      <category>education</category>
      <category>visualization</category>
      <category>teaching</category>
      <category>coding</category>
    </item>
    <item>
      <title>Trajectory lab - fun project in p5.js</title>
      <dc:creator>Jithin KS</dc:creator>
      <pubDate>Sat, 20 Jun 2020 10:46:54 +0000</pubDate>
      <link>https://dev.to/jithinks/trajectory-lab-fun-project-in-p5-js-3n99</link>
      <guid>https://dev.to/jithinks/trajectory-lab-fun-project-in-p5-js-3n99</guid>
      <description>&lt;p&gt;I created an interactive visualization in p5.js. It visualizes the trajectory followed by a particle in gravitational field.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://trajectory-lab.netlify.app/"&gt;See the visualization&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can add new gravitational source by clicking the Add source button in the bottom. A source can be deleted by selecting it and pressing the delete button.&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="https://github.com/JithinKS97/trajectory-lab"&gt;source code&lt;/a&gt; for the &lt;br&gt;
project.&lt;/p&gt;

&lt;p&gt;If you like it, please leave a star in github :) &lt;/p&gt;

</description>
      <category>visualization</category>
      <category>javascript</category>
      <category>p5</category>
    </item>
    <item>
      <title>Writing (clean) React code</title>
      <dc:creator>Jithin KS</dc:creator>
      <pubDate>Wed, 11 Mar 2020 06:22:27 +0000</pubDate>
      <link>https://dev.to/jithinks/writing-clean-react-code-2mcm</link>
      <guid>https://dev.to/jithinks/writing-clean-react-code-2mcm</guid>
      <description>&lt;h3&gt;
  
  
  Building simple software
&lt;/h3&gt;

&lt;p&gt;We generally think that building complex software is hard. But the hardest thing is building complex software in a way that is as simple as possible. &lt;/p&gt;

&lt;p&gt;Even a simple software can turn into a complicated mess if we don't put a conscious effort into keeping it simple.&lt;/p&gt;

&lt;p&gt;One of the main metrics of simplicity in a piece of software is how easily an outside developer can understand the codebase and work on top of it to extend and improve it.&lt;/p&gt;

&lt;p&gt;In this post, I'm going to explain some of the things that I've learned in the past couple of months about writing simple and clean React code.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Make your React component as short as possible
&lt;/h3&gt;

&lt;p&gt;Compared to the time taken to write code, developers spend almost 10x time to read and understand it. Our goal should be to make this process as effortless as possible for them. As the size of the code increases, the readability of the code drops drastically.&lt;/p&gt;

&lt;p&gt;If you do not keep a check on the size of the React component, it can quickly grow beyond your control. If the component is really large, the person who wrote it might be familiar with all of its parts and understand its working, but it will never be easy for another developer to understand it. Components with 500 or 1000 lines of code will be a nightmare for an outside developer. &lt;/p&gt;

&lt;p&gt;Always see if you can refactor the code into separate files. Break down your component into appropriate sub components. Put helper functions used within the component into separate JS files and import them. This helps improve reusability as a good side effect.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Components which are at the same level of abstraction should be together
&lt;/h3&gt;

&lt;p&gt;If you're familiar with Clean Code by the infamous Uncle Bob, you might be familiar with this concept in terms of functions. Functions that are at the same level of abstraction should be present together. This makes the code easy to read. The same applies for components. Components that are at the same level of abstraction should occur together.&lt;/p&gt;

&lt;p&gt;Case 1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;TopMenu&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;TextEditor&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;RightMenu&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Case 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleFilePress&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;File&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleSavePress&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Save&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Editor&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;RightMenu&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first piece of code immediately gives the reader a high level idea about the text editor app. But the second piece of code is not as obvious as the first.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Reduce the number of props to as minimum as possible
&lt;/h3&gt;

&lt;p&gt;In the book clean code, it is advised that no. of parameters of a function should be as minimum as possible. Why? Because as the number of parameters increases, what the function does will become less and less obvious(Props to a React component can be considered to be its parameters)&lt;/p&gt;

&lt;p&gt;For example, consider the code&lt;/p&gt;

&lt;p&gt;Case 1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Table&lt;/span&gt; 
  &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;scrollable&lt;/span&gt;
  &lt;span class="nx"&gt;resizable&lt;/span&gt;
  &lt;span class="nx"&gt;cellColor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;grey&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="nx"&gt;headerColor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;black&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="nx"&gt;font&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Roboto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Case 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;scrollable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;resizable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;cellColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;grey&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;headerColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;black&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Roboto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Table&lt;/span&gt;
    &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second code snippet looks more neat and understandable when compared to the first because when a developer looks at the component, in his mind, a mental picture is immediately formed, that the Table component has three high-level props which are data, style, and config. Then if he wants, he can dig deeper into any of them.&lt;/p&gt;

&lt;p&gt;In the first code snippet, the developer is bombarded with a lot of information immediately and it is really easy for him to get lost here.&lt;/p&gt;

&lt;p&gt;If needed, you should abstract the props as done in creating the config object. It is really easy to add more prop to the component every time you need to add one. But it takes some care and attention to stop, think and refactor to make the code look better.&lt;/p&gt;

&lt;p&gt;Let me give you another example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Circle&lt;/span&gt;
 &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// center = {x,y}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Circle&lt;/span&gt;
 &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I've abstracted the x and y into a center object which makes the code more neat and clean.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Abstract application-specific API calls using Promises
&lt;/h3&gt;

&lt;p&gt;Rather than writing the API calls directly in the component. Abstract the fetch calls into functions.&lt;/p&gt;

&lt;p&gt;Below is the code for rendering a list of comments.&lt;/p&gt;

&lt;p&gt;Case 1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CommentList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;postId&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;commentList&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCommentList&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;postId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;commentList&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setCommentList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;commentList&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;  
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Comment&lt;/span&gt;
           &lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
           &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;))}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Case 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CommentList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;postId&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;commentList&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCommentList&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;getCommentList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;commentList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;setCommentList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;commentList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;  
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Comment&lt;/span&gt;
           &lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
           &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;))}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getCommentList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;postId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;commentList&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;commentList&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In case 2, the React component for rendering comments in a post looks way cleaner when the details of the fetch call are taken out and abstracted into a new function.&lt;/p&gt;

&lt;p&gt;To get your code even more organized, you can put all these application-specific API calls into a separate file that will reduce the clutter in the react component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Rather than jumping in without a second thought and writing code, spend sufficient time in designing the components, their responsibilities, the hierarchy between them, props, state, etc. It will save a lot of time and effort for you as well as the other developers in your team.&lt;/p&gt;

&lt;p&gt;So keep it short, sweet and simple and you should be okay :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PS: Please feel free to add points that are not covered here in the comments&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Understanding the Universe through Code: Spiral galaxies</title>
      <dc:creator>Jithin KS</dc:creator>
      <pubDate>Fri, 06 Mar 2020 03:04:48 +0000</pubDate>
      <link>https://dev.to/jithinks/understanding-the-universe-through-code-dg8</link>
      <guid>https://dev.to/jithinks/understanding-the-universe-through-code-dg8</guid>
      <description>&lt;h3&gt;
  
  
  Mathematical nature of our Universe
&lt;/h3&gt;

&lt;p&gt;The Universe, from the tiniest to the largest scale that we have so far been capable of exploring, is mathematical in nature; and this has always fascinated me! It is because we could understand and exploit this, that we were able to develop technologies that would’ve been perceived to be nothing less than magic by our ancestors if they were here to see them. At present, using technology, we can communicate with our loved ones even on the other side of the globe at any time simply because our Universe obeys laws of quantum mechanics (We use transistors in our devices which were built by making use of laws of quantum mechanics) and we were lucky enough to understand the laws and use it to our advantage.&lt;/p&gt;

&lt;p&gt;This means that if we are good at Mathematics, we can learn a lot about our Universe. Scientific geniuses who have come before us like Newton and Einstein made use of Mathematics to gain a very deep understanding of our Universe. But I think we are a bit luckier than people who lived before us because we are living in the age of computers. Computers help us do mathematics and calculations more easily and quickly which means we have an opportunity to understand the Universe better now.&lt;/p&gt;

&lt;h3&gt;
  
  
  About this series of blog posts
&lt;/h3&gt;

&lt;p&gt;In this blog series, I'm going to make an attempt to take up some interesting observations in the Universe and make use of the power of simple math and coding to gain more insights into them using visualizations.&lt;/p&gt;

&lt;p&gt;I'll be using a Javascript library called &lt;a href="http://p5js.org/"&gt;p5.js&lt;/a&gt; which is one of the easiest libraries to create visualizations on the web. If you want to get familiarized with p5, there is an amazing Youtube channel called &lt;a href="https://www.youtube.com/watch?v=8j0UDiN7my4&amp;amp;list=PLglp04UYZK_PrN6xWo_nJ-8kzyXDyFUwi"&gt;coding train&lt;/a&gt; which will help you and you can also make use of their &lt;a href="https://p5js.org/reference/"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'll be explaining a topic through a sequence of 2 blog posts. In the first, I'll illustrate the idea using visualizations and in the second, I'll explain in detail how those visualizations are created.&lt;/p&gt;

&lt;h3&gt;
  
  
  Spiral arms of galaxies
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yb-34jWk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.spacetelescope.org/archives/images/thumb700x/opo0501a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yb-34jWk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.spacetelescope.org/archives/images/thumb700x/opo0501a.jpg" alt="Spiral galaxy" width="700" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There won't be anybody who is not awestruck by the beauty of spiral galaxies. They are one of the most beautiful structures in the Universe that we have been able to observe. Today we are going to address the question of how galaxies get their beautiful spiral shape with the help of some simple simulations created using basic math and coding.&lt;/p&gt;

&lt;p&gt;Unfortunately, even now, scientists don't fully understand how spiral galaxies get their shape. But some interesting theories have been developed to explain this out of which one of the most widely accepted is the &lt;a href="https://en.wikipedia.org/wiki/Density_wave_theory"&gt;Density wave theory&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;According to this theory, the spiral arms of galaxies are the places where the density of the stars is relatively higher which is caused by gravitational effects within the galaxy. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T3mNG4p1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://hedberg.ccnysites.cuny.edu/img454/galaxies/ellipses-rotated.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T3mNG4p1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://hedberg.ccnysites.cuny.edu/img454/galaxies/ellipses-rotated.jpg" alt="Density wave theory" width="506" height="299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Spiral arms can be modeled by using elliptical orbits that are tilted slightly as their radii grow as shown in the figure above.&lt;/p&gt;

&lt;p&gt;I'm going to illustrate this idea using an app called &lt;a href="https://www.dynamiclearning.io/about"&gt;Dynamic learning&lt;/a&gt;. Dynamic learning is an open-source project/platform which aims at improving Science and Math education with the use of interactive visualizations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Open the &lt;a href="https://www.dynamiclearning.io/workbookeditor/WFvSNq7YqQA4tX2xH"&gt;Lesson in Dynamic learning&lt;/a&gt; ( please view in desktop)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sdw43RZz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/JithinKS97/miniature-happiness/master/dl-preview.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sdw43RZz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/JithinKS97/miniature-happiness/master/dl-preview.png" alt="Preview" width="880" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you got a basic idea of density wave theory and how it leads to the formation of spiral arms of galaxies.&lt;/p&gt;

&lt;p&gt;In the next post, I'll get into the details of creating the visualizations itself !!!&lt;/p&gt;

</description>
      <category>visualization</category>
      <category>javascript</category>
      <category>coding</category>
      <category>math</category>
    </item>
  </channel>
</rss>
