<?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: Valentin PARSY</title>
    <description>The latest articles on DEV Community by Valentin PARSY (@parsyvalentin).</description>
    <link>https://dev.to/parsyvalentin</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%2F180127%2F3d5476e9-6e0a-42c0-962c-52119a539f1e.jpg</url>
      <title>DEV Community: Valentin PARSY</title>
      <link>https://dev.to/parsyvalentin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/parsyvalentin"/>
    <language>en</language>
    <item>
      <title>You don't know spread operator !</title>
      <dc:creator>Valentin PARSY</dc:creator>
      <pubDate>Sun, 12 Sep 2021 12:27:23 +0000</pubDate>
      <link>https://dev.to/parsyvalentin/you-don-t-know-spread-operator-3gk2</link>
      <guid>https://dev.to/parsyvalentin/you-don-t-know-spread-operator-3gk2</guid>
      <description>&lt;p&gt;I was recently reading a &lt;a href="https://2ality.com/2021/08/iteration-helpers.html" rel="noopener noreferrer"&gt;blog post about iteration&lt;/a&gt; from &lt;a href="https://twitter.com/rauschma" rel="noopener noreferrer"&gt;Axel Rauschmayer&lt;/a&gt; (I suggest you follow him, all his posts are minegold for JS devs).&lt;br&gt;
This post was mindblowing to me as I learned so much about iteratables in JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's challenge our knowledge
&lt;/h3&gt;

&lt;p&gt;Let me sum up a bit of what I learned here with a small challenge to you : &lt;br&gt;
When I use the spread operator on a Number, I want the result to be an array that counts from 1 to the given value : &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0z8hf4grikvwed044qoe.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0z8hf4grikvwed044qoe.jpg" alt="Example in the chrome console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  First steps to an answer
&lt;/h3&gt;

&lt;p&gt;First thing to do is try the code for yourself and you will see that using a spread operator on a Number throws an error =&amp;gt; &lt;strong&gt;Uncaught TypeError: X is not iterable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then &lt;strong&gt;what is an iterable&lt;/strong&gt; ? &lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators" rel="noopener noreferrer"&gt;An iterable is an object that defines an iteration behavior,&lt;/a&gt; meaning it has a property with a Symbol.iterator key and an iterator as value.&lt;br&gt;
This iterator should respect the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol" rel="noopener noreferrer"&gt;iteration protocol&lt;/a&gt; which means it is a function that returns an object with a next fonction that returns an object with 2 properties : "value" (the current iteration's value) and "done" (a boolean indicating weither we are done iterating with this iterator or not).&lt;/p&gt;

&lt;p&gt;The spread operator is simply a consummer of such iterables: when you give it an iterable, it'll call the next function of its Symbol.iterator property until it returns an object with {done: true} (and push each time the result in an array).&lt;/p&gt;

&lt;h3&gt;
  
  
  Verify that with an Array
&lt;/h3&gt;

&lt;p&gt;An array in JavaScript is an iterable since it has an iterator as a value of its property with Symbol.iterator key.&lt;br&gt;
Here is how you can use this iterator :&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwg4tk254640lb3tjmc7j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwg4tk254640lb3tjmc7j.jpg" alt="Usage of an array iterator in the chrome console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Answer to the challenge
&lt;/h3&gt;

&lt;p&gt;So how do I make the spread operator not throwing an error when given a number ? You set the Symbol.iterator property on the Number primitive wrapper object.&lt;br&gt;
Let's make all numbers iterables ! &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwfhb43kg2abzaek28sk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwfhb43kg2abzaek28sk.jpg" alt="Setting the property on the Number's prototype"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Obviously you never want to change the prototype of a primitive wrapper object, it's too dangerous.&lt;br&gt;
But the knowledge of how iteration and the spread operator works is I think very valuable as a developper. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Piece of Mind: Testing</title>
      <dc:creator>Valentin PARSY</dc:creator>
      <pubDate>Thu, 31 Oct 2019 09:52:14 +0000</pubDate>
      <link>https://dev.to/parsyvalentin/piece-of-mind-testing-4edb</link>
      <guid>https://dev.to/parsyvalentin/piece-of-mind-testing-4edb</guid>
      <description>&lt;p&gt;Welcome to this series of articles &lt;strong&gt;Piece of Mind&lt;/strong&gt;.&lt;br&gt;
In these articles I will just tackle the surface of subjects I care about and what is my thought process on them. They will hopefully bring you to reflect and maybe research them in order to grow your own ideas and practices on them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.realpython.com%2Fmedia%2FGetting-Started-with-Testing-in-Python_Watermarked.9f22be97343d.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.realpython.com%2Fmedia%2FGetting-Started-with-Testing-in-Python_Watermarked.9f22be97343d.jpg" alt="testing machine"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Testing your code is a very important step in your developer journey. Unfortunately, a lot of people think it's useless and/or don't need that much consideration while coding. I often see code badly tested (false positives, unreadable tests, etc...) when it should be a priority to the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Anti-regression
&lt;/h2&gt;

&lt;p&gt;When updating a codebase, especially a big one, you can't always guess what your changes will bring. &lt;br&gt;
Let's say you have a slider with a blue button on the first slide and a yellow button on the others.&lt;br&gt;
You are now asked to change the last slide button color to green.&lt;br&gt;
You add one line of code there, remove one here, you compile and launch the project to visually test that the last button is green. &lt;br&gt;
Everything's perfect, you have done your job, and the project manager will be happy to see their green button. &lt;br&gt;
But at the next meeting, the project manager is not happy ... they (or the QA team) found that the first button is no longer blue. You completely missed that when you checked for your modification on the last slide.&lt;/p&gt;

&lt;p&gt;Well it wouldn't have happened with tests (ok ok it still happens ... but a lot less !)&lt;br&gt;
With correct tests, you can catch regressions before they happen.&lt;br&gt;
If a test says "On the first slide the button should be blue" and another says "On every page but the first one, the button should be yellow" and after you update the code the first test fails, you know you broke something and can quickly fix it (and you also know you should update your tests to add a test about the last button).&lt;/p&gt;

&lt;h2&gt;
  
  
  Project comprehension
&lt;/h2&gt;

&lt;p&gt;Good tests can be an awesome tool for project comprehension. Sure you can read all the codebase and have a pretty good idea about what's going on, but not everyone is capable of that and anyone can miss some points.&lt;br&gt;
With well-written tests, you can just read the test descriptions to know what was asked of the developer.&lt;br&gt;
Without reading any code, you open the tests for the button from the previous example and you read : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First test: "The button is blue on the first slide"&lt;/li&gt;
&lt;li&gt;Second test: "The button is yellow on all slides but first and last"&lt;/li&gt;
&lt;li&gt;Third test: "The button is green on the last slide" &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After 3 lines you know exactly what this component is all about, and what is expected of it by UI/UX/Business&lt;/p&gt;

&lt;h2&gt;
  
  
  TDD (Test Driven Development)
&lt;/h2&gt;

&lt;p&gt;The 3 big letters of testing! You surely may have heard of it before. TDD is a way of writing tests for your project. Basically you write tests BEFORE you write code. The tests obviously fail, your job is then to make them pass.&lt;br&gt;
This is a great way to work because you just have to translate what you've been asked: just write down as description what is expected ("The button is blue on the first slide").&lt;br&gt;
The big downside, at first, of this process is that it's hard to work like that on a technology you're not used to yet or when you begin to learn how to write tests... Once you got those two requirements, try TDD out =D&lt;/p&gt;




&lt;p&gt;Ideas to go further : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://kentcdodds.com/" rel="noopener noreferrer"&gt;https://kentcdodds.com/&lt;/a&gt; : &lt;a href="https://twitter.com/kentcdodds" rel="noopener noreferrer"&gt;Kent C.Dodds&lt;/a&gt; is a software developer that is passionate about testing and testing good practices. Even if his talks/articles are mainly about front-end development, any developer can learn from him.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://smartbear.com/learn/automated-testing/best-practices-for-automation/" rel="noopener noreferrer"&gt;A great article&lt;/a&gt; about rules to follow to create great tests in your projects.&lt;/li&gt;
&lt;li&gt;For JavaScript developers: &lt;a href="https://raygun.com/blog/javascript-unit-testing-frameworks/" rel="noopener noreferrer"&gt;a nice article that compares some testing tool&lt;/a&gt;. Because it's important to choose a good tool for a job.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://medium.com/@yahelyechieli/5-tips-for-writing-great-javascript-unit-tests-86296ad2d997" rel="noopener noreferrer"&gt;Nice tips for writing good test descriptions&lt;/a&gt; by Yahel Yechieli.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A special thanks to &lt;a href="https://twitter.com/rudy_weber" rel="noopener noreferrer"&gt;Rudy Weber&lt;/a&gt; for helping me writing this piece of mind.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
