<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by BAVI-BOOP on Medium]]></title>
        <description><![CDATA[Stories by BAVI-BOOP on Medium]]></description>
        <link>https://medium.com/@birceste?source=rss-8176c562caa0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6xIywEmhC0A7LK1f</url>
            <title>Stories by BAVI-BOOP on Medium</title>
            <link>https://medium.com/@birceste?source=rss-8176c562caa0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 01:00:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@birceste/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[15 Frontend Questions Asked In A Real Interview And Explanations]]></title>
            <link>https://medium.com/@birceste/15-frontend-questions-asked-in-a-real-interview-and-explanations-8b3e3ffefe3c?source=rss-8176c562caa0------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b3e3ffefe3c</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[BAVI-BOOP]]></dc:creator>
            <pubDate>Mon, 17 Oct 2022 11:00:30 GMT</pubDate>
            <atom:updated>2022-10-17T11:00:30.128Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello and welcome, today I want to share a whole interview experience with an IT company for a frontend developer position. These were shared by another dev very recently. I wanted to spread it with my extra interpretation. I’ll leave credit at the end of the article so you can go and thank him.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*yi5ZvSz82Wfz_yCyWOh0Hg.jpeg" /></figure><p>The interview took place in 4 rounds.<br>1- Js basics<br>2-JS advanced<br>3-React.js<br>4-Cultural parts and soft skills</p><h3>First Round</h3><p><em>here session one starts</em></p><h4>Q1 Explain map and ForEach and compare them</h4><p>So these are basically array methods and there are points that need to be underlined.</p><ul><li>Map creates and <strong>returns</strong><em> </em>a new array populated with the results of calling a provided function on every element in the calling array.</li></ul><pre>const array1 = [1, 2, 3, 4];<br>const squared = array1.map(x =&gt; x ** 2);</pre><ul><li>If you want to modify the <strong>original</strong> array . Use for each with array parameter.(Array methods take three arguments: element, index, array)</li></ul><pre>const array1 = [1, 2, 3];</pre><pre>array1.forEach((element, index, array) =&gt; array[index] += 1 );</pre><ul><li>We can<strong> chain</strong> map with other array methods like filter, reduce but we can not chain forEach since it doesn’t return anything.</li></ul><pre>const array2 = [1, 2, 3, 4];<br>const squaredAndFiltered = array1.map(x =&gt; x ** 2).filter((mappedItem) =&gt; 8 &lt; mappedItem);</pre><pre>console.log(squaredAndFiltered)</pre><p>Every frontend dev should know ahow to use array methods. You don’t have to memorize but have an understading. Check the full list<a href="https://emojipedia.org/backhand-index-pointing-down/">👇</a><a href="https://www.w3schools.com/jsref/jsref_obj_array.asp">https://www.w3schools.com/jsref/jsref_obj_array.asp</a></p><h4>Q2 What’s the difference between Null vs Undefined</h4><ul><li>Null is an actual value but undefined means variable is declared but not initialized yet.</li><li>Null is the intentional absence of the value. It is one of the primitive values of JavaScript.</li><li>Undefined means the value does not exist in the compiler. It is the global object.</li></ul><pre>//! null == undefined // true</pre><pre>//! null === undefined // false</pre><pre>//! isNaN(2 +  null)      // false</pre><pre>//! isNaN(2 + undefined) // true</pre><pre>//! null ? console.log(&quot;true&quot;) : console.log(&quot;false&quot;) // false</pre><pre>//! undefined ? console.log(&quot;true&quot;) : console.log(&quot;false&quot;) // false</pre><h4>Q3 What is event delegation</h4><p>This term is about events in Javascript such as click or mouse events. Capturing and bubbling allow us to implement one of the most powerful event handling patterns called event delegation. If you don’t know what they mean I strongly recommend you to search</p><p>Event Delegation is basically a pattern to handle events efficiently. Instead of adding an event listener to each and every similar element, we can add an event listener to a parent element and call an event on a particular target using the .target property of the event object.</p><p>Let me write steps for you.</p><ol><li>Use getElementById or another to reach an element in HTML</li><li>Add an event listener to a parent element in document. You can simply assign onClick.</li><li>Catch it with <strong>event.target</strong> and console the results in dev tools.</li></ol><pre>&lt;div id=&quot;buttons&quot;&gt; </pre><pre>&lt;button class=&quot;buttonClass&quot;&gt;Click me&lt;/button&gt;</pre><pre>&lt;button class=&quot;buttonClass&quot;&gt;Click me&lt;/button&gt;</pre><pre>&lt;!-- buttons... --&gt;</pre><pre>&lt;button class=&quot;buttonClass&quot;&gt;Click me&lt;/button&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;script&gt;</pre><pre>document.getElementById(&#39;buttons&#39;) &lt;!-- Step 1 --&gt;</pre><pre>.addEventListener(&#39;click&#39;, event =&gt; { // Step 2</pre><pre>if (event.target.className === &#39;buttonClass&#39;) { </pre><pre>console.log(&#39;Click!&#39;); // Step 3</pre><pre>}</pre><pre>});</pre><pre>&lt;/script&gt;</pre><p>For a longer explanation check 👇</p><p><a href="https://dmitripavlutin.com/javascript-event-delegation/">A Simple Explanation of Event Delegation in JavaScript</a></p><h4>Q4 Flatten the Array</h4><p>You probably will come across with algorithm problems in your interviews. To be prepared you can solve code challenges in websites like codewars, leetcode. Let’s get to the question.</p><p>Let’s say you have an array with nested arrays how would you make flat.</p><pre>let arr = [[1, 2],[3, 4],[5, 6, [7, 8], 9],[10, 11, 12],];</pre><pre>//Expected let arr = [1, 2, 3, 4, 5, 6,7, 8, 9, 10, 11, 12 ];</pre><p>There are a few ways actually for this.</p><p>for one level nested arrays</p><pre>//! let flattened = [].concat(...arr)</pre><p>with built-in</p><pre>//! console.log(arr.flat(2));</pre><p>without built-in</p><pre>function customFlat(ar, depth = 2) {</pre><pre>let result = [];</pre><pre>ar.forEach((ar) =&gt; {</pre><pre>if (Array.isArray(ar) &amp;&amp; depth &gt; 0) {</pre><pre>result.push(...customFlat(ar, depth - 1));</pre><pre>} else result.push(ar);</pre><pre>});</pre><pre>return result;</pre><pre>}</pre><pre>console.log(customFlat(arr));</pre><h4>Q5 Show your projects portfolio</h4><p>In this part, they asked him to show his projects and explain them. Don’t forget that they will not just take a look. They will ask you questions about the projects that you showed or uploaded to your GitHub. So if you are displaying your projects be prepared to explain them.</p><ul><li>Why did you add this part of code ?</li><li>Why did you choose that particular tech stack?</li></ul><h3>Second Round</h3><p><em>here session two starts</em></p><h4>Q6 What is the difference between VAR , LET and , CONST</h4><p>This is a very fundemental question about variables. I am sure you know them but it is necessary to explain them fluently to recruiter.</p><p>I listed 5 basic distinction</p><pre>//? Scope</pre><pre>{var a = &quot;hello&quot;;}</pre><pre> console.log(a);</pre><pre>{ let b = &quot;hello&quot;;}</pre><pre> console.log(b);</pre><pre>//? Declaration</pre><pre>var a = 3;</pre><pre>var a = 3;</pre><pre>const a = 3;</pre><pre>//! const a = 3;</pre><pre>//? initialization</pre><pre>let a = 3;</pre><pre>a = 4;</pre><pre>const a = 3;</pre><pre>a = 4;</pre><pre>//? Assigning without value</pre><pre>var b;</pre><pre>let a;</pre><pre>const c;</pre><pre>//? Hoisting</pre><pre>console.log(a);</pre><pre>var a = 3;</pre><h4>Q7 What will be the output ?</h4><pre>function a() {</pre><pre>for (var i = 0; i &lt; 3; i++) {</pre><pre>setTimeout(() =&gt; {</pre><pre>console.log(i);</pre><pre>}, i * 1000);</pre><pre>}}<br>a();</pre><p>Some you might expected 0, 1 , 2 but because of <strong>var </strong>it works surprisingly (3,3,3).So what is the reason behind it ?</p><p>Var doesn’t have a block scope and it runs afther completion of code since setTimeout .The order is this:</p><p>i =&gt; 1 2 3</p><p>i =&gt; 1 2 3</p><p>i =&gt; 1 2 3</p><p>The answer is If you change it to <strong>let</strong> it works expectedly because it has a complete different scope.</p><pre>//! {i = 0}</pre><pre>//! {i = 1}</pre><pre>//! {i = 2}</pre><p>How can we solve this issue without changing var to let ? We need to use closure</p><pre>for (var i = 0; i &lt; 3; i++) {</pre><pre>function timer(iter) {</pre><pre>setTimeout(() =&gt; {</pre><pre>console.log(iter);</pre><pre>}, iter * 1000);</pre><pre>}</pre><pre>timer(i);</pre><pre>}</pre><p>When we pass the primitive type as the argument to function, then its a pass by value and not the pass by reference. Check this awesome article 👇</p><p><a href="https://www.scaler.com/topics/javascript/pass-by-value-and-pass-by-reference/">https://www.scaler.com/topics/javascript/pass-by-value-and-pass-by-reference/</a></p><h4>Q8 Explain Call, Apply and Bind and compare them</h4><p>First we need to know what <strong>this</strong> keyword mean</p><ul><li>Alone, <strong>this</strong> refers to the global object.</li><li>In a function, <strong>this</strong> refers to the global object.</li><li>In a function, in strict mode, <strong>this</strong> is undefined.</li><li>In an event, <strong>this</strong> refers to the element that received the event.</li><li>Methods like call(), apply(), and bind() can refer <strong>this</strong> to any object.</li><li>They help you replace the value of this inside a function with whatever value you want.</li></ul><ol><li>With the apply() method, you can write a method that can be used on different objects.</li></ol><pre>const person = {<br>  fullName: function() {<br>    return this.firstName + &quot; &quot; + this.lastName;<br>  }<br>}<br><br>const person1 = {<br>  firstName: &quot;Mary&quot;,<br>  lastName: &quot;Doe&quot;<br>}<br><br>// This will return &quot;Mary Doe&quot;:<br>person.fullName.apply(person1);</pre><p>another version of apply:</p><pre>function Car(type, fuelType){<br>	this.type = type;<br>	this.fuelType = fuelType;<br>}<br><br>function setBrand(brand){<br>	Car.apply(this, [&quot;convertible&quot;, &quot;petrol&quot;]); //Syntax with array literal<br>	this.brand = brand;<br>	console.log(`Car details = `, this);<br>}<br><br>function definePrice(price){<br>	Car.apply(this, new Array(&quot;convertible&quot;, &quot;diesel&quot;)); //Syntax with array object construction<br>	this.price = price;<br>	console.log(`Car details = `, this);<br>}<br><br>const newBrand = new setBrand(&#39;Brand1&#39;);<br>const newCarPrice = new definePrice(100000);</pre><p>Note: Call function is almost identical to apply(), except that call() accepts an argument list, while apply() accepts a single array of arguments .</p><p>2. With call(), an object can use a method belonging to another object.</p><pre>const person = {</pre><pre>fullName: function() {</pre><pre>return this.firstName + &quot; &quot; + this.lastName;</pre><pre>}<br>}</pre><pre>const person1 = {</pre><pre>firstName:&quot;John&quot;,</pre><pre>lastName: &quot;Doe&quot;</pre><pre>}</pre><pre>const person2 = {</pre><pre>firstName:&quot;Mary&quot;,</pre><pre>lastName: &quot;Doe&quot;</pre><pre>}</pre><pre>// This will return &quot;John Doe&quot;:</pre><pre>person.fullName.call(person1);</pre><p>If you use call without arguments, JavaScript refers to the global object.</p><p>Also, we can use call for inhteritance in OOP. It was used before ES6. Now we use <strong>extends</strong> keyword</p><pre>this.name = name;</pre><pre>this.price = price;</pre><pre>}</pre><pre>function Food(name, price) {</pre><pre>Product.call(this, name, price);</pre><pre>this.category = &#39;food&#39;;</pre><pre>}</pre><pre>console.log(new Food(&#39;cheese&#39;, 5).name);</pre><p>3. The bind function creates a copy of a function with a new value to the this present inside the calling function.</p><pre>!const module = {</pre><pre>x: 42,</pre><pre>getX: function() {</pre><pre>return this.x;</pre><pre>}</pre><pre>};</pre><pre>const unboundGetX = module.getX;</pre><pre>console.log(unboundGetX()); // The function gets invoked at the global scope</pre><pre>// expected output: undefined</pre><pre>const boundGetX = unboundGetX.bind(module);</pre><pre>console.log(boundGetX());</pre><p>If you are learning React. You are probably familiar with bind. In class components we use bind to help function reach the context of the class</p><pre>class App extends React.Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = {<br>      counter: 1<br>    };<br>   this.handleCode = this.handleCode.bind(this); //bind this function<br>  }<br>  handleCode() {<br>    console.log(&quot;HANDLE CODE THIS = &quot;, this.state);<br>  }<br>  render() {<br>    return &lt;button onClick={this.handleCode}&gt;Click Me&lt;/button&gt;;<br>  }<br>}</pre><p>Check this article the grasp better👇</p><p><a href="https://www.freecodecamp.org/news/understand-call-apply-and-bind-in-javascript-with-examples/">https://www.freecodecamp.org/news/understand-call-apply-and-bind-in-javascript-with-examples/</a></p><h4>Q9 Explain Infinite Currying</h4><p>Currying simply means evaluating functions with multiple arguments and decomposing them into a sequence of functions with a single argument.</p><p>without currying</p><pre>function (a, b){<br>return a + b ;</pre><p>finite currying</p><pre>function add(a) {</pre><pre>return function (b) {</pre><pre>return function () {</pre><pre>return a + b;</pre><pre>};</pre><pre>};</pre><pre>}</pre><pre>console.log(add(5)(2)());</pre><p>infinite currying</p><pre>function add(a) {</pre><pre>return function (b) {</pre><pre>if (b) return add(a + b);</pre><pre>return a;</pre><pre>};</pre><pre>}</pre><pre>console.log(add(5)(2)(3)(6)(7)());</pre><p>This article is great for learning currying</p><p><a href="https://blog.logrocket.com/understanding-javascript-currying/#:~:text=What%20is%20currying%20in%20JavaScript,functions%20with%20a%20single%20argument.">https://blog.logrocket.com/understanding-javascript-currying/#:~:text=What%20is%20currying%20in%20JavaScript,functions%20with%20a%20single%20argument.</a></p><h4>Q10 Write polyfill for the compose method which will evaluate these three functions</h4><pre>function addFive(a) {</pre><pre>return a + 5;</pre><pre>}</pre><pre>function substractTwo(a) {</pre><pre>return a - 2;</pre><pre>}</pre><pre>function multiplyFOur(a) {</pre><pre>return a * 4;</pre><pre>}</pre><p>So we will write a function that takes three function arguments and returns a function that takes a initial value</p><pre>const evaluate = compose(addFive, substractTwo, multiplyFOur);<br>evaluate(4);</pre><p>compose works right to left</p><p>The answer is</p><pre>const compose = (...functions) =&gt; {</pre><pre>return (args) =&gt; {</pre><pre>return functions.reduceRight((arg, fn) =&gt; fn(arg), args);</pre><pre>};</pre><pre>};</pre><p>What does these mean ? Compose and Pipe are among the most powerful concepts in functional programming in JavaScript.Let’s start with compose:</p><p>Imagine we want to get the name of a user and uppercase it. First of all, we have to write a function that extracts the name of the user:</p><pre>const user = {name: &#39;Gianmarco&#39;, password: 1234}<br>const getUserName = (user) =&gt; user.name<br>getUserName(user)<br>// &#39;Gianmarco&#39;</pre><p>And then a function that uppercases strings:</p><pre>const upperCase = (string) =&gt; string.toUpperCase()<br>upperCase(&#39;Gianmarco&#39;)<br>// &#39;GIANMARCO&#39;</pre><p>Now we can compose the two functions to have just one function that executes both actions: Get the name and uppercase it.</p><pre>const compose = (g, f) =&gt; x =&gt; g(f(x));</pre><pre>// &#39;x&#39; in compose()<br>const user = {name: &#39;Gianmarco&#39;, password: 1234}</pre><pre>// function &#39;f&#39; in compose()<br>const getUserName = (user) =&gt; user.name</pre><pre>// function &#39;g&#39; in compose()<br>const upperCase = (string) =&gt; string.toUpperCase()</pre><pre>const getUserNameAndUpperCase = compose(upperCase, getUserName)</pre><pre>getUserNameAndUpperCase(user); //&#39;GIANMARCO&#39;</pre><p>The version above is for only limited arguments. For unlimited version we need to use reduceRight()</p><pre>const compose = (...functions) =&gt; x =&gt; functions.reduceRight((acc, fn) =&gt; fn(acc), x);</pre><p>let’s implement this to our example</p><pre>const compose = (...functions) =&gt; x =&gt; functions.reduceRight((acc, fn) =&gt; fn(acc), x);<br>const user = {name: &#39;Gianmarco&#39;, password: 1234}<br>const getUserName = (user) =&gt; user.name<br>const upperCase = (string) =&gt; string.toUpperCase()<br>const firstFour= (string) =&gt; string.substring(0,4)<br>compose (firstFour, upperCase, getUserName) (user);<br>// &#39;GIAN&#39;</pre><p><strong>Pipe</strong> is exactly like compose(), but it works left to right. I personally prefer it over compose() because you can think of it as a sequence of events. Change <strong>reduceRight</strong> to <strong>reduce</strong></p><pre>const pipe = (...functions) =&gt; x =&gt; functions.reduce((acc, fn) =&gt; fn(acc), x);</pre><h4>Q11 Implement polyfill for Promise.all</h4><p>Fİrst let’s start with what promise.All is. It takes array of promises and again returns array of resolved values and it waits until last resolves. If any of them fails then it rejects with the first error message.</p><p>example for promise.All</p><pre>const promise1 = Promise.resolve(3);</pre><pre>const promise2 = Promise.resolve(24);</pre><pre>const promise3 = new Promise((resolve, reject) =&gt; {</pre><pre>setTimeout(resolve, 100, &quot;foo&quot;);</pre><pre>});<br>Promise.all([promise1, promise2, promise3]).then((values) =&gt; {</pre><pre>console.log(values);</pre><pre>});</pre><p>implementation of promise.All</p><pre>const promise1 = Promise.resolve(3);</pre><pre>const promise2 = Promise.resolve(24);</pre><pre>const promise3 = new Promise((resolve, reject) =&gt; {</pre><pre>setTimeout(resolve, 100, &quot;foo&quot;);</pre><pre>});</pre><pre>function myPromiseAll(promises) {</pre><pre>let result = [];</pre><pre>return new Promise((resolve, reject) =&gt; {</pre><pre>promises.forEach((p, index) =&gt; {</pre><pre>p.then((res) =&gt; {</pre><pre>result.push(res);</pre><pre>if (index === promises.length - 1) {</pre><pre>resolve(result);</pre><pre>}</pre><pre>}).catch((err) =&gt; reject(err));</pre><pre>});</pre><pre>});</pre><pre>}</pre><p>What does this code do ?</p><ol><li>We create a new array</li><li>and create a new promise for final resolve</li><li>inside we loop promises with forEach and push resolved value to array</li><li>if we reach at the end of the array we resolve the final promise</li><li>during the code if any of the promises fails we throw an error with catch</li></ol><h3>Third Round</h3><p><em>here session three starts</em></p><h4>Q12 Explain lifecycle methods for both class and function components</h4><p>In class components we use three</p><pre>1- componentDidMount</pre><pre>//! It runs when our rendered first time. We use this for usecases like fetching data from an API or provide inital value to some state</pre><pre>2- componentDidUpdate</pre><pre>//! Takes two arguments prevProps, prevState. With this we say react whenever the state changes do sth</pre><pre>3- componentWillUnmount</pre><pre>//! This runs when we remove the component from our app or just unmounting</pre><p>In function components we use useEffect</p><pre>//! useEffect(() =&gt;{console.log(&quot;updated&quot;)},[])</pre><pre>//! if dependency array(second param) empty then it just works one time at the beginning</pre><pre>//! if dependency array is not empty then every time it updates our useEffect will run</pre><pre>//! if we return a callback inside useEffect then when our component unmounted our callback will run</pre><p>Obviously there are more lifecycle methods but these are main, major ones. If you explain more , good for you.</p><h4>Q13 Show us ways to center a div</h4><p>here he said “I was waiting my whole life for the interviewer to ask me this question”😂<br>Here are some ways :</p><pre>//! position: absolute;</pre><pre>//! top: 50%;</pre><pre>//! left: 50%;</pre><pre>//! transform: translate(-50%, -50%);</pre><pre>//! display: flex;</pre><pre>//! justify-content: center;</pre><pre>//! align-items: center;</pre><pre>//! display: grid;</pre><pre>//! justify-content: center;</pre><pre>//! align-items: center;</pre><h4>Q14 Explain CSS Box Model</h4><p>There are three main terms when it comes to bo model. You probably know all of them. If not, you are not ready for interviews</p><ol><li>Border</li><li>Margin</li><li>Padding</li></ol><figure><img alt="box model" src="https://cdn-images-1.medium.com/max/408/1*Z2JNNj4WNTe4MMBJXowDvg.png" /></figure><h4>Q15 Explain Implement debounce</h4><p>In JavaScript, a debounce function makes sure that your code is only triggered once per user input. Search box suggestions, text-field auto-saves, and eliminating double-button clicks are all use cases for debounce.</p><p>let’s say you are searching for a product in a shopping website. You are writing into output and after miliseconds you stopped typing it starts to perform some actions.</p><p>Implementation</p><pre>export default function App() {<br>const myDebounce = (callback, delay) =&gt; {</pre><pre>return function (...args) {<br>if(timer) clearTİmeout(timer);<br>let timer;</pre><pre>timer = setTimeout(() =&gt; {</pre><pre>callback(...args);</pre><pre>}, delay);</pre><pre>};</pre><pre>};</pre><pre>const handleChange = myDebounce((event) =&gt; {</pre><pre>console.log(event.target.value);<br>}, 1000);</pre><pre>return (<br>&lt;div className=&quot;App&quot;&gt;<br>&lt;input onChange={handleChange}/&gt;<br>&lt;/div&gt;<br>);<br>}</pre><p>Try this block of code and you will see that after one second you stop typing it will log the value to the console.</p><h3>Fourth Round</h3><p><em>here session four starts</em></p><p>In this part they ask</p><ol><li>cultural questions</li><li>strengths and weaknesses</li><li>How would you react to different situations</li><li>Problem solving techniques</li><li>Soft skills</li></ol><h3>Summary</h3><p>Thank you for reading my work until here. Every developer has a unique way of solving problems. However, for interviews it is better if you prepare and search questions that asked often. Especially for juniors like me need some extra preparation for their first job interviews.</p><p>This interview was taken by Piyush Agarwal a.k.a Roadside Coder on youtube. I appreciate his efforts to help us with sharing these questions. You can subscribe and like his channel to help him as well. 🙏🏻<br><a href="https://www.youtube.com/c/RoadsideCoder">https://www.youtube.com/c/RoadsideCoder</a></p><p>Thank you and see you in another article❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b3e3ffefe3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Object Oriented Programming in Nutshell]]></title>
            <link>https://medium.com/@birceste/python-object-oriented-programming-in-nutshell-2c12205ee10e?source=rss-8176c562caa0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c12205ee10e</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[BAVI-BOOP]]></dc:creator>
            <pubDate>Wed, 06 Jul 2022 16:31:14 GMT</pubDate>
            <atom:updated>2022-07-06T16:31:14.203Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Object Oriented Programming" src="https://cdn-images-1.medium.com/max/1024/1*rD0UZElTf1vJbghpqRbAww.jpeg" /></figure><p>This paradigm seems kind of hard for beginner and mid-level programmers. It is a relief rather than a burden for us. Believe it or not, developing a product without OOP is similar to building an apartment with only one builder. In IT, there is a term called <em>Procedural programming and it </em>uses a linear top-down process. Imagine you start writing from line 1 to the last line that you stop writing. However, in this way when you are working on long and complex projects, the readability and efficiency of the program decrease.Our code becomes very like spaghetti.This method belongs to old programming languages like Fortran.While you try to connect all the items, it becomes like Kardashian’s dating history 😄</p><figure><img alt="Kardashian’s dating history" src="https://cdn-images-1.medium.com/max/653/1*TIltVku-bw-y2whdncCfKg.png" /></figure><p>For this not to happen we need to divide our program into modules and classes. Here comes Object-Oriented Programming, which is very versatile in contrast to procedural programming. Let’s say you started in Starbucks as a software developer and your task is to create an algorithm for a coffee machine. Take your time and think about this for a couple of minutes!</p><figure><img alt="Coffee machine" src="https://cdn-images-1.medium.com/max/1024/1*fvqw7An-69h0DKwetji_Vg.jpeg" /></figure><p>We need a couple of functions to make it work.</p><ol><li>to check if the water and milk is enough</li><li>to count the coins inserted</li><li>to give the changes back</li><li>make the coffee</li><li>deduct the resources used</li></ol><p>You can write these functions from top to bottom. Somehow you can connect them but as I said it would be messy.Let me show you an example of this<a href="https://emojipedia.org/backhand-index-pointing-down/">👇</a> This simple coffee machine project was developed with procedural programming.</p><p><a href="https://github.com/BAVI-BOOP">https://github.com/BAVI-BOOP</a></p><p>With OOP you can create a class for each of them in different modules. Instead of one player, we prefer teamwork with many players. If we depend on one module then we limit ourselves and come across problems. When all the modules finish, they all work in the main module. The main module serves as a gathering point for all functions.</p><p>What is more important is you can use these modules again and again in different programs. Each class serves a function and <em>is reusable</em>. For instance, we can use <em>the money counting</em> module in the supermarket algorithm or we can use <em>make the coffee</em> module in a bar program. It increases the productivity and readability of our program.</p><p>Coffee machine written with OOP<a href="https://emojipedia.org/backhand-index-pointing-down/">👇</a></p><p><a href="https://github.com/BAVI-BOOP/100-days-of-python/tree/main/day-16">https://github.com/BAVI-BOOP/100-days-of-python/tree/main/day-16</a></p><p>Probably you are wondering how you can write these modules and classes. First, you need to understand the mentality behind it. I already tried to explain to you but in case you didn’t understand please check other resources. Secondly, you need to create another python file beside your main.py. Then you have got to define the class with this syntax. Class naming should be PascalCase.</p><figure><img alt="Class syntax" src="https://cdn-images-1.medium.com/max/535/0*jwhYPZiEnw6Dpefo.png" /></figure><p>What is a class? It is like a <em>blueprint</em> for you. You can use the class and create infinite <em>instances.</em> These instances are <em>objects</em>. Every object has a unique place in the computer’s memory such as &lt;__main__.Test object at 0x2aba1c0cf890&gt;<em>. </em>Using objects with coffee machine class<em> y</em>ou can create coffee machines with different prices different colors different coffee types with different resources.</p><figure><img alt="Blueprint" src="https://cdn-images-1.medium.com/max/441/0*dpBAettQSdSkcUhi.jpg" /></figure><p>Functions inside classes are called <em>method</em>s and variables inside classes are called <em>attributes</em>.</p><p>I stop here because I don’t want to dig deep and I expect you the understand the fundamentals. You can learn all the rules and syntax by googling. However, I get so many questions about the keyword <em>self and __init__ keywords. </em>For the last topic, I’ll try to mention it.</p><p>__init__ is one of the reserved methods in Python. In object-oriented programming, it is known as a <em>constructor</em>. The task of constructors is to initialize(assign values) to the data members of the class when an object of the class is created. When you create an object from that class, it initializes itself and automatically assigns the instance attributes. Instance attributes are defined inside a constructor using the self parameter.</p><p>The self is used to represent the instance of the class. With this keyword, you can access the attributes and methods of the <a href="https://www.edureka.co/blog/python-class/">c</a>lass in python. It binds the attributes with the given arguments. You can assign different attributes to every object you are creating. Arguments and parameters in functions help us to achieve it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*CV8KaIGiAcf7TpAtFROidQ.png" /></figure><p>For a better understanding, study a bit more on this topic and read this article one more time. You will see the difference. Thank you so much for reading until the end of the article. Let me know you liked it or not <a href="https://emojipedia.org/backhand-index-pointing-down/">👇</a></p><p><a href="https://www.linkedin.com/in/ahmet-ayd%C4%B1n-2583b1199/">https://www.linkedin.com/in/ahmet-ayd%C4%B1n-2583b1199/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c12205ee10e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>