<?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 Juani Galán on Medium]]></title>
        <description><![CDATA[Stories by Juani Galán on Medium]]></description>
        <link>https://medium.com/@juani-galan?source=rss-9c7bea790013------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YcdW9T8ZQ7-m85rSUmlrkA.jpeg</url>
            <title>Stories by Juani Galán on Medium</title>
            <link>https://medium.com/@juani-galan?source=rss-9c7bea790013------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 20:01:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@juani-galan/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[LumApps — Changing our frontend interview process]]></title>
            <link>https://medium.com/lumapps-engineering/lumapps-changing-our-frontend-interview-process-37086f998f4a?source=rss-9c7bea790013------2</link>
            <guid isPermaLink="false">https://medium.com/p/37086f998f4a</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[continuous-improvement]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Juani Galán]]></dc:creator>
            <pubDate>Tue, 12 Jan 2021 08:42:27 GMT</pubDate>
            <atom:updated>2021-01-12T08:42:27.629Z</atom:updated>
            <content:encoded><![CDATA[<h3>LumApps — Changing our frontend interview process</h3><p>At the beginning of 2020, we decided to change our interview process for our frontend candidates by introducing a new frontend test that tries to take away the pressure of coding challenges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzMUPMlSNSD5fKhwQJ_faQ.jpeg" /><figcaption>It is time to say goodbye to the whiteboard interview</figcaption></figure><h3>A little bit about LumApps</h3><p>If you do not know about <strong>LumApps</strong>, we are a global tech company with R&amp;D teams in France that provides our customers a <strong>SaaS Digital Workplace</strong> solution, which creates a holistic workspace, integrated with several suites and collaboration tools. Want to know a little bit more about us? Head over to <a href="https://www.lumapps.com/">LumApps.com</a> and take a look!</p><h3>What was our frontend interview process like before?</h3><p>Up until 2020, our frontend interview process consisted of several interviews that tried to evaluate the technical knowledge of the candidates as well as the cultural fit with the company:</p><ul><li>An <strong>initial interview with our tech recruiter</strong> as a the initial step of the interview process</li><li>An <strong>interview with the team&#39;s manager</strong> in order to get to know the candidate a little bit more and evaluate their tech background as well as their cultural fit.</li><li>An online questionnaire with technical questions for <strong>JavaScript</strong>, <strong>Angular</strong> <strong>JS</strong> and <strong>React</strong>. These questions would be quite theoretical (like <em>What is “hoisting” in JavaScript?</em>) or tricky (like what is the output of <em>(function() { var a = b = 5; })(); console.log(b);</em>), or involved specific framework concepts such as digest cycle for Angular JS or explain the reconciliation process for React.</li><li>We then had a <strong>live coding challenge</strong> where the candidate would have a series of exercises to do while another engineer followed their steps.</li><li>If those tests went well, we then had a <strong>final round of interviews</strong> with several members of different teams, each of them with a different technical background.</li></ul><h3>What were things that led us to change the process?</h3><h4>Technical perspective</h4><p>From a technical standpoint, our technical test was not ideal for either our candidates as well as our company.</p><ul><li>Our online form had mostly questions that tried to evaluate very specific technical knowledge but <strong>ended up being</strong> questions that were <strong>tricky, nit-picky</strong> and really <strong>did not help us evaluate a candidate</strong>. We really did not need to know if a candidate knows what is the output of <em>(function() { var a = b = 5; })(); console.log(b);</em>), it proves little to nothing 😅</li><li>We also asked questions about Angular JS, which is really a technology that we are currently using in our Legacy application, but <strong>we are slowly transitioning into full React</strong>. Having questions that evaluate Angular JS knowledge <strong>will not help us in the future</strong>, since what we really want is to have a full React application. And usually when we need to change something on the legacy application, is it basically to fix a bug or add a React component, <strong>so we really did not need to evalute a candidate&#39;s knowledge on Angular JS</strong>.</li><li>Then there was the <strong>coding challenge</strong>. This is a current subject in the frontend community, with several opinions and perspectives. From our end, we believe that <strong>we need to evaluate our candidate on how well they will perform their daily tasks</strong>, <strong>how they can code using the technologies that we are using</strong>, and which are their strengths and which are the topics that they need a little bit more help. <strong>A coding challenge does not represent any of those things</strong>, since you are not usually coding a binary search (on LumApps frontend at least), you are not usually coding with someone evaluating your every move, and you do not code without Google or an IDE.</li><li>Furthemore, as a company, LumApps grows everyday, with a lot of features under development, some of them with a very important weight on their shoulders. We needed to <strong>start evaluating candidates on whether they were capable of leading entire initiatives</strong>, or they could be part of those initiatives with more of a contributor role. This meant that we needed to evaluate our candidates on an architectural and long term perspective, and with <strong>our current tests, were not able to</strong>.</li></ul><h4>Cultural perspective</h4><p>As for our cultural evaluation of the candidate, what we were really missing is the fact that the candidate <strong>did never encounter other developers from their own team</strong>. They had interviews with their managers, and other coworkers from other teams, but they never talked with someone that will be working with them on a daily basis.</p><h3>Which is our interview process now?</h3><p>Taking all of those topics into consideration, we decided to restructure our frontend interview process:</p><ul><li><strong>Our initial interviews with the recruiter and the manager are still in place</strong>, we found that those steps are quite essential for explaining the candidate what we do at LumApps, what they could possibly do in their team and how the interview process will unfold.</li><li><strong>We ditched the online form, all the technical questions and the coding challenge</strong>, and replaced it with a <strong>frontend test that each candidate can do from their home</strong>. We have a <a href="https://github.com/lumapps/frontend-tech-test">public repository</a> with a base application, with several utilities and scaffolding already in place in order to mimic the tools that we use at LumApps on our daily basis. The candidate needs to fork that repository, and code the provided exercise, which is basically a <strong>search results and details page of superheroes from Marvel</strong>, using Marvel&#39;s public API. The test usually takes around 4 hours to complete, we already provide a developement environment, with no setup needed. Just hit <strong><em>yarn</em></strong> and you are good to go.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*WJeIXJJlXNGhljBFlI4Rrg.png" /><figcaption>We provide pseudo mockups so that the candidate has an idea on what it is expected of them</figcaption></figure><ul><li>Once the candidate is satisfied with their test (the candidate can take all the time they want to do it, add tests, iterate, etc.), they provide us access to their forked repository and <strong>we start the review</strong>. In order to do that, we have a series of <strong>guidelines and key aspects that we want to evaluate</strong>, and depending how the candidate has performed on each aspect, we can have an idea of what their seniority would be. These topics go from <strong>code readability, project scaffolding, maintainability, performance, accessibility, usability and user and developer experience</strong>.</li><li>After that test, we do three interviews (usually the same day) with that candidate. The first one is <strong>a debrief of the technical test</strong> where we discuss a few of the implementations and decisions that the candidate took for their test. We want to have a moment to <strong>discuss these topics personally with the candidate</strong>, in order to evaluate what they wanted to do on the test, how they did it, and what they could add in the future.</li><li>The second one is more of a <strong>cultural fit interview</strong> where the candidate discusses with <strong>two of their future/possible team mates</strong>. We try to get someone from the backend team and someone from the frontend team in that meeting, so they we have several different points of view.</li><li><strong>The third one is with our CTO</strong>. Our cultural fit is very important and our CTO loves to exchange with the future candidates on this topic, and this allows the candidates to have an exchange with a co-founder, with provides a lot of insights and opportunities to discuss the long term vision of the company.</li></ul><h3>What did we learn from this change?</h3><p>As of today, <strong>we have already changed for good our frontend test</strong>, and all of our frontend candidates from now on will take the new format. From it, we learned that allowing candidates to <strong>take the test in a normal working environment</strong>, where you do not have someone breathing on your neck and where you are implemeting <strong>something cool and fun</strong> rather than testing your skills for coding a complex function can provide a set of results that allows us not only to <strong>evaluate their skills and how can they work on a daily basis</strong>, but also allow candidates to <strong>express what they can do</strong>, what technologies they can use, and how they can use them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37086f998f4a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lumapps-engineering/lumapps-changing-our-frontend-interview-process-37086f998f4a">LumApps — Changing our frontend interview process</a> was originally published in <a href="https://medium.com/lumapps-engineering">LumApps Experts</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LumApps — Road to React]]></title>
            <link>https://medium.com/lumapps-engineering/lumapps-road-to-react-ee0cc96af26e?source=rss-9c7bea790013------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee0cc96af26e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[lumapps]]></category>
            <dc:creator><![CDATA[Juani Galán]]></dc:creator>
            <pubDate>Mon, 23 Nov 2020 11:03:25 GMT</pubDate>
            <atom:updated>2020-11-23T11:13:56.376Z</atom:updated>
            <content:encoded><![CDATA[<h3>LumApps — Road to React</h3><p>For the last couple of years we have been slowly transitioning our application frontend application from <strong>Angular JS v1 to React JS</strong> while adding several <strong>performance enhancements</strong> to the our application. In the last couple of months we managed to put into <strong>production</strong> our <strong>first fully React JS</strong> frontend page (with the help of our new <a href="https://medium.com/lumapps-engineering/lumapps-a-monorepo-story-da3c4512f564">monorepo architecture</a>)and we wanted to share <strong>how we did it</strong> and the <strong>results</strong> that we have obtained!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SypUifi14ERLPEVgZgldSQ.png" /><figcaption>The sun is setting on our Angular JS application and the road to fully React is now more clearer than ever!</figcaption></figure><h3>A little bit about LumApps</h3><p>If you do not know about <strong>LumApps</strong>, we are a global tech company with R&amp;D teams in France that provides our customers a <strong>SaaS Digital Workplace</strong> solution, which creates a holistic workspace, integrated with several suites and collaboration tools. Want to know a little bit more about us? Head over to <a href="https://www.lumapps.com/">LumApps.com</a> and take a look!</p><h3>Where we needed to improve</h3><p>The migration from Angular JS v1 to React was one of the key and most important subject of our migration. We wanted to use a newer framework that provided us the tools to <strong>fully reuse and compose our UI</strong>, while providing an API that is easy to use and fully handles the complex scenarios that LumApps has on the product level.</p><p>But this was not the only thing that we wanted to fix in our new frontend version. There were other important aspects that needed to be attended to:</p><ul><li><strong>Bundle size</strong> was one of the key performance bottlenecks that we had, since we were downloading a <strong>high percentage</strong> of code that we did not use in our <strong>first render of the page</strong>, or the code that was not used due to features being disabled.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Rznyu9IhWuwIi5GlSygnvQ.jpeg" /><figcaption>We can confirm this is 100% true</figcaption></figure><ul><li>As for our API calls, <strong>our first API call</strong> which retrieves the initial state of the application <strong>was executed from the js bundle</strong>, which meant that we lost some precious time between the HTML was parsed and the bundles were downloaded, where we could potentially retrieve that initial state. Furthermore, we wanted to <strong>remove as many API calls as possible</strong>, since some of the information that we looked up was not needed for the first render of the page.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*C-PSY7Hl_XsbMsUzYWrcmw.jpeg" /><figcaption>Well, maybe not a billion, just a couple more than needed 😅</figcaption></figure><ul><li><strong>Improving our caching strategies</strong> for our bundles, assets and API calls was also another point that we wanted to improve, since many of those resources did not implement the appropriate caching mechanisms that would allow our application to provide a different user experience.</li><li>Setup a series of mechanisms that will allow our <strong>API calls to be executed with a different levels of priorities</strong>, so we can manage that flow of data and allow the non-blocking API calls to be executed at a second stage of the application&#39;s life cycle.</li></ul><h3><strong>How we did it</strong></h3><h4>Split those bundles!</h4><figure><img alt="Homelander from The Boys hovering over a cheering crowd" src="https://cdn-images-1.medium.com/max/464/1*XDfpMF4KTpLlA-EKjQjR3g.gif" /><figcaption>This is how we received code splitting by <strong>page, feature and usage</strong></figcaption></figure><p>For our JS bundles, we decided to take the philosophy of <strong><em>&quot;only-download-what-you-need&quot;</em></strong>.</p><p>Basically, the idea here is to <strong>split our code into different bundles</strong> that will be downloaded only <strong>if the feature or the page is currently displayed</strong>, or if we want that code to be quickly available for the next navigation.</p><p>And in order to make this process simple, we decided to create a <strong>small series of questions</strong> in order to help our the developers during the process of adding code to the page. By answering these questions, you will definitely know how you need to add your code to the application:</p><blockquote>Do <strong>we need the code for the first render of the page</strong>?</blockquote><p>If we do, we need to <strong>add it to the main bundle</strong> of the page, so importing that module will be done as usual, with a <strong>simple import statement</strong>. It will be then downloaded with a high priority.</p><p>If no, then we need to ask ourselves the following question:</p><blockquote><strong>When and where</strong> are we going to use that code?</blockquote><p>If it is code that will be used to <strong>display another page</strong>, we are going to lazily load that code using <strong>React.Suspense </strong>and we will only <strong>download it when we need it</strong>, which will be on navigation. If it is an <strong>extremely used page</strong> (as a in a page that is highly likely to be visited during the user&#39;s session) we can <strong>prefetch the page&#39;s code</strong> so we can have that code already available before navigating without blocking the main render of the page.</p><blockquote>What about <strong>specific features</strong> on the same page?</blockquote><p>This is related to certain features or AB tests that could or could not be there depending on the user&#39;s current configuration. <strong>If the feature needs a certain flag to be enabled</strong>, we should <strong>download the code only if that flag is enabled</strong>. We should also take the same approach with <strong>mobile vs desktop</strong> versions, so if there is a feature that only displays on desktop, we should only download that code for the desktop version.</p><h4>API calls</h4><p>We first took the time to remove or replace the API calls that did not affect the first render of the page, applying the philosophy of <strong><em>“only-download-what-you-need”</em></strong>. Content that would be display upon clicking on a button or opening a dropdown is no longer downloaded with the initial state and only downloaded when that specific data is requested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*8EWtcmsUASX3DHajgxLq3Q.jpeg" /></figure><p>We also <strong>changed the priority of our API calls</strong>, by adding our <strong>initial request directly into our HTML</strong>, thus triggering this request before the JS bundles start downloading.</p><p>And finally, we decided to experiment a little bit with <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback"><strong><em>requestIdleCallback</em></strong></a><strong><em> </em></strong>and allow certain API calls to be executed once the browser has entered an idle period. With this approach, we managed to have the notifications API call as the last API call that we do, allowing other APIs to be executed before it.</p><h4>Caching</h4><p>Finally, we decided to tune our caching policies across the application, from changing several <strong>Cache Control</strong> headers returned from several APIs to creating caching mechanisms on the frontend side in order to save information during navigations or refreshes. We implemented two caching strategies that would save the data in localStorage or in memory:</p><ul><li>If we are using a <strong>slow API </strong>(more than 500ms to respond)<strong> </strong>and if the <strong>data is cold enough, </strong>we started to use a stale-while-revalidate strategy and save the information on localStorage. That way, we can quickly respond and show a cached version of the data and at the same time update the content that we have.</li><li>If we are triggering <strong>multiple times an API call</strong> and response should not change between those API calls, we used a cache-first strategy while saving this information in memory.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*ubYkbwWfpytGev_-nobBPw.jpeg" /></figure><h3>The end result</h3><p>With all of these changes, we managed to obtain some really interesting results:</p><ul><li>We managed to <strong>reduce bundle size by 50%</strong>, passing from downloading 13 files for our first render, to 2 files (with an another additional prefetched file for rendering future navigations) 🚀</li><li><strong>API calls were reduced by 85%</strong> for the 1st render of the page.</li><li>Our new full React application <strong>starts rendering 2.5x faster</strong> than our Angular JS app, with an astonishing <strong>5x faster for start rendering</strong> the page on the second visit 😍</li><li>Also with our <strong>new skeleton and loading state rework</strong>, we are now <strong>2x faster for FCP</strong> and <strong>2x faster for LCP</strong>. This also helped a lot for another Web Core vital called <strong>Cumulative Layout shift</strong>, where our application averaged a score of 0.004 📊</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jj-DX8LyLP3D1TmshX7vKA.gif" /><figcaption>Rendering comparison for the Search page.</figcaption></figure><h3><strong>What is next</strong></h3><p>Even if we have this big milestone already in place, we still have a long way to go when it comes to our migration to React:</p><ul><li><strong>We still have several pages that need to be fully migrated to React</strong>. Today we are redirecting to the legacy application, and we would love to have those pages in our new React application to <strong>improve User Experience </strong>and <strong>keep our users in our SPA</strong></li><li><strong>Maintain the quality</strong> of our new frontend. We are investigating several utilities that will help us maintain the level of performance that our current product has, with <strong>automatic checks</strong> that validate not only the <strong>performance of our site</strong>, but the<strong> use of best practices</strong>, <strong>accessibility</strong> standards and several other key frontend aspects.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee0cc96af26e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lumapps-engineering/lumapps-road-to-react-ee0cc96af26e">LumApps — Road to React</a> was originally published in <a href="https://medium.com/lumapps-engineering">LumApps Experts</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking a monorepo]]></title>
            <link>https://medium.com/lumapps-engineering/mocking-a-monorepo-a5c208e3dd65?source=rss-9c7bea790013------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5c208e3dd65</guid>
            <category><![CDATA[mock]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[json-server]]></category>
            <dc:creator><![CDATA[Juani Galán]]></dc:creator>
            <pubDate>Sun, 22 Nov 2020 11:45:16 GMT</pubDate>
            <atom:updated>2020-11-23T11:04:16.736Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S50m4yiLPy9lrbWUrOUVKA.jpeg" /><figcaption>This is an actual picture of our development envirnoment after we created a mock server for our repo</figcaption></figure><p>With an <strong>increasing amount of services</strong> being created on our backend, our frontend development started to be impacted by how many repos and servers you needed to install locally to get the frontend going. And if we also take into consideration our <a href="https://medium.com/lumapps-engineering/lumapps-a-monorepo-story-da3c4512f564"><strong>frontend architecture rework</strong></a>, we knew we had to take action in order to have a fast and smooth development experience. That is where our monorepo mock server comes in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*gNuVWsOjJ50BiEG2n74i0A.jpeg" /></figure><h3>A little bit about LumApps</h3><p>If you do not know about <strong>LumApps</strong>, we are a global tech company with R&amp;D teams in France that provides our customers a <strong>SaaS Digital Workplace</strong> solution, which creates a holistic workspace, integrated with several suites and collaboration tools. Want to know a little bit more about us? Head over to <a href="https://www.lumapps.com/">LumApps.com</a> and take a look!</p><h3>What we needed</h3><p>Up until a couple of years ago, our frontend application was pretty straightforward to launch in your own development environment to start coding. You executed the frontend and the backend, and that was it! But since the <strong>company and the application have grown exponentially</strong> over the last couple of years, with <strong>new services created</strong> and <strong>new developers coming in</strong> to develop the product, booting the application locally was not that easy as it used to be.</p><p>These new services meant that you would need to configure them in your machine, which not only took time to setup, but also a lot of CPU, thus creating a <strong>really tough combination</strong> for our development environments. We needed a system that allowed us to:</p><ul><li><strong>Remove those services dependencies</strong> for local development and have a <strong>single server</strong> that served the data that the frontend needed for local development, and thus, increasing local development time 🚀</li><li>Create a set of data that <strong>all teams could reuse</strong> in order to develop their functionalities. This meant <strong>sharing that data across teams</strong> and allowing those teams to create their own data sets in order to remove/add configuration for each specific team configuration 🛠</li><li>Have a <strong>consistent set of data</strong> that can be reused for <strong>unit and integration tests ✅</strong></li></ul><h3>How we did it</h3><p>After some research, we found a nifty npm module called <a href="https://github.com/typicode/json-server"><strong><em>json-server</em></strong></a><em> </em>that allowed us to <strong>create a full fake REST API</strong> with really no configuration at all. It is really an <strong>amazing tool</strong>, since it not only allow to mock data and create a server, but it provides a lot of core API functionalities out of the box, which makes this tool <strong>really the next level</strong> when it comes to mocking. With it, we could for example <strong>execute a POST to create a resource</strong> and the next time we do a GET for retrieving the list of resources, <strong>the recently created resource would be there! </strong>It also allows usto create<strong> express js middlewares </strong>that can be used to tweak requests and response, giving us full access to change whatever we want!</p><p><a href="https://www.npmjs.com/package/json-server">json-server</a></p><p>On top of that, we created a small node js file that allowed us to easily manage these mock files on a monorepo. Basically <strong>json-server </strong>needs an json entrypoint where the mock data lives, but since we are using a monorepo architecture, we wanted to <strong>each package to have their own mock data</strong> so they are the owners of that data and furthermore, it allows us to clearly see the endpoints that a package consumes. This node js file is a script executed before <em>json-server </em>and it:</p><ul><li>Goes through each of the packages in our workspace and searches for files named <strong><em>api.json </em></strong>on the<strong><em> _mocks </em></strong>folder and combines all of them into a single file with all the data from each package. It also takes into consideration the other <strong><em>json-server</em></strong> configurations, such as <strong>routes</strong> or <strong>middlewares</strong>, and puts them all together in a single location</li></ul><figure><img alt="A user folder with a subfolder called _mocks and 3 files: api.json, routes.json and user.middleware.js" src="https://cdn-images-1.medium.com/max/230/1*43YX86cIP0dDTPNZiwRDiA.png" /><figcaption>This is how our user package looks like with its own mocks defined</figcaption></figure><ul><li>Writes into a predefined folder those combined files and executes <strong><em>json-server</em></strong> with those files as input.</li><li>This is all executed in a single command <strong><em>yarn mocks </em></strong>which creates the files and then launches <strong><em>json-server</em></strong>.</li><li>We also allowed each module to create different scenarios for their API responses, which we call <strong><em>overrides</em></strong>. Each package can create as many overrides as they want, which are a subset of the data that the API returns, with different values overriden and changed so that the API returns a different scenario. So for example, our API response for our notifications service looks like this:</li></ul><figure><img alt="An API response for our notifications service with the keys items, unread notifications with a value of 5 and more in true" src="https://cdn-images-1.medium.com/max/766/1*9hctDeZBEtTdhUoQ98FL4A.png" /><figcaption>Our notifications service returns a list of notifications to display, how many of them were not read by the user and if there are more notifications to fetch</figcaption></figure><p>But what if we wanted to easily launch a frontend where the user does not have any notifications at all? In that case we create the override <strong><em>no-notifications.api.json </em></strong>that overrides this file:</p><figure><img alt="An API response for our notifications service with the unread notifications with a value of 0and more in false" src="https://cdn-images-1.medium.com/max/744/1*9aA-H94BgbCJm8GLR9anRQ.png" /><figcaption>Override for a scenario where there are no notifications for the current user</figcaption></figure><p>At a folder level, our notifications package looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*7MZwvbX_iMjLRL_roJrWNw.png" /><figcaption>We do have a lot of different scenarios for our notifications center 😅</figcaption></figure><p>And in order to apply those overrides, we just launch <strong><em>yarn mocks -override no-notifications </em></strong>and our node js file will look for the different overrides created on each package with the name <strong><em>no-notifications</em></strong> and <strong>merge deep</strong> their values with the original values of the each API response. This also meant that if there are other packages that want to create an override for the <strong>no-notifications</strong> scenario they can also do that! They just need to create a file called <strong>no-notifications.api.json</strong> in their <strong>_mocks</strong> folder.</p><p>Finally, you can also apply several overrides at once by doing <strong><em>yarn mocks -override no-notifications,admin,no-posts. </em></strong>This will apply those overrides one after the other, overriding each key in the API responses in the provided order.</p><h3>What is next</h3><p>We still need to go through a couple more scenarios that we want to tackle to allow our developers to have a more fluid development experience:</p><ul><li><strong>Automatically create mocks </strong>from a remote backend service.</li><li><strong>Periodically validate</strong> these mocks against a remote backend service in order to check that the API response did not change.</li><li><strong>Open source this small node js</strong> script so those of you out there that are using monorepos and want to reuse this code can do it! Stay tuned for future developments on this subject!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5c208e3dd65" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lumapps-engineering/mocking-a-monorepo-a5c208e3dd65">Mocking a monorepo</a> was originally published in <a href="https://medium.com/lumapps-engineering">LumApps Experts</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LumApps — A monorepo story]]></title>
            <link>https://medium.com/lumapps-engineering/lumapps-a-monorepo-story-da3c4512f564?source=rss-9c7bea790013------2</link>
            <guid isPermaLink="false">https://medium.com/p/da3c4512f564</guid>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Juani Galán]]></dc:creator>
            <pubDate>Sat, 24 Oct 2020 14:39:20 GMT</pubDate>
            <atom:updated>2020-11-23T11:04:19.072Z</atom:updated>
            <content:encoded><![CDATA[<h3>LumApps — A monorepo story</h3><p>Up until last year, at LumApps we were struggling to kick start our migration of our frontend application from Angular JS to React. Fortunately, a superhero called <strong>Monorepo</strong> came to the rescue and helped things take off!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*Qh63WAMpnXkCZPFr0YweCw.jpeg" /></figure><h3>A little bit about LumApps</h3><p>If you do not know about <strong>LumApps</strong>, we are a global tech company with R&amp;D teams in France that provides our customers a <strong>SaaS Digital Workplace</strong> solution, which creates a holistic workspace, integrated with several suites and collaboration tools. Want to know a little bit more about us? Head over to <a href="https://www.lumapps.com/">LumApps.com</a> and take a look!</p><h3>Where we were up until last year</h3><p>LumApps was born about 6 years ago and up until a couple of years ago, it was a <a href="https://en.wikipedia.org/wiki/Single-page_application"><strong>SPA</strong></a> developed only in <strong>Angular JS</strong> by a small team of frontend developers. At the beginning of any project, usually keeping it simple allows the project to move faster and escale quickly, which is what exactly happened with our product. The project was pretty straightforward, you just needed to install the backend and the frontend and you were good to go! <strong>Development was easy and quick</strong> and <strong>time to production was as fast as you could get</strong>.</p><p><strong>As the product grew, the company grew as well</strong>. Other frontend developers joined the team, new customers were added and new features were implemented. So naturally, more code was added and at that moment, we began to look at how our project <strong>did not scale</strong> with the amount of devs that we had, and the amount of code that we needed to create while using <strong>Angular JS</strong>. Managing controllers, templates, models and services was beginning to create a <strong>complex scaffolding</strong> that was not easy to follow and maintain, specially for the new arrivals.</p><p>In order to ease that complexity, an evaluation of the state of the art when it comes to frameworks was made and <strong>React</strong> seemed like a good alternative to start using for our new code, and we thus began our transition to React.</p><p>But in order to make this transition a little bit less violent, we decided to use a react-element-directive that allowed using <strong>React components hooked into an Angular JS application</strong>. And this was where we were last year, with a frontend team of <strong>15 developers</strong>, a code base that had <strong>several technologies intertwined between each other</strong>, complex to find or maintain a feature, <strong>long build and development times</strong> due to the size and lack of scability that the application had (with a backend that had the same issues as well), which ended up <strong>affecting the quality</strong> of the product and the developer experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*3nnssNUpRGuQ2E7McyRvqw.gif" /><figcaption>what it felt to add a React component in our code base</figcaption></figure><h3>We needed a change 😅</h3><p>With that context, we decided to take action and drastically change the way in which we develop our components. In essence, we wanted:</p><ul><li>A <strong>quicker development environment</strong> without the need to launch heavy applications that are complex to configure and take a heavy toll in our computers 🚀</li><li><strong>Clearly separate our code</strong>, encouraging the need for <strong>documentation 📚</strong>in order to allow easier maintenance and higher code quality, and also drawing a clear line between our new code and the legacy one. We also want to <strong>increase our confidence on making a change</strong> into our code base, in order to <strong>increase our quality</strong> and clearly identify the impact of a change and what modules should be double checked.</li><li><strong>Encourage the React migration</strong>, in order to enhance not only the quality of our product, but also our <strong>web performance</strong>, since removing Angular JS would drastically reduce our bundle size, but developing new components in the current environment was becoming a painful task.</li></ul><h3>Monorepo comes to the rescue</h3><p>After analyzing several alternatives, we decided that the <strong>Monorepo</strong> architecture would be a great fit for our use case. What we did was basically use <strong><em>yarn workspaces</em></strong> in order to create a separate folder in our repository called <strong><em>packages</em></strong>, that will hold a set of different modules separated by functionality, where each module would <strong>declare the different dependencies that it uses</strong>, define <strong>what team is the owner</strong>, and <strong>create a standard scaffolding</strong> and a <strong>set of developer tools</strong> that can be executed on each module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*2l36EW3JRj_PinJjQy5hbQ.png" /><figcaption>Basically all of our packages look like this. It&#39;s easy to find what you are looking if you know the route</figcaption></figure><p>For each module, developers are now able to launch a suite of tools that will avoid the huge overhead that they had while developing the legacy application:</p><ul><li>We installed <strong>storybook</strong> and allowed each package to <strong>create stories in order to develop their components</strong>. This removed the need for <strong>launching the backend or even the frontend application</strong> in order to code these components, and allowed the developers to do the heavy coding in an agile and fast environment. Storybook also helped us <strong>to document our project</strong>, by clearly stating the different use cases that our components have and how they should look like in that scenario.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Mp4lS4Dl-9EClD6t8IeitQ.jpeg" /></figure><ul><li>We added <strong>json-server </strong>in order to allow a mocked server to be executed that starts up in a matter of seconds. And with a little bit of tooling, we managed to allow <strong>each package to define a set of mocks</strong> that will be recovered by json-server on startup, and in that way, each package clearly defines the API dependencies that it has and how to mock it, so other packages can profit from it</li><li>The monorepo approached also allowed us to <strong>better manage our unit tests</strong> and allow developers to just execute the tests associated to a specific package rather than executing an entire suite of tests or having to execute tests using paths or expressions. <strong>Just use the name of the package + yarn test and you are good to go!</strong></li><li>We also started coding in <strong>TypeScript</strong>, which allowed us to elevate the quality and the confidence in our product, but also using TS in a monorepo environment proved really handy since <strong>each package defines a set of types</strong> and interfaces that other packages can retrieve and reuse and having that information on a package that you do not know is quite cool.</li></ul><h4>Why did this monorepo approach worked for us?</h4><ul><li><strong>Our base code was still in the same repository</strong> for all of our frontend teams (legacy code included), so that allowed everyone to take a look at how other teams were working, <strong>learn from each other,</strong> but also it helped to <strong>maintain best practices</strong> and modules that are core for the application (like our Design System) in an <strong>easier way than if the code was separated in different repositories</strong>. Moreover, our legacy code was still in the <strong>same place as our new code</strong>, which became quite handy when it came to migrating modules, but also it was <strong>clearly separated</strong> from our packages that you can even only open the packages folder in your IDE and you will never see a single Angular JS line!</li><li>Determine <strong>which packages would be impacted</strong> when a change was made on the codebase became pretty straightforward, since each package defines the set of dependencies that it needs. <strong>Upgrading a dependency across multiple packages is now a simple task, </strong>and we can now see how our modules depend and interact between each other from each package&#39;s package.json</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*u80DSpoD7W3D4tGvlk0tCA.png" /><figcaption>If we ever change lodash or reselect, we know where to look for a possible impact</figcaption></figure><ul><li>The new scaffloding and package oriented development gave us a new perspective when it came to coding components and how they will be used from other ones. Figuring out <strong>what to export, how to export it</strong>, defining <strong>clear and simple props </strong>that would be used by another dev became a great discussion to have will reviewing a PR. This gave us a new quality standard, <strong>one which the Developer Experience mattered</strong>, and one where the way you coded a package could have an impact on another one. It gaves us back that sense of being the same frontend while having clear boundaries and scopes for each team. And defining code owners for each package is great as well when you have a growing team!</li></ul><h4>What did our devs say?</h4><p>So we did a survey after a couple of months working with the new architecture in order to determine if we had taken the right decision of using a monorepo and as well as see if our frontend devs were happy with this change.</p><p>So when it came to the <strong>Legacy</strong> application, our devs thought that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgXck70m59sfZg9s8iJZ2g.png" /><figcaption>Some of the stats related to development on the legacy side</figcaption></figure><p>When it comes to the <strong>New architecture with a Monorepo</strong>, our devs think that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w6tyfcYUNzy1ffX9hjLfSA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PdHs1IEqxGGDIoJZPu4aOg.png" /></figure><h3>What are our next steps?</h3><p>Now that we have a path to React that scales for our current scenario, we are still have a lot of ground to cover when it comes to the migration, since we have many lines in Angular JS.</p><p>Our next goal is to <strong>migrate an entire page in React JS</strong> and start separating our legacy application from the new one. The idea will be to have entire pages on full React, meaning that if a user clicks on a certain link and that link shows a page entirely migrated, we will load a new page that only has React code. We will definitely profit from <strong><em>yarn workspaces</em></strong> here in order to create new packages for our frontend applications. More on that on a next post!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da3c4512f564" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lumapps-engineering/lumapps-a-monorepo-story-da3c4512f564">LumApps — A monorepo story</a> was originally published in <a href="https://medium.com/lumapps-engineering">LumApps Experts</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I like to approach PR reviews]]></title>
            <link>https://juani-galan.medium.com/how-i-like-to-approach-pr-reviews-3b91d26100c9?source=rss-9c7bea790013------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b91d26100c9</guid>
            <dc:creator><![CDATA[Juani Galán]]></dc:creator>
            <pubDate>Fri, 31 Jul 2020 16:07:46 GMT</pubDate>
            <atom:updated>2020-10-11T08:37:33.258Z</atom:updated>
            <content:encoded><![CDATA[<h4>PR reviews are such a huge central part of our daily routines that how you actually approach them can have an impact on the other developers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZE948lJ-K32OkYiZQ9AV3w.jpeg" /><figcaption>Actual picture of you looking at your PR before it is reviewed</figcaption></figure><p>Pull request review is a really popular mechanism that we have today that allows engineers to validate a set of changes that will be applied to the source code, in order to have a verification step before merging them. It is a great step to check for code legibility and maintainability, as well as validating that our code is doing what we expect it to do, and that we are taking into consideration the different variables that could affect that code.</p><p>That is as far as code is concerned, but what about the <strong>people</strong> involved in that PR 🤔? How does that review affect the developer that created the pull request in the first place? Did we ever get a training on how to do these reviews, what to look for and what is the best way to provide feedback?</p><p>Over the last couple of years, I have seen a lot of PR reviews and I have learned the things that I like about PR reviews ❤️, the things I do not like so much about them 😅, and how I like to approach them, hoping that when I create a PR, it will be treated the same way as I did. So here are some of the things that I learned from reviewing and creating PRs.</p><h3>Try not to assume, ask and discuss!</h3><p>I am pretty sure that you have already seen these comments on a PR before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0BDCMvi07MN83YJcTdMvEA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3q6dGz54m1Kh7ZHcuwE8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*liR_tiOU16DyXhcmdmc8hw.png" /><figcaption>(these are real examples, and no, I did not write them 😅 )</figcaption></figure><p>There is a common factor between these types of comments, and it is that the reviewer is assuming why the author did it like that specific changement the way they did it, and that for the reviewer, it should not have been executed like that. As a consequence, the comment can be perceived not only as a harsh critic, which could potentially diminish the work that the author did to have these changes.</p><p>Let&#39;s take the <strong><em>&quot;Adding this function here makes no sense&quot;</em></strong><em> </em>comment as an example on how we can improve it. The comment is stating that a specific function made no sense where it is, but <strong>how does the reviewer really know that it does not make sense there</strong>? Maybe it is a function that could be moved to a utils package on the application, maybe the reviewer saw some potential on reusing that function somewhere else, or maybe they just don&#39;t like where it is 😅.</p><p>But does that mean that the author <strong>did not consider those aspects while they were writing that code</strong>, so they decided to go ahead and add that function there anyway? or does it mean that the author has a larger context on the PR that they are developing and they could have perfectly created that code change as it is for a specific reason 🤔 ?</p><p>Since it is impossible to answer those questions with only the code, I like to approach these scenarios with the philosophy of <strong>ask, rather than assume and command.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AxUzXNtW-PQNUIUbK0bVWw.png" /></figure><p>So in this comment, we can see a different approach to suggesting a change on a PR. The reviewer does not assume that the PR&#39;s author did that change willingly and asks for more information in order to determine the logic behind said change. This could potentially have the following advantages if we compare it with the more <em>&quot;direct&quot;</em> comment:</p><ul><li>Creates an environment where <strong>both</strong> the reviewer and the author can discuss as peers the proposed change, and allows the author to add more detail to the created solution. By opening a discussion with questions rather than orders, the comment is less perceived as a critic and more as reflection on the current solution and whether it could be improved.</li><li>This <strong>allows the author to explain</strong> their train of thought and why they made that change the way they did. Their reasoning could be 100% valid, and maybe it just needed a couple of comments or better naming in order to correctly convey it.</li><li><strong>Junior developers can profit from these types of exchanges</strong>, since it promotes an enviroment where the PR&#39;s author can think about the approach that they took and reflect on their decision making process. Comments like <em>&quot;This is not useful&quot; </em>tend to gatekeep these developers from since they do not have a chance to discuss the changes in a healthy manner, they will just follow that comment like it is an order. And also it sets an example on how we could potentially approach PRs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Y9jUUu7PdrwVd48UqnFPHw.jpeg" /></figure><h3>Review your own PRs!</h3><p>This is one tip that I found really, really useful while working with PRs. Once I have created the PR, I usually take my time to read it and go through the code. By doing that, I can anticipate some of the questions and comments that others may have, and by doing so, accelerate the review process and make my code a lot cleaner and more readable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*3GVScn4bfqMgJEHVfLZ-ag.jpeg" /></figure><p>The idea here is to go through your code as if it was not yours, and review it. While we are developing, things make more sense when we code them, since we are in that sweet spot where we know every aspect of the code we are writing, how it impacts other parts of the code and how it all comes together. But reading just the changes is really another story, and gives you the perspective of what a reviewer will end up seeing!</p><p>So what I do is, I create the PR and while I wait for the CI checks to pass, <strong>I go through my code and do some validations</strong>:</p><ul><li>If there is something on that code that is not extremely clear to me, or if it looks like a complex logic, I will go ahead and commit some fixes in order to make more clearer. Maybe I will add some comments or change the variables names, so I can make sure that the reviewer will clearly understand what I was trying to do and not go through the same problems I had while reading my code.</li><li>If there is something that lacks context (like a function creation that shows up on the changes and later on it is used), I will go ahead and add some comments myself! GitHub allows you to add individual comments to your own PR, which comes really handy when you want to let the reviewer know that something will be used later on, or that you still need to add tests to a certain module, etc.</li></ul><p>This approach will not only give you the chance to look at your code from another perspective, but also learn what things you could review in another PRs with other developers!</p><h3>Add some flavor to your reviews!</h3><p>Last but not least, while I am doing a PR review, I want also to take a moment to celebrate the work that my team mates have done and point out the things that I really liked. PRs are usually filled with comments in order to improve or change a certain code, but we really do not add anything saying <em>&quot;Hey, what you did here, is awesome!&quot;. </em>And in some way or another this feels like the natural thing to do, since it is a <strong>review</strong> 😅 Usually in reviews you say the things that you did not like about something and you also comment the things that you really liked. Why do we not take the same approach for PR reviews?</p><p>So whenever you are doing a PR review, think about the things that you liked, not only the things that you thought they could be better. If you see something cool, something that caught your eye and made you say, <em>&quot;hey, this is actually pretty good&quot;</em>, just add a comment and make the PR&#39;s author know! Take advantage as well of the possibility to add a message once you have approved a PR. Take that moment to celebrate and encourage the author to keep up the good work!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*j3UigSePUTBWEHCOiD7Fkw.jpeg" /></figure><p><strong>And add some Gifs or emojis while you are at it!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b91d26100c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(Don't Fear) the components]]></title>
            <link>https://itnext.io/dont-fear-the-components-754babc5db77?source=rss-9c7bea790013------2</link>
            <guid isPermaLink="false">https://medium.com/p/754babc5db77</guid>
            <category><![CDATA[reusability]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[maintenance]]></category>
            <dc:creator><![CDATA[Juani Galán]]></dc:creator>
            <pubDate>Sun, 19 May 2019 02:14:35 GMT</pubDate>
            <atom:updated>2019-05-20T12:09:15.376Z</atom:updated>
            <content:encoded><![CDATA[<h4>Quick example on how a refactor to your components can make your life so much easier!</h4><p>I have been working with React over a couple of years now, and over those years, I have noticed that there is a development life cycle ♻️ that tends to repeat itself for each component. We create a simple component on a single file, with no more than 30 - 40 lines of code where you define how it works, its internal state and how it is rendered to the end user. You also create a test file, where you test the logic that you implemented, passing different props and seeing how your component behaves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*mP2WbuRRt49uNG3d1J-ZJw.png" /></figure><p>Up until now, everything looks great! Your component is reusable, has tests of its own and it takes care of a simple task. But then, a new feature arrives and we need to add some code to it. We add those changes, we adapt our styles and tests to match them, and voilà! Our component displays this new cool feature 😎😎 and we still have it encapsulated in a single file within a single component.</p><h3>The Snow Component Effect</h3><p>However, we know that it does not end there. New features arrive all the time, and a component that used to be 40 lines of code becomes a really complex file with over 500 lines of code taking care of multiple responsibilities, and our tests and stylesheets start to suffer from the same symptom. I call this the <strong><em>snow component effect </em></strong>❄️❄️<em>, </em>where we keep on adding code and features to a component, and it then becomes this monster that haunts us throughout our releases 👻👻</p><p>So how can we minimize this effect? What things do we need to keep an eye on in order to detect these scenarios? And how can we refactor our code to keep the <em>snow component effect</em> at bay?</p><h3>A practical example</h3><p>I decided that it would be best to take a look at these scenarios through a series of code examples that illustrate how a simple component can escalate real quick and what code smells arise that tell us <strong>&quot;hey, maybe we can move this to another component!&quot;</strong>. These code smells 👃👃 do not mean that you are doing something wrong, they are just pointers that can <strong>help you to figure out if what you are doing makes sense for your current scenario, and maybe detect that there is a better approach!</strong> The idea behind all of this is that the <strong>code makes sense for you and your team</strong>, and that the decisions you are taking will not tie you up in the future.</p><p>Therefore, I created a small web that displays the latest PS4 games, showing a title, an image and a link to the game itself:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nho77MQ5bZPlzMlI7QXB9Q.png" /><figcaption>These are in my opinion the best games of last year, but God of war is the best</figcaption></figure><p>Taking a quick glance at the component, we could say that it looks simple enough right 🤔🤔? Our component should expect a list of games, each of them with a title, a source for the image and the link to redirect, and we will iterate through those games and create the link tag and the image tag for each of them:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1220420a784ed8da519cff64690aa47/href">https://medium.com/media/a1220420a784ed8da519cff64690aa47/href</a></iframe><p>As simple as it looks, we can already identify a couple of things that should raise some questions regarding our logic:</p><ul><li>We are passing a games list to our component, so in order to check that each game has the correct information, we created a prop type validation that checks for the prop <em>games </em>to be an array with a specific shape, which is already starting to look like a small snow ball. <strong>Does it make sense to validate the game&#39;s information on the component that renders a list of them?</strong> Should the component that renders a list of games validate the information of each game, or should it only take care of how a list of games is rendered, no matter what the game has?</li><li>What if we want to render these games in a different manner, maybe using ordered lists or just plain divs? Is the rendering of a specific game tied to the fact that there is a list of them? <strong>What if we want to render a single game in a non-list context?</strong></li><li>We have created two base class names for our components, one called <em>&quot;games&quot;</em> which we are using for all of our elements that are related to the list of games, and <em>&quot;game&quot;</em> for everything related to the game itself, and we are using one or the other depending on the element. This is already showing us that styles and class names have a different base depending on what we are rendering. <strong>Does it help us to have these class definitions on the same file?</strong> What about stylesheets? Does it make sense to have styles for &quot;<em>games&quot;</em> elements and <em>&quot;game&quot;</em> element on the same file?</li></ul><p>Now imagine that we released this component as is, and a couple of weeks later new requirements arrive:</p><ul><li>We want to add some visual distinction to the games that we consider featured, maybe a border outline of some sort, just to capture the user&#39;s attention towards these games</li><li>We also want to show what games are not available, maybe due to out-of-stock situations, and we want to prevent users from clicking on it.</li></ul><p>From a data standpoint, it makes sense to add some flags to each game, maybe something like <em>isFeatured</em> and <em>isAvailable. </em>But what happens to our component? To tackle these requirements, we will add specific css classes to our component in case the game is featured or available, and also prevent the click on the link if it is not available.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91609a5cae7a274143e5d4fe8b0e78e2/href">https://medium.com/media/91609a5cae7a274143e5d4fe8b0e78e2/href</a></iframe><p>This new requirement has added some key changes that should also start a discussion:</p><ul><li>We added the prop types for isAvailable and isFeatured on the arrayOf definition. But these are new props, and it could take sometime for the consumers of this component to adjust to these new props. So in order to avoid showing Prop Type warnings as well as resulting in unexpected behavior, we want to default to a specific value. Since these are booleans, it should be easy enough, so let&#39;s say we will default to isFeatured = false and isAvailable = true. But taking a look at the example, how can we actually achieve that? We currently have an arrayOf a shape, how are we going to write our default props? <strong>Should default props for an object depend on the data structure that holds it? </strong>We could achieve that by creating a specific default function for these props, but we would be mutating the array, which can result in unstable behavior.</li><li>Changes related to these features are now directly tied to the component that renders the list of games. If sometime in the future, these css classes change, or we need to add a new variety, we will always comeback to the games component. Here we could ask ourselves, <strong>does it make sense for functionality related to iterable objects live beside the component that iterates them?</strong></li><li>Also let&#39;s take a look at the test for this component. We will need to define different arrays in order to try out the original requirement plus how the game is rendered when it is featured and when it is available:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f795a24d0cd7e1c864b7663eb2931704/href">https://medium.com/media/f795a24d0cd7e1c864b7663eb2931704/href</a></iframe><ul><li>Should the games component really care if the games list has some featured games and some available ones? <strong>Should this component test edge cases that are related to the iterated objects?</strong> Aren&#39;t they more tests cases related to the game itself? If we want to test the click on the link and see that it trigger the preventDefault function when the game is not available, does it make sense to test that on the Games component test?</li></ul><h3>One possible solution</h3><p>Up until now, we have seen that there are a couple of decisions that we made make the Games Component and each game itself really coupled between one another. But what if we separate these pieces, and create another component for the Game itself?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8fa5e8f0bcc3e2715cb062513eabf20/href">https://medium.com/media/d8fa5e8f0bcc3e2715cb062513eabf20/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dca20539dbf80989df3cf3684362e602/href">https://medium.com/media/dca20539dbf80989df3cf3684362e602/href</a></iframe><p>So we have created two separate components, one called Games and another one called Game. By doing so, we have several advantages that come from it:</p><ul><li>The most noticeable is that the Games component <strong>has turned into a much smaller and simpler component</strong>. It is easier now to read and maintain, and tests will only need to pass and test scenarios related to the games prop and the title prop. <strong>No need to create edge cases for the game specific functionality.</strong></li><li>Namespaces used for classes are now separated between the two components, making our classes independent from each other. <strong>Separating these components also allow us also separate our styles</strong>, maybe creating separate files for each component.</li><li>Game props are directly validated on the Game component, not in the Games component. <strong>The Game component is actually the one that states what things are necessary for it to render</strong>, and are not tied to the data structure that holds them. Also, <strong>we can declare those default props</strong> for isAvailable and isFeatured, setting the default behavior directly in the Game component.</li><li>We have also made the Game component independent from the context in which it renders. Previously, there was no way to render an image outside of a list. Now, we can use the Game component wherever we want, in a list, individually, or in another way. <strong>When separating components, we can extract the functionality and increase our reusability.</strong></li><li>Finally, <strong>testing has become much simpler and targeted</strong>, since for example, testing related to the featured and availability functionalities are directly tested on the Game component, and the Games component does not know about this. In the future, if there are further changes to the game component, we will add the appropriate tests to that suite, and our Games component will still be agnostic to this.</li></ul><h3>To sum up!</h3><p>There is definitely a breaking point when developing React components when our components pass from a maintainable and reusable piece of code to a big complex component that englobes a lot of functionality. This at first can seem simple, but later in the development process, iterations and new functionality can turn these components into a snow ball, each time adding more and more code that becomes this massive structure that everyone is scared of getting hit by it.</p><p>In order to avoid that, take sometime to think through where each functionality should live, and if it makes sense for it to live in a particular component, or maybe migrating to another one will save you sometime in the future. Try to see what helps your code be more maintainable and readable, and I hope that these pointers I found can give you an idea of what questions to ask when you are writing React components :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=754babc5db77" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/dont-fear-the-components-754babc5db77">(Don&#39;t Fear) the components</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Primer Workshop JS en Montevideo!]]></title>
            <link>https://juani-galan.medium.com/primer-workshop-js-en-montevideo-a1c1df0e3f0?source=rss-9c7bea790013------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1c1df0e3f0</guid>
            <dc:creator><![CDATA[Juani Galán]]></dc:creator>
            <pubDate>Sat, 16 Feb 2019 21:17:28 GMT</pubDate>
            <atom:updated>2019-02-16T21:36:35.651Z</atom:updated>
            <content:encoded><![CDATA[<h3>First Workshop JS in Montevideo!</h3><h4>On May 26, we held a React JS workshop in Mercado Libre!</h4><p>In recent years, in Mercado Libre, we have begun to use new technologies in all our frontends. It has been a long way, but now we have a <a href="https://www.youtube.com/watch?v=huH_TyPDBpU">Frontend technological Stack</a> that has the following components:</p><ul><li>Node JS as the server for our frontend applications</li><li>React JS for our client-side code</li><li>Webpack</li></ul><p>With this new adoption, it has really been a change in our way of working and developing. We have substantially lowered the development, generation of versions and deployment times, as well as installation and testing times. It has been a great success for all of us who developed frontend in Mercado Libre!</p><p>And for this reason, we decided that it was a good opportunity to start promoting the use of these frontend technologies in the community in Uruguay, and that is why we organized one of the first JS workshops in Montevideo.</p><h4>From scracht!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/0*pUWEy1u8kCi7g_hs" /></figure><p>We wanted to start the beginning, so that anyone who is really interested in frontend can join the event and learn a little about these technologies. With this in mind, we decided to hold the workshop on React JS.</p><p>React is a library developed by Facebook, oriented to the development of components. It seeks to create visual units independently so that later these components can work together creating more complex applications. This approach is very important for us, since one of our objectives when developing frontends is that Mercado Libre maintains a visual coherence throughout the user experience, and with React JS, it is very simple and fast for us to share different components in order to maintain that coherence.</p><p>With all this, with <a href="https://twitter.com/martinvarelaaaa">Martin Varela</a> we decided to put together an event where the community could get closer and learn a bit of this technology, to have the basic concepts and be able to promote the use in their companies or in their personal projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*00tI8oMAWw9XLqk-jkxkvQ.jpeg" /></figure><p>his workshop was held on May 26 and the places to come quickly sold out. About 40 people came to the Mercado Libre development center in WTC in the Buceo zone in Montevideo.</p><p>During the workshop, we carried out a dynamic that interspersed theoretical aspects with practical ones. Our idea was to give a workshop where you can quickly apply the concepts seen, in order to increase the understanding of them. Making this approach, we set up a practical exercise where each person had to make a list and a search engine of Mercado Libre products, which we were building in each stage using concepts seen in the practical part.</p><p>At the same time, <a href="https://workshops-js-montevideo.gitbook.io/react/">we created a practical/theoretical material</a> that served as a guide to perform these exercises, as well as allowing people to follow the workshop in a more detailed manner and with code exercises. This material allowed them to see examples and have a knowledge base to which they can return.We used the wonderful tool of GitBook to make this material.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WrK1YWVt54gCovcQdyveKQ.jpeg" /></figure><p>The workshop was a success, all those who joined contributed a lot and in general terms, we received very good feedback from the workshop, since 100% of the people commented that they would return to another.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5QwvldAX4CmFtAij2s29kQ.jpeg" /><figcaption>Juani Galán explaining a little bit about React</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7zO1cV3IkpAKmeUoiQg4GA.jpeg" /><figcaption>Martin Varela throwing some ideas!</figcaption></figure><p>We want to thank all the people who came to the workshop as it was a great experience and we hope that they left wanting to know a little more about these technologies, as well as the way in which we apply them here in Mercado Libre.</p><p>We also thank all the people in Mercado Libre who helped us organize the workshop!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1c1df0e3f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Battle of the Colors]]></title>
            <link>https://juani-galan.medium.com/battle-of-the-colors-e1c333098c41?source=rss-9c7bea790013------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1c333098c41</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[rgb]]></category>
            <dc:creator><![CDATA[Juani Galán]]></dc:creator>
            <pubDate>Sat, 18 Aug 2018 22:38:17 GMT</pubDate>
            <atom:updated>2018-08-19T20:36:31.557Z</atom:updated>
            <content:encoded><![CDATA[<h4>Rendering search filters in eCommerce websites have always been a real tricky subject, and the Color filter is no exception!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*FJ-tszjKsGZKkhZ9bThAEg.png" /><figcaption>Implementing this guy can get real tricky real fast!</figcaption></figure><p>Search filters are one of the most important aspects of eCommerce websites, allowing our customers to refine their results and find what they are really looking for. In order to do that, we usually try to make these filters as useful and usable as possible, since we want them to be really helpful and provide a great experience for our customers. From a frontend technical perspective, the filters design can turn into a complex problem to resolve, which can impact both usability, maintainability and performance of our search result pages.</p><h3>Our contestants</h3><p>After doing some research through the most popular eCommerce websites, I was able to categorize those implementations into these groups:</p><ul><li>Sprites with dynamic styles: images are used to display colors, which are located on a sprite and later each color rendered has an inline style that sets the background-position to the corresponding color.</li><li>Inline styles: background color for each option is set via inline styles with a background-color property to the corresponding HEX or RGB color</li><li>Css class based: css classes are defined for each specific color, with a specific naming convention. On rendering, that class is added to each color filter option, which then links to the css class, and their respective RGB or HEX color.</li></ul><p>Once I got the the most popular implementations, I decided to recreate them in a simple environment, with the idea to evaluate the following:</p><ul><li>Performance: How each alternative affects the size of each dependency of the page, as well as the time for the page to complete load, doing a specific focus on the Critical Rendering Path</li><li>Maintainability and scalability: we need to consider how the implementation will affect us in the future, in case we need to edit the colors in any way, or maybe change the entire filter</li><li>User experience: It is very important that we take into consideration how the final version affects our users and how they will use our filter, and how the interaction with this filter can increase conversion and return rates.</li></ul><p>For the implementation itself, I wanted to create a free external dependencies scenarios, in order to have a website where there would only be the html, with the css and images dependencies, with no js on the client side. In order to achieve that, I created three separate html files which each alternative.</p><p>To test this, I created a <a href="https://github.com/juanigalan91/battle-of-the-colors">repository on GitHub</a> with these three html files, and I accessed them via GitHub pages:</p><ul><li><a href="https://juanigalan91.github.io/battle-of-the-colors/dynamic/">Dynamic Alternative</a></li><li><a href="https://juanigalan91.github.io/battle-of-the-colors/sprites/">Sprites Alternative</a></li><li><a href="https://juanigalan91.github.io/battle-of-the-colors/static/">Static Alternative</a></li></ul><p>Also, to evaluate all these aspects and try to determine a difference between the alternatives, I used Lighthouse Audits with <a href="https://developers.google.com/web/tools/chrome-devtools/network-performance/network-conditions">Throttling Applied Fast 3G, 4X CPU Slowdown</a> from the Google Developer Tools, for evaluating the performance and cost of each implementation.</p><h3>Fight Highlights</h3><p>Without further delay, here&#39;s the results for each alternative.</p><h4>Sprites with dynamic styles</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2sH0-V5OTb4_RD3CFjVHCw.png" /><figcaption>Performance audits for Sprites alternative</figcaption></figure><p>So in rendering terms, the sprites alternative took 860 ms to render the first content on the browser. In this case, it would be the texts for each color and also the title. Since we are showing these colors using an image, the request to retrieve that image does not block our rendering, so the browser can show the names of each color before showing the actual block with the color.</p><p>This is actually a good thing, since this approach allows us to render something meaningful (like the audit said) to the user, which ends up enhancing the experience that they have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/136/1*9JT045jrg2y05-z2Hy7xqA.png" /><figcaption>Which one would you say that includes the red you are looking for?</figcaption></figure><p>Plus, with images you can provide a filter that is more detailed and precise, and represents what they are really searching. Imagine searching for a red shirt, but you are not quite sure what specific tone of red you want. Maybe an image displaying a palette of reds will make you as a user more confident that what you are looking for is in that area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*rARdM80S-X2Z2q8quUih9w.png" /><figcaption>Sizes of each resource</figcaption></figure><p>On the other hand, we obviously need to fetch the sprite containing all these images for each color and that adds loading time and costs. And that affects the <em>load </em>event been triggered, since this won’t happen until that image is downloaded, which ends up making the crazy spinner that you see (and every user sees and worries about) on your browser’s tab spin a little big longer. That’s why the Speed Index (how fast the page is visible) and Time to Interactive (time when page is fully interactive) happen 400ms after First Contentful Paint, because the page is not fully loaded yet. However on the next request, you will have this image cached by your browser.</p><p>Furthermore, taking this approach without considering what colors are really shown when searching on a specific category or filtered list can result on sending really big sprites to the frontend, and maybe end up using 2 or 3 of those colors, since the items that you are displaying do not have all the colors on your sprite.</p><p>Plus, if you have a different image for different states (hover, selected), that sprite will duplicate in size, which will add up to the overall size of your application. You can definitely create several sprites for different scenarios (maybe by category) but it will take some operation time to do this and maintainability for this scenarios will be some hard work.</p><h4>Dynamic Styles</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COJSRSgYuZmdd-p5PPWV4Q.png" /><figcaption>Performance audit for dynamic styles alternative</figcaption></figure><p>With dynamic styles, we can see that the First Contentful Paint takes around the same time as using sprites. However, when we show the user content, we automatically display the names of each color with their corresponding RGB. We can see this by analyzing the Speed Index and Time to Interactive ms, which are faster than the sprite scenario. This means that the site could be considered more interactive, since the time that the browser takes to display the full content of the page is faster, and we allow the user to interact with it in less time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*r1ksmyhXaEkbMUElD-k_1w.png" /><figcaption>Size of the HTML for dynamic alternative</figcaption></figure><p>The size of the HTML is a little bit smaller for this alternative, since the css needed to set a background-position is longer that setting a background-color. But the difference here is less than 1KB, so it would not be a big impact. Plus, since you are only bringing to the frontend the colors that you are going to use, the more specific the filter is, the more bytes you will save, because that color list will probably get smaller and smaller. However, this approach does not scale when you have several color filters on your website, like primary and secondary colors. This is because each filter will be rendered with its own inline css, which will make some css to repeat itself.</p><h4>Static Styles</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zLLv1ZlHBgC41NHWqYlvJw.png" /><figcaption>Performance for static styles alternative</figcaption></figure><p>As we can see for this alternative, all metrics take considerably more time than sprites and dynamic styles. This is due to the fact of the presence of the stylesheet, which blocks the rendering of the page until it is loaded. We even have a note from Lighthouse regarding that stylesheet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Gl-E__gackkiOcDOVQ3Uw.png" /><figcaption>Stylesheets make our critical rendering path longer!</figcaption></figure><p>In this scenario, not only did we have to download the HTML to render the page, but also wait for the css to be downloaded so then they can be processed and rendered. Moreover, the stylesheet used will potentially have all the colors that you need, which will result in the browser not using a percentage of that file, since not all the colors could be present. On the other side, the file will be cached by the browser, so the next request will be much smoother. And also if you have several color filters on your site, it will be useful to have all colors centralized in one file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*ZDVy3iUbYUglc7XsN1mkRw.png" /><figcaption>Sizes for each file.</figcaption></figure><p>From a maintainability stand point, adding new or changing colors will result in generating a new stylesheet and deploying, as well as adding or changing the classes that we have created to map colors to their rgbs. Plus, this creates a new dependency, since the way that we have to associate colors to their rgbs is by naming convention, which usually ends up being the ID of the color. If that ID also changes, we need to update the stylesheet as well.</p><h4>And the winner is…</h4><p>Taking a look at the options, we can say that there is actually no winner, but a more suitable approach for a specific scenario.</p><p>If you are very focused on how the user perceives your website and want to provide a very customized experience, with different color flavors and patterns depending on what you are seeing, definitely using sprites is the option for you. But beware, you will need to take into consideration that creating those sprites and the css to set the background position could take some time!</p><p>If your website targets mainly mobile devices and you want to deliver as little as possible to the end user, then dynamic styles will definitely fit your scenario. It will allow you to download only what is needed, which will save both processing and loading time, as well as overall costs for your application. Also you can leverage this possibility by displaying a small set of colors on your filter, maybe the most popular ones, and then allow the user to see more. Once that happens, you can do an AJAX request to retrieve the full list of colors, which will come directly on the HTML.</p><p>And to finish up, if you have a simple scenario where you only would like to show a simple color filter with no custom logic or different flavors, going with the static alternative will suffice for the moment. You can also leverage this technique when building Single Page Applications, since styles will be downloaded only once and will be useful during the entire time the user is navigating your application. However do take into consideration that this alternative can bring some headaches in the future if your application grows.</p><p>Hope you enjoyed this article! If you liked it, leave a clap or a comment, I would love to hear some feedback!</p><p>If you want to learn more about Critical Rendering Path, I suggest you take a look at the free course in <a href="https://www.udacity.com/course/website-performance-optimization--ud884">Udacity about Web Performance Optimization</a>. I took it to have a little bit more background for this article and loved it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1c333098c41" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is there a price to pay for using exceptions?]]></title>
            <link>https://juani-galan.medium.com/is-there-a-price-to-pay-for-using-exceptions-17fa4982fe75?source=rss-9c7bea790013------2</link>
            <guid isPermaLink="false">https://medium.com/p/17fa4982fe75</guid>
            <category><![CDATA[exception-handling]]></category>
            <category><![CDATA[exception]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Juani Galán]]></dc:creator>
            <pubDate>Sun, 29 Jul 2018 19:30:01 GMT</pubDate>
            <atom:updated>2018-07-29T19:30:01.320Z</atom:updated>
            <content:encoded><![CDATA[<h4>Have you ever wondered how exceptions start to shape and have an impact on your project? Are they useful? Do they affect performance in anyway?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykfNuCR44rRM0SYAprBYXg.png" /><figcaption>Sometimes exceptions can be thrown from the smallest operations!</figcaption></figure><p>During a recent class at my University there was a specific discussion related to exceptions and how they can take a toll on your project. Most of the conversation involved arguments about how exceptions work, when are they useful and how they affect your project, from several perspectives; code readability, coupling, performance and overall usefulness of exceptions. I wanted to explore this idea a little bit and see what implications exceptions have when you start using them.</p><p>In my experience, exception handling is a very vast and discussed topic, with several different opinions on it, which usually are formed due to each individual’s personal experience. I have seen programmers doing extensive and defensive code by doing a try/catch for every single operation or method execution, to surround everything in a big try/catch with one exception handling, to nothing at all.</p><h4>Is exception handling useful?</h4><p>Yes, it is very handy in scenarios were you are accessing specific resources that can fail in a critical way, for example, accessing a database, an API call, opening a file, etc. These situations will eventually fail, due to a timeout, a resource cannot be found, you did not comply with a specific rule in your database such as a foreign key or a required field, or an unexpected error. And exceptions allow you to recover from those scenarios and show something to the user, an Error Page, a Page not Found, a “Sorry, try again later”. Something meaningful that will let the user know that something went wrong, and not just have their window or browser closed or frozen.</p><p>Exceptions are very useful as well when you are developing libraries that are meant to be used by other teams or if you want to contribute to open source. Usually people don’t take the time to read how a specific library works, and they just use it. If there is something that they missed, throwing an exception would be a great way to educate them and control how they interact with your library.</p><h4>But sometimes, could it be a little bit too much?</h4><p>On the other hand, we have other scenarios were using an Exception would be a bit of an overkill, since you maybe could solve that scenario by other simple control structures.</p><p>Take the following example: You have a class called <em>Employee</em>, that has a constructor that accepts 1 parameter, a name. Imagine that name is required, and you cannot create an Employee without a name. So you decide to implement a custom exception, that when <em>name == null</em>, you throw this exception to anyone who wants to use it, which we are going to call <em>EmployeeException</em>. This would imply that:</p><ul><li>Every part of your application that wants to create an employee, would need to surround the code in a try catch to catch that specific error</li><li>Every part of your application would have a dependency to both <em>Employee</em> and <em>EmployeeException</em>, which would increase coupling that could lead to maintenance problems in the future.</li><li>The try/catch would be a little bit confusing, since you would be throwing an <em>EmployeeException</em>. Was it because the name was empty? or did I have to set other variables as well? Or the name needs to have a specific format? Obviously you can change the name of the exception to something more understandable, but if you are working in a team or using an external library, and someone else coded that Exception, it could lead to confusion. And imagine if there are several errors that could throw that Exception? Would you create a custom exception for each of them? That could lead to increase more the coupling between your project and Employee.</li><li>It could have an impact on performance (I will explain this later on)</li></ul><p>We could potentially resolve this by adding a static method to the Employee class that from a specific set of parameters, returns a boolean that shows if the Employee can be created or not and that would help with the points I stated above. This would be one of those alternatives to exception handling, validate inputs and create validation methods.</p><h4>And how about the performance of my application?</h4><p>For this discussion, I thought that I could take a more practical approach. So I created a simple Java Project that does follows the Employee scenario that I mentioned before. Basically we create an <em>Employee</em> with a <em>constructor(String name)</em> and we throw an exception if name is null. And we do the same but we add an <em>isValid</em> method to check before creating the <em>Employee</em>. I tested this using a for loop and running the constructor several times, because in order to see a difference in time execution, I need to create more than 1 Employee. So I tested the following scenarios:</p><ol><li>Create an Employee with name = null and surround it with a try/catch.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*sIDRsSD4fXlyLk6xjbpFaw.png" /></figure><p>2. Create an Employee where half of them will throw an error and half of them would pass and surround it with a try/catch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*k9vp8AlzWKKAN0jSMB4_LQ.png" /></figure><p>3. Create an Employee where half of them will throw an error and half of them would pass and surround it with a try/catch, and also on the catch, I execute ex.getStackTrace(), just to simulate exception handling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kdxCsL-gupEPVYk2U4lGyg.png" /></figure><p>4. Create an Employee where a fifth of them will throw an error and half of them would pass and surround it with a try/catch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*9zW2G9WHJAtHC2Y9YJa8bA.png" /></figure><p>5. Create an Employee with name = “test” and surround it with a try/catch, but since it is a valid name, no exceptions are thrown</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*Q1woxbxyvhT94yn-6Pvj1w.png" /></figure><p>6. Create an Employee with name = “test”, but before I executed an isValid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*IIL6bw5QDs9Ewlx5Uck-rg.png" /></figure><p>I executed these scenarios with <em>total</em> set in 100, 1000, 10000, 100000, 1000000. And here are the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*25VRTyIoG7eiTbby1mTu0g.png" /><figcaption>Execution results. Times are in ms.</figcaption></figure><ul><li>For i = 100, there is not much of a difference, executions take from 0 to 1 ms</li><li>For i = 1000, scenarios 1, 2, 3 take 3 times more than scenarios 4, 5, 6. This starts to give me the idea that handling an exception takes more time. Furthermore from number 5, we can notice that adding a try/catch block does not slow down performance, if no exception is thrown.</li><li>For i = 10000, scenarios 1, 2, 3 take 16 to 23 times more than the other scenarios</li><li>For i = 100000, it sky rockets to 136 ms and 154 ms for scenarios 1 and 3, and 5 ms and 4 ms for scenarios 5 and 6.</li><li>For i = 1000000, scenarios where exceptions are thrown and managed can take up to 1 second.</li></ul><h4>To sum up!</h4><p>Overall, we can say that exceptions are obviously one of the pillars for programming languages. They enable us to recover from several critical scenarios and allow us to convey that information to the user. Moreover, it allows us to track these errors on the catch part, so we can learn from these errors and iterate our project to prevent them.</p><p>On the other hand, we need to take into consideration that exceptions are not only affecting the end user, but also the developer. Custom exceptions can lead to problems with code maintenance, readability and performance. I would say that it is more of a case-by-case analysis, sometimes they can be quite helpful, but in other scenarios it could lead to some headaches! Just make sure you give a little bit of thought before introducing exceptions into the mix.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17fa4982fe75" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>