<?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 Julien Demarque on Medium]]></title>
        <description><![CDATA[Stories by Julien Demarque on Medium]]></description>
        <link>https://medium.com/@juliendemarquedev?source=rss-20dd915a211a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*01BNjZ5QkhkN0Fw3</url>
            <title>Stories by Julien Demarque on Medium</title>
            <link>https://medium.com/@juliendemarquedev?source=rss-20dd915a211a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:08:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@juliendemarquedev/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[Flow applied to coding]]></title>
            <link>https://juliendemarquedev.medium.com/flow-applied-to-coding-61675f4a1d33?source=rss-20dd915a211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/61675f4a1d33</guid>
            <category><![CDATA[flow]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[motivation]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Julien Demarque]]></dc:creator>
            <pubDate>Sun, 25 Oct 2020 19:06:22 GMT</pubDate>
            <atom:updated>2020-10-25T19:06:22.833Z</atom:updated>
            <content:encoded><![CDATA[<p>Working as a web developer at <a href="https://www.inv.tech/">Invisible</a> in the last years has been exhilarating. Our work is entirely remote and looking at how involved are the developers on the team made me wonder: What keeps us motivated to work when we likely have so many distractions around?</p><p>Few things come to mind: salary, feeling a sense of meaning and purpose in their work, working in positive company culture, being recognized for our hard work, opportunities for learning and development in the workplace…</p><p>But although all these are certainly true, when someone is head down doing some coding, then this person is certainly not thinking about the money he/she makes every 2 seconds, or about how people are going to congratulate him/her for such a beautiful code. Then what keeps us coding from moment to moment? coding itself maybe? Which brings us to flow:</p><p>Here is Wikipedia’s definition:</p><blockquote>In positive psychology, a <strong>flow state</strong>, also known colloquially as being <strong>in</strong> <strong>the zone</strong>, is the mental state in which a person performing some activity is fully immersed in a feeling of energized focus, full involvement, and enjoyment in the process of the activity. In essence, flow is characterized by the complete absorption in what one does, and a resulting transformation in one’s sense of time.</blockquote><p>One of the most important parts of the definition is <em>‘enjoyment in the process of the activity</em>’. Coding in flow means coding with pleasure. How is it possible? Well, we all have (or had) these moments where we finally got a solution to a challenging problem and felt good about it, whether if it was writing a functional chain of code, or understanding an API. We have all experienced flow at some point. <strong>So what kills flow? too challenging or too easy tasks.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*jd0kVdOuVfpEeAcKnTHWYA.png" /></figure><p>To make it simple, if the task is too challenging, you’ll get anxiety and you probably feel like not touching your keyboard. if the task is too easy, you might get bored.</p><p>First, the rarest case (as coding is generally hard): What if the task is too easy? This reminds me of grinding in games… how do game devs make us do boring repetitive tasks over and over again? They use juice (pleasant audio-visuals), difficulty, achievement rewards, division… How can we apply this to actual coding? well, my advice is to open your favorite IDE theme and put on your music playlists and burn down these tasks one by one. The carrot in the end is the team will be thankful to you for crushing the boring stuff.</p><p>So most importantly <strong>how do we get the right amount of challenge?</strong> There are 2 ways:</p><ul><li>Teamwork. Someone may have better skills to solve the task than another. So assigning the right challenge to the right person is important. Another way to solve it is pair programming, the anxiety will go down if a challenge is shared with others.</li><li>Making this comfortable zone bigger. I can’t affirm for sure that it works, but I think experienced coders are just getting comfortable with not knowing… so even if the challenge is big, they tackle it with enthusiasm. That doesn’t mean you should overestimate your capabilities, or take on all the tasks, regardless of your skill level, it just means that if after choosing the right person, the task is still pretty challenging, the only way to deal with it is to accept the challenge and attack it head-on.</li></ul><p>All in all, coding is fun! it’s building stuff with the tips of our fingers, it’s a game with no end, you can play it all your life and it is never really the same. It’s you and your team against the world. Infinite replayability, infinite levels. Welcome to Coding World…</p><p>Sources:</p><p>What motivates people to work: <a href="https://social.hays.com/2016/04/26/5-things-that-motivate-your-employees-more-than-money/">https://social.hays.com/2016/04/26/5-things-that-motivate-your-employees-more-than-money/</a><br>Flow: <a href="https://en.wikipedia.org/wiki/Flow_(psychology)">https://en.wikipedia.org/wiki/Flow_(psychology)</a><br>Game grind: <a href="https://www.youtube.com/watch?v=nP1qLrXaDvE">https://www.youtube.com/watch?v=nP1qLrXaDvE</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61675f4a1d33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the “this” keyword in JavaScript]]></title>
            <link>https://juliendemarquedev.medium.com/lessons-learnt-from-ydkjs-this-object-prototypes-part-1-be9db05f90e6?source=rss-20dd915a211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/be9db05f90e6</guid>
            <category><![CDATA[freecodecamp]]></category>
            <category><![CDATA[kyle-simpson]]></category>
            <category><![CDATA[ydkjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[this-keyword]]></category>
            <dc:creator><![CDATA[Julien Demarque]]></dc:creator>
            <pubDate>Sun, 14 Oct 2018 22:01:35 GMT</pubDate>
            <atom:updated>2018-10-15T12:01:22.052Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lessons learnt from YDKJS “this &amp; Object Prototypes” — Part 1</h3><p>This article will try to cover only the essential points from You Don’t Know JS “this &amp; Object Prototypes” by Kyle Simpson. Advanced discussions in the book are left off here but sometimes mentioned for reference; if you enjoyed the article, read the book!</p><p><a href="https://github.com/getify/You-Dont-Know-JS">https://github.com/getify/You-Dont-Know-JS</a></p><p>So let’s get to it:</p><h3><strong>The “this”</strong> keyword</h3><p>the this keyword holds a value. To find its value, we only need to follow some rules. First we need to see where the this is declared: global context, function context or arrow-function context.</p><blockquote>1.Global Context</blockquote><p>In the global execution context (outside of any function), this refers to the global object whether in strict mode or not.</p><p>exemple:</p><pre>console.log(this === window); // true<br>var foo = 2;<br>console.log(window.foo); // 2<br>console.log(this.foo); // 2</pre><p>Note: You might be wondering why window.foo references 2, this is because any variable declared in the global scope also ends up as a property on the global-object window .</p><p>Ok this was the first rule for this. Obviously not a useful use case so you probably won’t see it anywhere.</p><p>Next comes the real use cases, the function context.</p><blockquote>2.Function Context</blockquote><p>We have seen that if the this is declared in the global scope, it is pretty useless. So now we will explore the rules for the case where this is declared in a function scope. We need now to ask ourselves how is the function being called. Let me say that again:</p><blockquote>Inside a function, the value of “this” depends on how the function is called.</blockquote><p>So here are the rules, the call-site can be one of the following:</p><p><em>2.a. Simple Call (default binding)</em></p><p>If the function call is a standalone function invocation (or you could call it a simple call), this refers to the global object (this is what Kyle Simpson refers as the default binding) or to undefined if in strict mode.</p><p>exemple:</p><pre>function foo(){<br> console.log(this);<br>}<br>foo(); // window &lt;--here is the call-site</pre><pre>function bar(){<br> &quot;use strict&quot;;<br> console.log(this);<br>}<br>bar(); // undefined &lt;--here is the call-site</pre><p><em>2.b. As a object method (implicit binding)</em></p><p>If the call-site has a context object (the first thing on the left of the function call), then this refers to the object the method is called on. This is what Kyle Simpson calls the “implicit binding” as we use a context object in the call-site to indirectly bind this to the object.</p><p>exemple:</p><pre>function foo(){<br> console.log(this.a);<br>}; </pre><pre>var obj1 = {<br> a: 2,<br> foo: foo,<br> baz: function baz(){<br>     console.log(this);<br>  }<br>};</pre><pre>obj1.baz(); // obj {a: 2, foo: ƒ, baz: ƒ} &lt;--here is the call-site<br>obj1.foo(); // 2 &lt;--here is the call-site</pre><p>Note: it doesn’t matter if foo is declared and then later added as a reference property onto obj or initially declared <em>on</em> foo. As Kyle Simpson points out, in JavaScript function like foo are never really “owned” or “contained” by an object, but you could say that obj “owns” or “contains” a reference to the function foo.</p><p>An Other Note : Only the top/last level of an object reference chain matters to the call-site.</p><pre>obj1.obj2.foo(); &lt;--- &quot;this&quot; inside foo would refers to obj2</pre><p><em>2.c. Apply/call method (explicit binding)</em></p><p>All functions you create have access to applyand call methods. They both take an object of your choice as their first parameter, this object is then used for the this. Now we are explicitly giving the context to the function call.</p><p>exemple:</p><pre>function foo(){<br> console.log( this.a );<br>}</pre><pre>var obj = {<br>  a: 2<br>}</pre><pre>foo.call(obj); //2   &lt;-- this is the call site<br>foo.apply(obj); //2   &lt;-- this is the call site</pre><p>Note: call and apply are taking more parameters, see MDN for documentation.</p><p><em>2.d. The bind method (explicit hard binding)</em></p><p>Remember I said that inside a function, the value of this depends on how the function is called, well here is now kind of an exception: the use of bind. I’ll explain later why I use “kind of”.</p><p>f.bind(someObject) creates a new function with the same body and scope as f, but where this occurs in the original function, in the new function it is permanently bound to the first argument of bind, regardless of how the function is being used (This is copy-paste from MDN).</p><p>exemple:</p><pre>function foo(){<br> console.log( this.a );<br>}</pre><pre>var obj = {<br>  a: 2<br>}</pre><pre>var baz = foo.bind(obj); <br>baz(); // 2</pre><p>Note: the call-site of foo isn’t really apparent, we can imagine conceptually that it is actually hidden inside the bind function definition this way: foo.call(obj);, if we look at it like that, we didn’t really break the rule of looking at the call-site for finding the value of this.</p><p><em>2.e. As a constructor (new binding)</em></p><p>JavaScript has a new operator, and that ressembles class-oriented languages, however in JavaScript, constructors are just plain functions that happen to be called with the new operator in front of them. It is a standard to use CamelCase for them to differentiate them from other functions. Here is an exemple:</p><pre>function Foo(a){<br> this.a = a;<br>}</pre><pre>var bar = new Foo( 2 );<br>console.log(bar.a) // 2</pre><p>Here is how it works, when we call newon Foo:</p><ol><li>A brand new object is created out of thin air</li><li>The newly constructed object is [[Prototype]]-linked to Foo.prototype</li><li>The newly constructed object is set as the this binding for the function call.</li><li>Unless the function returns its own alternate object, the new-invoked function call will automatically return the newly constructed object.</li></ol><p>Hard to make sense? Well let’s leave out step number 2, it is not relevant for our discussion here and will be explained in details when with talk about Object Prototypes. For now let’s imagine conceptually what happened as if Foo was transformed:</p><pre>function Foo(a){<br> var newObject = {}; &lt;-- step 1<br> newObject.a = a; &lt;-- step 3, see how &quot;this&quot; becomes newObject?<br> return newObject; &lt;-- step 4<br>}</pre><pre>var bar = new Foo( 2 );<br>console.log(bar.a) // 2</pre><p>Note: As of ES6, there is a class keyword that is essentially syntactic sugar for constructor functions:</p><pre>class Foo{<br> constructor(a){<br>   this.a = a;<br> }<br>}</pre><pre>var bar = new Foo( 2 );<br>console.log(bar.a) // 2</pre><p>Alright, We have explored 5 cases when this is declared in a function context. Let’s quickly review them in order of precedence:</p><ol><li>Called with new ? Use the newly constructed object.</li><li>Called withbind ? Use the specified object.</li><li>Called with call or apply? Use the specified object.</li><li>Called as a method? Use the context object.</li><li>Default: undefined in strict mode, global object otherwise.</li></ol><p>Extra case: What if the call-site is not visible?</p><p><em>2.f. As a DOM event handler</em></p><p>When we pass a callback function to an event handler, this is set to an DOM element (most likely the element the event fired from or the element on which the listener is placed). Note that is rarely what we want, so you will often see the function callback being bind to some other object using the bind method before being passed as a callback or you will see the use of the ES6 arrow-function which leads us to the last part:</p><blockquote>3.Arrow-function context</blockquote><p>Arrow-functions are signified not by the function keyword, but by the so-called “fat arrow” operator, =&gt;. Instead of using the previous this rules, arrow-functions adopt the this binding from the enclosing (function or global) scope.</p><p>exemple:</p><pre>function foo(){<br>   return (a)=&gt;{<br>    console.log(this.a);<br>   }<br>}<br>var obj1 = {<br>  a: 2<br>};<br>var obj2 = {<br>  a: 3<br>};</pre><pre>var bar = foo.call( obj1);<br>bar.call(obj2); // 2, not 3!</pre><p>So what happened here, well conceptually we can just imagine the foo function being like this:</p><pre>function foo(){ <br>  var that = this;<br>  return function(a){<br>    console.log(that.a);<br>   }<br>}</pre><p>Makes sense? I hope.</p><p>That’s it! We covered it all for the keyword this .</p><h3>Conclusion</h3><p>Want a real life exemple? Let’s talk about React, either saw something like that?</p><pre>class HelloWorld extends React.Component { <br>   constructor(props) {   <br>     super(props);    <br>     this.state = { message: &#39;Hi&#39; }; <br>     this.logMessage = this.logMessage.bind(this);<br>   }   </pre><pre>   logMessage() {   <br>     console.log(this.state.message); <br>   }   <br>  <br>   render() { <br>     return (    <br>       &lt;input <br>          type=&quot;button&quot; <br>          value=&quot;Log&quot;<br>          onClick= {logMessage} /&gt;    <br>     ); <br>  }<br>}</pre><p>What’s going on? Any idea?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FTlbBXhmbYMLe0%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FTlbBXhmbYMLe0&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FTlbBXhmbYMLe0%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/301410795855943a745c9addcbbd30c4/href">https://medium.com/media/301410795855943a745c9addcbbd30c4/href</a></iframe><p>Ok, let’s see:</p><p>this is in the constructor of a ES6 class. Somewhere in the react library, the HelloWorld class will be called with new. So this will be set to a newly created object (an instance of the class). state will therefore be a property on this newly created object.</p><p>Ok so what happens with the line this.logMessage = this.logMessage.bind(this) ? React called new and created an new object that we will called hWInstance. (as HelloWorld instance). So as a result we got:</p><p>hWInstance.logMessage = hWInstance.logMessage.bind(hWInstance);</p><p>cool, why did we do that? well we have replaced the function definition oflogMessage and now the this inside of logMessage is explicitly hard binded to hWInstance.</p><p>Now we see we passed logMessage as the event handler of onClick on the input element. Inside logMessage we see console.log(this.state.message);</p><p>We want to access state on the newly created object (hWInstance), luckily we binded logMessage to this object so we got console.log(hWInstance.state.message);</p><p>Nice, what would have happen without this.logMessage = this.logMessage.bind(this) ?</p><p>Well as we saw before this in event handler normally gets bind to the DOM element, so console.log(this.state.message); would have tried to access a property called state on the DOM element, resulting in an error. This is a very common mistake for beginners in React.</p><p>If you want to know more how different ways this binding can be done, check this great article: <a href="https://medium.freecodecamp.org/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56">https://medium.freecodecamp.org/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56</a></p><p>Ok this is the end of this article, PART 2 will deal with Object Prototype.</p><p>About me: I am a self-taught web developer, here is my website: <a href="https://julien-demarque-portfolio.herokuapp.com/">https://julien-demarque-portfolio.herokuapp.com/</a></p><p>Feel free to contact me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be9db05f90e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>