<?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: Pramila Dalavai</title>
    <description>The latest articles on DEV Community by Pramila Dalavai (@pramila_15).</description>
    <link>https://dev.to/pramila_15</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%2F353503%2Fc32e2293-1124-4cb5-bf74-13c19141e162.jpeg</url>
      <title>DEV Community: Pramila Dalavai</title>
      <link>https://dev.to/pramila_15</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pramila_15"/>
    <language>en</language>
    <item>
      <title>Functional Programming - Pure Functions</title>
      <dc:creator>Pramila Dalavai</dc:creator>
      <pubDate>Tue, 08 Sep 2020 21:47:42 +0000</pubDate>
      <link>https://dev.to/pramila_15/functional-programming-pure-functions-4d57</link>
      <guid>https://dev.to/pramila_15/functional-programming-pure-functions-4d57</guid>
      <description>&lt;p&gt;Today we are gonna talk about pure functions, which is one of the core concepts of functional programming.No doubt pure functions make your life easier without affecting your application's state.&lt;br&gt;
Rules for pure functions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The function should take in at least one argument.&lt;/li&gt;
&lt;li&gt;The function should return a value or another function.&lt;/li&gt;
&lt;li&gt;The function should not change or mutate any of its arguments.
Impure functions example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Header(text) {
let h1 = document.createElement('h1');
h1.innerText = text;
document.body.appendChild(h1);
}
Header("Header() caused side effects");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In React, the UI is expressed with pure functions. In the following example, you can see the function doesn't mutate DOM. This function&lt;br&gt;
will create a heading-one element, and it is up to some other part of the application to use that element to change the DOM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Header = (props) =&amp;gt; &amp;lt;h1&amp;gt;{props.title}&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hence pure functions do not cause side effects, set global variables, or change anything about the application state.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>functional</category>
    </item>
    <item>
      <title>Functional Programming in Javascript - Imperative and  Declarative</title>
      <dc:creator>Pramila Dalavai</dc:creator>
      <pubDate>Sat, 05 Sep 2020 07:07:29 +0000</pubDate>
      <link>https://dev.to/pramila_15/functional-programming-in-javascript-imperative-vs-declarative-45f3</link>
      <guid>https://dev.to/pramila_15/functional-programming-in-javascript-imperative-vs-declarative-45f3</guid>
      <description>&lt;p&gt;Hello there, in this post I will be talking about the imperative and declarative concepts. Whenever you have attempted to reduce or map the array without your knowledge, you are good to go to be a functional programmer in javascript. React, Flux, and redux all these are functional programming javascript frameworks.&lt;br&gt;
Now talking of Declarative, its when your application is structured in a way that prioritizes describing what should happen over defining how it should happen.&lt;br&gt;
It would be easier if you compare the imperative and declarative examples here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var string = "hi there , I'm a web developer";
var removeSpace = "";
for (var i = 0; i &amp;lt; i.string.length; i++) {
  if (string[i] === " ") removeSpace += "-";
  else removeSpace += string[i]; 
}
console.log(removeSpace);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this example, we loop through every character in the string, replacing spaces as they occur. Just looking at the code, it doesn't say much. Imperative requires lots of comments in order to understand code. Whereas in the declarative program, the syntax itself describes what should happen and the details of how things happen are abstracted way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const string = "Hi there, I'm a web developer ";
const removeSpaces = string.replace(//g,"-");
console.log(removeSpaces);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Isn't this looks more readable and easier to reason about?&lt;br&gt;
Now, let’s consider the task of building a document object model, or DOM. An imperative approach would be concerned with how the DOM is constructed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var headline = document.createElement('h1');
headline.innerText = "Hello World";
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It would be very hard to make changes, add features, or scale 10,000 lines of code where the DOM is constructed imperatively.&lt;br&gt;
Now let’s take a look at how we can construct a DOM declaratively using a React component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { render } = ReactDOM
const Welcome = () =&amp;gt; (
&amp;lt;div id="App"&amp;gt;
//your HTML code 
//your react components
&amp;lt;/div&amp;gt;
)
render(
&amp;lt;App /&amp;gt;,
document.getElementById('home')
)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;React is declarative. Here, the Welcome component describes the DOM that should be rendered. The&lt;br&gt;
render function uses the instructions declared in the component to build the DOM, abstracting away&lt;br&gt;
the details of how the DOM is to be rendered. We can clearly see that we want to render our&lt;br&gt;
Welcome component into the element with the ID of 'target'.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>functional</category>
      <category>react</category>
    </item>
  </channel>
</rss>
