<?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: Muhamad Amir Azmi</title>
    <description>The latest articles on DEV Community by Muhamad Amir Azmi (@amirazmi).</description>
    <link>https://dev.to/amirazmi</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%2F517835%2F8817d31e-f048-4cf2-b7a8-799d42b51395.png</url>
      <title>DEV Community: Muhamad Amir Azmi</title>
      <link>https://dev.to/amirazmi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amirazmi"/>
    <language>en</language>
    <item>
      <title>React vs Vue - Local Component State</title>
      <dc:creator>Muhamad Amir Azmi</dc:creator>
      <pubDate>Mon, 09 Aug 2021 07:59:15 +0000</pubDate>
      <link>https://dev.to/amirazmi/react-vs-vue-local-component-state-56cj</link>
      <guid>https://dev.to/amirazmi/react-vs-vue-local-component-state-56cj</guid>
      <description>&lt;p&gt;React and Vue are some of the most popular front end frameworks that makes the web application becomes Single Page Application (SPA). Those frameworks using components approach for building UI for web application. So, it is necessary to have some kind of temporary data store for each component that can store any value and update the UI and content based on the value stored.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Both Framework Store Temporary Data
&lt;/h2&gt;

&lt;p&gt;Both in React and Vue have their own way to store local component data state but the concept pretty much the same which is to store temporary data for in the component.&lt;/p&gt;

&lt;h3&gt;
  
  
  React
&lt;/h3&gt;

&lt;p&gt;In React, they have 2 ways to write a component which are the Class Based component and Functional Based component. The Function Based Component becomes more popular these days after the arrival of the React Hooks including the &lt;code&gt;useState()&lt;/code&gt; hooks.&lt;/p&gt;

&lt;p&gt;First, let see how to store temporary data in Class Based component.&lt;/p&gt;

&lt;h4&gt;
  
  
  Class Based Component
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c1"&gt;// This is where the temp data stored&lt;/span&gt;
  &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;componentDidMount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// This is how to save data into the state&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Please insert your input&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="nx"&gt;render&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* This is how to use the state */&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The temporary local data for the component will be store in the state object inside the class. Then, the use of 'this' keyword is important when referencing the local state since the state is in the class object.&lt;/p&gt;

&lt;p&gt;To store any data into the state, the &lt;code&gt;this.setState()&lt;/code&gt; method need to be used as the code shown above.&lt;/p&gt;

&lt;h4&gt;
  
  
  Functional Based Component
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&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="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&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="c1"&gt;// This is where the temp data stored&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;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setInput&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="dl"&gt;''&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="c1"&gt;// This is how to save data into the state&lt;/span&gt;
    &lt;span class="nx"&gt;setInput&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Please insert your input&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="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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* This is how to use the state */&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;The temporary data for the functional component is being store in the &lt;code&gt;useState()&lt;/code&gt; hooks. The &lt;code&gt;useState()&lt;/code&gt; hooks can be used multiple times according on how many state we want in the component.&lt;/p&gt;

&lt;p&gt;To use the state, we can directly call the variable that has being use in the &lt;code&gt;useState()&lt;/code&gt; on top of our component. To update and save a new data to the state, use the &lt;code&gt;setInput&lt;/code&gt; for example, to update the input state in the component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vue
&lt;/h3&gt;

&lt;p&gt;In Vue, the way the store temporary data quite different (just the codes are different but the concept still the same). In Vue, we are using the &lt;code&gt;data(){}&lt;/code&gt; function in the component object. Let's look how to use &lt;code&gt;data()&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- This is how to use the state --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// This is where the temp data stored&lt;/span&gt;
  &lt;span class="nx"&gt;data&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="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&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="nx"&gt;created&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="c1"&gt;// This is how to save data into the state&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Please insert your input&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="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By local data will be return in as object in the &lt;code&gt;data()&lt;/code&gt; function inside the component object. Then, to use the state, same as the React functional component, directly call using the state variable.&lt;/p&gt;

&lt;p&gt;However, to update the state, the &lt;code&gt;this&lt;/code&gt; keyword need to be used to access the state in the component object. Simply by reassign the state using &lt;code&gt;this.[state]&lt;/code&gt;, will automatically update the state into new one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Both frameworks have their own way how to store, update and manage the local component state. I believe there are more detailed explanation about state but these are all what I understand through my experience and my self study.&lt;/p&gt;

&lt;p&gt;If there are anything missing about local component state for these frameworks, feel free to share in the comment below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;React Class Component State - &lt;a href="https://reactjs.org/docs/faq-state.html"&gt;https://reactjs.org/docs/faq-state.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;React useState - &lt;a href="https://reactjs.org/docs/hooks-state.html"&gt;https://reactjs.org/docs/hooks-state.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Vue Data Function - &lt;a href="https://vuejs.org/v2/guide/components.html"&gt;https://vuejs.org/v2/guide/components.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>react</category>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>My Experience Converting Django Template to ReactJS</title>
      <dc:creator>Muhamad Amir Azmi</dc:creator>
      <pubDate>Tue, 03 Aug 2021 09:41:48 +0000</pubDate>
      <link>https://dev.to/amirazmi/my-experience-converting-django-template-to-reactjs-396k</link>
      <guid>https://dev.to/amirazmi/my-experience-converting-django-template-to-reactjs-396k</guid>
      <description>&lt;p&gt;During my time at MEGASAP, July 2021, they have given me a task to convert the existing Django templates for their attendance tracking dashboard for employee and employer to React due to scalability and better UX in the future. However, they do not want to buy or have another server just to host React front end, so I need to include React directly in Django as an app using "django-admin startapp" command. &lt;/p&gt;

&lt;p&gt;Since the React embedded in Django application, I cannot use the common "npx create-react-app" way because the common way will generate the files that might not be accessible in Django statics. So, I need to combine certain library and using Webpack to compile all the Javascript file into one main file (main.js) and directly put the "main.js" into Django static folder.&lt;br&gt;
To enable developing the front end using React, these are the front end tools I need to get set up:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Webpack ⇒ setting up the Javascript, SASS, CSS, Images and others file compilation into a single "main.js" file and output the file into Django static folder.&lt;/li&gt;
&lt;li&gt;Babel ⇒ to enable the latest Javascript syntax being convert into older version so that old browser can access the content.&lt;/li&gt;
&lt;li&gt;React, React Router, React Hooks ⇒ the typical React library for developing the React application, together with front end routing system and global state management using Context API.&lt;/li&gt;
&lt;li&gt;Others React Library ⇒ React i18n for internationalization or language translation, React Helmet for dynamically changing the  or any  tag based on any condition given.&lt;/li&gt;
&lt;li&gt;Other Library ⇒ axios for fetching the data through API from Django Rest Framework.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As for backend, which is the Django, the API need to be built since all the communication for Django to React through REST API. So, the Django Rest Framework has been used.&lt;/p&gt;

&lt;p&gt;Working at MEGASAP for a short while really give me some new experience on how to work with React and Django, and how to start a React application without any boilerplate.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>oop</category>
    </item>
    <item>
      <title>Application Requirement</title>
      <dc:creator>Muhamad Amir Azmi</dc:creator>
      <pubDate>Fri, 25 Jun 2021 13:47:40 +0000</pubDate>
      <link>https://dev.to/amirazmi/application-requirement-2ggf</link>
      <guid>https://dev.to/amirazmi/application-requirement-2ggf</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The requirements should not to be too excessive. For now, make sure to take the absolute minimum set of requirements. Not the things that "nice to have" and optional. Just the minimum requirements for the minimum viable product.&lt;/p&gt;

&lt;p&gt;It's okay to not have a complete requirements in the beginning. The requirements can always be changed as the project development grows.&lt;/p&gt;

&lt;p&gt;Take note that, the requirements should not contain anything related with classes, object orientation yet for this stage.&lt;/p&gt;

&lt;p&gt;To show how the system requirements works, let's have an imaginary application idea that we want to build.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Application ⇒ Restaurant Reservation and Food Delivery Application&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  FURPS+ Requirements
&lt;/h2&gt;

&lt;p&gt;One of the most commonly used model is acronym FURPS+. The FURPS+ requirement can fulfilled the functional and non functional requirements of an application.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Functionality ⇒ Capability, Reusability, Security (main features of an app)&lt;/li&gt;
&lt;li&gt;Usability ⇒ Human Factors, Aesthetics, Consistency, Documentation (affects the user)&lt;/li&gt;
&lt;li&gt;Reliability ⇒ Availability, Failure Rate &amp;amp; Duration, Predictability&lt;/li&gt;
&lt;li&gt;Performance ⇒ Speed, Efficiency, Resource Consumption, Scalability&lt;/li&gt;
&lt;li&gt;Supportability ⇒ Testability, Extensibility, Serviceability, Configurability&lt;/li&gt;
&lt;li&gt;Design (the system design)&lt;/li&gt;
&lt;li&gt;Implementation (how to implement the system)&lt;/li&gt;
&lt;li&gt;Interface (the interface of internal system)&lt;/li&gt;
&lt;li&gt;Physical (hardware and physical constraints)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Functional Requirements
&lt;/h2&gt;

&lt;p&gt;The functional requirements should describes "what the application must do".&lt;br&gt;
The requirements should start with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The system &lt;strong&gt;must do...&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The application &lt;strong&gt;must do...&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Examples:
&lt;/h6&gt;

&lt;ol&gt;
&lt;li&gt;Allow customers to reserve a table in the restaurant before they arrived.&lt;/li&gt;
&lt;li&gt;Allow customers to go through the menu list&lt;/li&gt;
&lt;li&gt;Show the date availability for reservation&lt;/li&gt;
&lt;li&gt;Show the menu availability and prices&lt;/li&gt;
&lt;li&gt;Have the menu category&lt;/li&gt;
&lt;li&gt;Have options for dine in, take away or delivery&lt;/li&gt;
&lt;li&gt;Allow customers to have their account in the system&lt;/li&gt;
&lt;li&gt;Allow customers to save any menu they want&lt;/li&gt;
&lt;li&gt;Allow customers to view the detail and progress of food delivery&lt;/li&gt;
&lt;li&gt;Allow customers to view the reservation details&lt;/li&gt;
&lt;li&gt;Allow customers to change the reservation&lt;/li&gt;
&lt;li&gt;Allow customers to cancel the reservation&lt;/li&gt;
&lt;li&gt;Have contact section&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Non-Functional Requirements
&lt;/h2&gt;

&lt;p&gt;The non functional requirements should describes, maintainability, reliability, usability and availability.&lt;br&gt;
So, each non functional requirements should start with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The application &lt;strong&gt;should be...&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Examples:
&lt;/h6&gt;

&lt;ol&gt;
&lt;li&gt;Accessible from mobile and desktop&lt;/li&gt;
&lt;li&gt;User friendly and responsive&lt;/li&gt;
&lt;li&gt;Available during peak hours (lunch and dinner)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;These requirements might not be the final one and can always be changed in the future. But at least, start writing some requirements before doing anything so that you know what you want to develop later on.&lt;/p&gt;

&lt;p&gt;The next steps will be creating Use Cases and User Stories to refine the requirements a little bit more before start designing and developing anything.&lt;/p&gt;

&lt;p&gt;Anyway, hope this article give some useful information to you. I'm still learning and will continue creating article here so that I really understand what I'm currently learning.&lt;/p&gt;

&lt;p&gt;If something not right in this article, please comment below so that I learn some new stuff to improve my skill.&lt;/p&gt;

&lt;p&gt;Thank you for reading my article.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JS vs Python - Variables</title>
      <dc:creator>Muhamad Amir Azmi</dc:creator>
      <pubDate>Sat, 05 Jun 2021 05:52:19 +0000</pubDate>
      <link>https://dev.to/amirazmi/js-vs-python-variables-1npc</link>
      <guid>https://dev.to/amirazmi/js-vs-python-variables-1npc</guid>
      <description>&lt;p&gt;I have been doing web development for a year now and my main language is Javascript. But recently I got a new job offers that plays around Python and Django for their back end. So, I write this article as a note for me to remember the basics of Python and some comparison with my main language, Javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;Python has very simple way to define a variable compared to JS. In Javascript, to define a variable, a keyword need to include in front of variable name to make sure a variable is changeable or not.&lt;/p&gt;

&lt;h3&gt;
  
  
  Primitive Data Type
&lt;/h3&gt;

&lt;p&gt;The primitive data type for both language pretty much similar:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Int&lt;/li&gt;
&lt;li&gt;Float&lt;/li&gt;
&lt;li&gt;Boolean&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Javascript
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Variables&lt;/span&gt;

&lt;span class="c1"&gt;// const --&amp;gt; cannot change the value of a variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;honda&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// string&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// number/integer&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;20.89&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// float&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// boolean&lt;/span&gt;

&lt;span class="c1"&gt;// let --&amp;gt; can change and update later&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;car2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;toyota&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// string&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;number2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;43&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// number/integer&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;price2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;23.89&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// float&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isValid2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// boolean&lt;/span&gt;

&lt;span class="c1"&gt;// return an error because cannot reassign &lt;/span&gt;
&lt;span class="c1"&gt;// to const variable&lt;/span&gt;
&lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bmw&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// does not return an error because let &lt;/span&gt;
&lt;span class="c1"&gt;// can be reassigned&lt;/span&gt;
&lt;span class="nx"&gt;price2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;18.38

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Python
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Variables
&lt;/span&gt;
&lt;span class="c1"&gt;# python does not have assignment keyword 
# and variables can be reassigned
&lt;/span&gt;&lt;span class="n"&gt;van&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'volkswagen'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;# string
&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;# int
&lt;/span&gt;&lt;span class="n"&gt;mileage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;9823.08&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# float
&lt;/span&gt;&lt;span class="n"&gt;is_good&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;# bool 
# (the bool in Python must be capitalize, True/False)
&lt;/span&gt;
&lt;span class="c1"&gt;# does not return an error because 
# all primitive data type variable can be reassigned
&lt;/span&gt;&lt;span class="n"&gt;van&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'car'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Multiple Assignment
&lt;/h3&gt;

&lt;p&gt;Python and Javascript can do the multiple assignments but they have different approach. The multiple assignments very useful for one line assignment. The code might seems more clean. Usually I'll do multiple assignments for global or top line in the file.&lt;/p&gt;

&lt;h4&gt;
  
  
  Javascript
&lt;/h4&gt;

&lt;p&gt;For Javascript, the variable name and value must be couple together and each variable separated with ', '.&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="c1"&gt;// Multiple assignment&lt;/span&gt;

&lt;span class="c1"&gt;// const --&amp;gt; cannot change after initial assignment&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;van&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;toyota&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;kilometers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;238.38&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isBroken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

&lt;span class="c1"&gt;// let --&amp;gt; can change after initial assignment&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;honda&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;seats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;2384.23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isNew&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

&lt;span class="c1"&gt;// Reassignment for let variable&lt;/span&gt;
&lt;span class="nx"&gt;seats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="c1"&gt;// not throw an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Python
&lt;/h4&gt;

&lt;p&gt;For python, all variables name are group together on the left side and the variables value are group on the right side.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Multiple assignment
&lt;/span&gt;
&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seats&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;is_new&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'bmw'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3843.49&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# The line above can be presented as below:
&lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'bmw'&lt;/span&gt;
&lt;span class="n"&gt;seats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="n"&gt;mileage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3843.39&lt;/span&gt;
&lt;span class="n"&gt;is_new&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Type Conversion or Casting
&lt;/h3&gt;

&lt;p&gt;Both language has their own way to convert primitive data type from one to another. Typically type conversion used to convert int/number to string, string to number/int or float and float to string.&lt;/p&gt;

&lt;p&gt;To convert the string to int/number, the string must be a string of number first.&lt;/p&gt;

&lt;h4&gt;
  
  
  Javascript
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Type Conversions&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;seats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;  &lt;span class="c1"&gt;// string of number&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2.5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;   &lt;span class="c1"&gt;// string of float number&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;28.7&lt;/span&gt; &lt;span class="c1"&gt;// float number&lt;/span&gt;

&lt;span class="c1"&gt;// return 4 in number/int data type&lt;/span&gt;
&lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seats&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;seats&lt;/span&gt;

&lt;span class="c1"&gt;// return 2.5 in float&lt;/span&gt;
&lt;span class="nb"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;cc&lt;/span&gt;

&lt;span class="c1"&gt;// The '+' symbol will convert the &lt;/span&gt;
&lt;span class="c1"&gt;// string into number or float based on the string value.&lt;/span&gt;

&lt;span class="c1"&gt;// return '28.7' in string&lt;/span&gt;
&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// return '28.700' in string with 3 decimal places&lt;/span&gt;
&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// The toFixed(digits) method can be used &lt;/span&gt;
&lt;span class="c1"&gt;// with the float data type only. &lt;/span&gt;
&lt;span class="c1"&gt;// So, if the value is in string data type, &lt;/span&gt;
&lt;span class="c1"&gt;// convert to parseFloat first and &lt;/span&gt;
&lt;span class="c1"&gt;// then using toFixed() to add decimal places.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Python
&lt;/h4&gt;

&lt;p&gt;As for python, the term for type conversion is casting. Here are some example for casting in Python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Casting
&lt;/span&gt;
&lt;span class="n"&gt;seats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'4'&lt;/span&gt;  &lt;span class="c1"&gt;# string of number
&lt;/span&gt;&lt;span class="n"&gt;cc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'2.5'&lt;/span&gt;   &lt;span class="c1"&gt;# string of float number
&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;28.7&lt;/span&gt; &lt;span class="c1"&gt;# float number
&lt;/span&gt;
&lt;span class="c1"&gt;# return int 4
&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seats&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# return float 2.5
&lt;/span&gt;&lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# return string '28.7'
&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Check Variable Type
&lt;/h3&gt;

&lt;p&gt;Checking the type of variable quite crucial when doing the conditionals. Some times, we want to execute certain code if the variable obtained from the input is in certain type.&lt;/p&gt;

&lt;h4&gt;
  
  
  Javascript
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Variable Type Checking&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;shoe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vans&lt;/span&gt;&lt;span class="dl"&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="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;shoe&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// return type string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Python
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Variable Type Checking
&lt;/span&gt;
&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="n"&gt;seats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seats&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# return int
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;These are some of examples and differences for variables in Python and Javascript. I know there have so many things related to basic variables for Python and Javascript, but here what I have been using and learnt so far.&lt;/p&gt;

&lt;p&gt;In future, I'll regularly update the differences between both language so that, I understand more on both language and level up my skills even further.&lt;/p&gt;

&lt;p&gt;Thank you for reading my article, this is my first article and I really appreciate if this article helps.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
