<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jean Paul</title>
    <description>The latest articles on DEV Community by Jean Paul (@jeanpaulyps).</description>
    <link>https://dev.to/jeanpaulyps</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F578362%2F5d72a934-d9a0-4571-a6c0-89700b6a2066.jpeg</url>
      <title>DEV Community: Jean Paul</title>
      <link>https://dev.to/jeanpaulyps</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jeanpaulyps"/>
    <language>en</language>
    <item>
      <title>Developer Weekly Blog #4 - Playwright</title>
      <dc:creator>Jean Paul</dc:creator>
      <pubDate>Wed, 29 Nov 2023 15:01:37 +0000</pubDate>
      <link>https://dev.to/jeanpaulyps/developer-weekly-log-4-playwright-jje</link>
      <guid>https://dev.to/jeanpaulyps/developer-weekly-log-4-playwright-jje</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This week I learned about Playwright, this is a tool to do different types of testing like: automating testing or visual testing on your web applications. What I like about this library is that it needs almost 0 configuration and you already have a lot of tools ready out of the box to create your tests, like a tool that helps you to create your own tests called codegen, when you initiate your project automatically create a pipeline that is easy to use in your pipeline, it allows you to create visual tests for your app and you’re able to run the tests in various browsers. And using this tool I realized that this was an ideal solution for a problem that I had back in the past and I want to share this experience with you.&lt;/p&gt;

&lt;p&gt;I was writing tests on React Testing Library, a tool to create unit tests for components. At some point I abused this tool, using it in moments where I shouldn’t, creating long tests, those tests started to become flaky tests (tests that sometimes succeed or failed with no changes on the code.) Why were they failing may ask yourself? Because due to how it works this tool, it emulates a browser and sometimes as we were refreshing so many things a lot of times happened that doesn’t reach to the point where the changes were reflected on the emulated browser and the test failed.&lt;/p&gt;

&lt;p&gt;It would be nice back then to have the possibility to write some tests in Playwright because they would be more effective and accurate than my long and ineffective tests written in Testing Library. But this is not the only reason that I would recommend to use it on your projects, also is easy to use, has a lot of ways to debug your tests, it has a tool that helps you to create your own tests called codegen, is easy to deploy, you can create visual testing and you’re able to use it in various browsers. Now that I list you some of the reasons why I love this tool it’s time to see how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is important to include automating testing
&lt;/h2&gt;

&lt;p&gt;Automating testing is so important in your workflow because this allows you to make changes with the confidence that this doesn’t break anything extremely important on your app. Have you ever made a change and feel the stress and anxiety of something breaking? So where does this insecurity come from? I think more than impostor syndrome as an answer, is that it is not always possible to check all the scenarios where your change is going to be reflected. And it is impossible that your app works fine in every case, but you’re able to make your app work fine most of the time. But how to ensure nothing breaks?&lt;/p&gt;

&lt;p&gt;You possibly can test every time you make a change but a good way to ensure repetitiveness is through automated testing. And to better understand the benefits of doing it I refer to &lt;a href="https://abseil.io/resources/swe-book/html/ch11.html#the_story_of_google_web_server"&gt;the story of Google Web Server&lt;/a&gt; that illustrates how automated testing improves productivity  confidence on changes and  the reduction of numerous bugs. Using this practice you ensure the changes don't break some important behavior, reduce stress, reduce uncertainty, keep application flexible and easy to change overtime and increase confidence on your team. When the test succeeds you deploy with confidence.&lt;/p&gt;

&lt;p&gt;So I want to share information about this tool that allows you to write this kind of test in an easy way with low configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started with Playwright
&lt;/h2&gt;

&lt;p&gt;To install Playwright you need to have Node 16+ installed, and get Playwright through the command &lt;code&gt;$npx playwright install&lt;/code&gt; this will get the browsers to run your tests (Chromium, Mozilla and Safari). After that you’re able to use the commands that Playwright includes to run your tests and complementary tools to create your tests. If you want to add the configuration to an existing project use &lt;code&gt;$npm init plawright&lt;/code&gt; this creates some files in your project but the most important is &lt;code&gt;playwright.config.ts&lt;/code&gt; that allows you to change the default configuration and indicates that Playwright is being used in this project. From there it is just a matter of creating your tests, to do it create files with the extension &lt;code&gt;.spec.ts&lt;/code&gt; on the test folder and run them with &lt;code&gt;$npx playwright test&lt;/code&gt;. And see the results with &lt;code&gt;$npx playwright show-report&lt;/code&gt;. With those steps you’re ready to create more tests in your existing project. Let's see what it is like to create a test. &lt;/p&gt;

&lt;p&gt;The first thing you need to take into account is that you're using a real browser. If you're familiar with other UI testing libraries, you'll find a lot of similarities between them. However, since you're using a browser, there are some functions like changing accessing a different URL, something not available in other UI testing libraries like React Testing Library. With that in mind, how does a test in Playwright looks? A test in Playwright is mostly composed of 3 main instructions: &lt;code&gt;goto()&lt;/code&gt;, &lt;code&gt;locator()&lt;/code&gt;, and &lt;code&gt;expect()&lt;/code&gt; throughout a test. So let's define the purpose of each one of these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;goto()&lt;/code&gt; is a function used to navigate to a website, similar to typing a URL in your browser. This instruction is used to access the page that you will be probing.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;locator()&lt;/code&gt; is used to find elements within a website. Playwright uses the same syntax as CSS selectors when using the &lt;code&gt;locator&lt;/code&gt; method. This means that you can find elements using HTML element types, classes, or IDs to identify them. There are other ways to locate elements, but they are more related to accessibility attributes rather than HTML properties.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;expect()&lt;/code&gt; is used to compare the actual results of a test with the expected results. This function allows you to check if elements satisfy certain conditions, such as being visible, checked (for checkboxes), or having specific properties. There are many possibilities for comparing the results with the expected results. I will explain some of the most common methods to make these comparisons.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I want to show a brief example that shows a short a test to add products in a shopping cart on a website called &lt;a href="https://automationexercise.com/"&gt;automation exercise&lt;/a&gt;, designed to train yourself to make automated testing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;expect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@playwright/test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shopping cart test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Enter to automationexercise.com webpage&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://automationexercise.com/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Locate link to access the product &lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;locator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.features_items .choose a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Click to skip ads &lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mouse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Add 3 products&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;locator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#quantity&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Add product to the cart&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;locator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.product-information button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Click on the button to close the modal and keep navigating &lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;locator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.modal button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Expect the modal is closed once is clicked &lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;locator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.modal&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;not&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBeVisible&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the step-by-step process of what I'm doing here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enter the website automation exercise.&lt;/li&gt;
&lt;li&gt;Go to the section that includes the products and find the first link located there.&lt;/li&gt;
&lt;li&gt;Add an instruction to skip the ads that sometimes appear on the website and click in the top-left corner to close a modal that contains the advertisement.&lt;/li&gt;
&lt;li&gt;Once on the product detail screen, fill out the form to add 3 products.&lt;/li&gt;
&lt;li&gt;Click the button to add the products to the basket. When the products are added, a modal is displayed.&lt;/li&gt;
&lt;li&gt;Close the modal by clicking the button to do so.&lt;/li&gt;
&lt;li&gt;Close the modal using the button inside, and finally, check if the modal is not visible.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you notice that I was on two screens while doing this test, do I need to explicitly mention it? No, because Playwright does a lot of auto-waiting for me. For example, when moving to a new URL or waiting for the modal to close. Those are the tiny details that makes the developer experience awesome using it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to wait for something to happens
&lt;/h2&gt;

&lt;p&gt;But if you want to wait for something to happen because sometimes you need to wait for something to continue your test, like wait for some element to appear/disappear on the screen. You have the option to do it explicitly using &lt;code&gt;waitFor()&lt;/code&gt; to make a pause until some element satisfies a condition. I think this is a very repetitive situation when using a testing framework for the UI. In my first experiments I have to use it to wait that an elements appear on the screen and I wanted to share with you an example about how I use it. &lt;/p&gt;

&lt;p&gt;This is a test that need to wait for an element to be visible to continue to test a functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Search for something that has at least one result&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Enter to Playwright page&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://playwright.dev/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Find the search button&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Search &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Locate the search box to find a doc&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;searchBox&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByPlaceholder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Search docs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Click on the search box&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;searchBox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Type havetext on the searchbox&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByPlaceholder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Search docs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;havetext&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Wait for one result to appear on the screen&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;locator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.DocSearch-Dropdown-Container section&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitFor&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;visible&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="c1"&gt;// Count how many results does it get&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numberOfResults&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;locator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.DocSearch-Dropdown-Container section&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Expect at least to have one result &lt;/span&gt;
        &lt;span class="c1"&gt;// looking at the results section&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numberOfResults&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toBeGreaterThan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The step-by-step process is something like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the Playwright website.&lt;/li&gt;
&lt;li&gt;Find the search button.&lt;/li&gt;
&lt;li&gt;Locate the input with the placeholder "search docs".&lt;/li&gt;
&lt;li&gt;Click on that input.&lt;/li&gt;
&lt;li&gt;Fill the input with the text "havetext".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wait for the results to be visible&lt;/strong&gt; because we need to wait until the result is sent back to us.&lt;/li&gt;
&lt;li&gt;Count the number of results.&lt;/li&gt;
&lt;li&gt;Make sure that at least one result exists.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that we are familiar with the most common tests you will find, let's talk about the tools that come with Playwright.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools
&lt;/h2&gt;

&lt;p&gt;One of the things I love the most about Playwright is the tooling that comes with it. There are a lot of different ways that Playwright facilitates the job of creating or fixing tests. Let's begin with the main tool that I found very useful to get started with: codegen, a tool that opens a browser and starts to create code based on the actions you perform on the website, such as clicking on an element, typing in a form, or selecting text on the page. Is it possible to use the codegen result as the tests you will use? Sometimes yes, but I think for the vast majority of the tests, you will need to make some changes to improve things like the locator of an element, use a REGEX to ignore case when searching for text on your website, or make any other improvements to increase flexibility in your tests. Now let’s talk about debugging tools.&lt;/p&gt;

&lt;p&gt;To debug in Playwright, there are plenty of options to see the steps it's executing. For example, if you want to observe how the tests execute in the browser, you can do so by adding the &lt;code&gt;--headed&lt;/code&gt; flag when running the test. However, the test might be fast, and you may not perceive anything. If you prefer a slower execution, you can use an option called &lt;code&gt;slowMo&lt;/code&gt; to prevent the test from executing too quickly. Additionally, using the &lt;code&gt;--debug&lt;/code&gt; flag opens another window that allows you to pause, proceed to the next step, or run the test until the end, giving you control over the test's actions. These tools make your life easier when you need to fix errors, and these are not the only options available. Another option is called &lt;em&gt;"trace."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When you run your test with the flag &lt;code&gt;--trace on&lt;/code&gt;, this will record every activity that the browser does. After the tests are done, the failed tests will generate an interactive record that allows you to see how the element was located and how the DOM looks at that moment. It's similar to when you open a page with DevTools, which allows you to interact with the page and view the details. To see the trace, you need to use &lt;code&gt;show-report&lt;/code&gt; to see the test results and be able to open the trace. The report is only available through the option &lt;code&gt;show-report&lt;/code&gt;. You cannot serve it through other static servers or open it as plain HTML, especially when there are files that you need to view, like the traces so if you want to see traces results use that option.&lt;/p&gt;

&lt;p&gt;Now we are going to review the functions available to write tests and let’s begging with the selectors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selectors
&lt;/h2&gt;

&lt;p&gt;There are many ways to filter elements inside a page, and now I want you to become familiar with some of the ways to find elements inside a page. You can find elements by HTML attributes or the purpose on the page, such as accessibility role, label text, placeholder (if it is an input), text inside a page, alt text of an image, title attribute, or test ID. To find elements using any of these criteria, use some of the functions provided by Playwright.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;getByRole()&lt;/code&gt; to locate elements based on how people that uses assistive technologies perceive the page, so is useful to review which accessible roles exists to help you to understand which type of elements are you able to locate you can find more about roles in the following link: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles"&gt;WAI-ARIA Roles MDN Web Docs&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;getByLabel()&lt;/code&gt; to locate mainly form related elements, the label is the inscription for any type of input like text , checkboxes, radio buttons, selector and many others.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;getByPlaceholder()&lt;/code&gt; is related to form elements as well, but it is created to find elements based on a text that indicates how to fill the input or what the input is for.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;getByText()&lt;/code&gt; to locate any text inside of the page.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;getByAltText()&lt;/code&gt; helps you locate an image using the descriptive text used by people who use assistive technologies to understand the content of those images.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;getByTitle()&lt;/code&gt; to locate elements that use &lt;code&gt;title&lt;/code&gt; tag&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;getByTestId()&lt;/code&gt; is a special attribute used in HTML called &lt;code&gt;test-id&lt;/code&gt;, which is intended for testing frameworks to easily locate elements on the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to get an extensive list of all the selectors and get more information, go to the &lt;a href="https://playwright.dev/docs/locators"&gt;official documentation on locators&lt;/a&gt; to learn more. Since there are many ways to locate elements on the page, there are also many ways to compare final results with expected results, so let’s review some of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Assertions
&lt;/h2&gt;

&lt;p&gt;There are many functions to compare results, so I want to talk about the most common ones that you will use to check if some element of the page satisfies a certain condition. Let's see some of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;toBeTruthy()&lt;/code&gt; checks if an element is not &lt;code&gt;false&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt;, or &lt;code&gt;0&lt;/code&gt;. It is used to verify if a condition is met and is one of the simplest ways to compare if an element fulfills a certain requirement. The opposite is &lt;code&gt;toBeFalsy()&lt;/code&gt;, which checks if something does not meet a condition.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBe()&lt;/code&gt; checks if the value is the same. It is one of the most basic ways to check if something has an expected value. For example, when performing a search, you expect to have a certain number of elements.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeDefined()&lt;/code&gt; checks if an element is not &lt;code&gt;undefined&lt;/code&gt;. It is useful for verifying the existence of an element on a web page. For example, you can use it to check if a button is present on the web page.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeVisible()&lt;/code&gt; checks if an element is visible on the web page. For example, if you have an element that appears or disappears depending on user interactions, you can use this function to check if the element is visible on the page.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toHaveText()&lt;/code&gt; check if some element have some text. Let’s say a button and you need to verify if the call to action have the right text, you can use this function to verify it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeDisabled()&lt;/code&gt; helps you verify if an element is disabled. It is useful to check if buttons, inputs, and any other kind of interactive element are not enabled for the user to interact with.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toHaveURL()&lt;/code&gt; checks if a link has the correct URL. When you need to verify that a link has the correct redirection, you will use this.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toHaveAttribute()&lt;/code&gt; allows you to select an attribute and compare if it contains a certain value. For example, if you want to check if an image has a specific width. And not only that, you can virtually compare any attribute that was not previously included.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes, we actually need to verify that something does not satisfy a condition. To cover those cases, we have the &lt;code&gt;.not&lt;/code&gt; attribute available. It allows us to check if something does not match a condition. For example, if you want to verify that some text has changed, you can use the &lt;code&gt;.not&lt;/code&gt; attribute to check if the text is no longer on the page.&lt;/p&gt;

&lt;p&gt;I will probably continue to describe every way to make an assertion, but you can check every assertion that exists in the &lt;a href="https://playwright.dev/docs/test-assertions"&gt;test assertions documentation&lt;/a&gt; and you'll get more information there. If you consider that you need to use &lt;code&gt;toHaveAttribute()&lt;/code&gt; to compare something, please first read if there exists a method for that because it will make your intention clearer.&lt;/p&gt;

&lt;p&gt;Now we talk about one of the most impressive features, that is doing visual testing with Playwright.&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual testing
&lt;/h2&gt;

&lt;p&gt;Have you ever imagined having the chance to visually compare how a page looks before and after a change, automatically, and know if any differences exist? Well, this is now possible with Playwright. You can create a &lt;em&gt;screenshot&lt;/em&gt; that automatically compares the appearance before and after running tests. If any differences are found, the test will fail. The best part is that these tests generate a diff file that shows the specific differences between the previous and new versions, allowing you to easily spot the changes.&lt;/p&gt;

&lt;p&gt;To create this kind of test, all you need to do is use the assertion &lt;code&gt;toHaveScreenshot()&lt;/code&gt;. Once you use it, it creates an image that will be used as a reference for how the page is supposed to look, and it compares the results with that reference every time the test is executed. If you feel this is too strict and want to allow a little freedom, you can define a tolerance for the difference between screenshots using the option &lt;code&gt;maxDiffPixels&lt;/code&gt;. This allows you to change the maximum tolerated difference in pixels between two images.&lt;/p&gt;

&lt;p&gt;So doing a visual testing is that simple as write a test like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://playwright.dev&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveScreenshot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;maxDiffPixels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you got it you have your visual test online.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;I found Playwright to be a tool that is really easy to use. It has a lot of capabilities out of the box. If you're familiar with other tools for UI testing, this will be familiar to you. Remember that automated tests are a way to increase confidence in your app in a scalable way. You can add a few tests on Playwright to make sure that the most important parts of your app are working fine. If you have an e-commerce test where you can log in, add products to your shopping cart, and complete the purchase, it will cover one of the most common and important flows in e-commerce applications.&lt;/p&gt;

&lt;p&gt;Take advantage of this tool and test it because it will increase your productivity overall and catch bugs early on the development.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>testing</category>
      <category>playwright</category>
    </item>
    <item>
      <title>Developer Weekly Blog #3 - Web Accessibility</title>
      <dc:creator>Jean Paul</dc:creator>
      <pubDate>Mon, 30 Oct 2023 22:26:38 +0000</pubDate>
      <link>https://dev.to/jeanpaulyps/developer-weekly-log-3-3l3</link>
      <guid>https://dev.to/jeanpaulyps/developer-weekly-log-3-3l3</guid>
      <description>&lt;p&gt;This week I was studying accessibility on the web. There are a lot of lessons that I take about a course that I take about the topic. To summarized what I learned what do you need to check in order to have good accessibility is to assure you include in your web or component is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The usage of semantic HTML in your tags&lt;/li&gt;
&lt;li&gt;Guarantee a similar experience with screen-readers and how the people use it&lt;/li&gt;
&lt;li&gt;Have a good contrast with your text in order to be easy to read it&lt;/li&gt;
&lt;li&gt;Guarantee that the focusable sequence between elements makes sense and is similar as the default experience&lt;/li&gt;
&lt;li&gt;Use LightHouse to measure and get further accessibility improvements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using these key points you will guarantee a good experience for all kinds of people in your website and these will get you extra points at the SEO(Search Engine Optimization) because it indicates the meaning of the content on the page. So let’s dive deep into each of these points.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage of semantic HTML in your tags
&lt;/h2&gt;

&lt;p&gt;When we are writing HTML we have the freedom to write in whatever way we want to make it, but using the tags introduced by HTML 5 we have the opportunity to correctly label some common parts of our website like the header, the navigation bar or the footer. Using them allows a blind person, for example, that is not able to see the page to get more information about where he is located at the moment and give more valuable information. Take into account this two examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; Steps to make a toast &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; Take out your bread &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; Turn on your stove &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; Put the pan &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; Put the bread into the pan &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; Wait 2 to 5 minutes &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; Remove the bread &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When some screen-reader goes through this text will read something like: &lt;em&gt;“paragraph steps to make a toast, paragraph take out your bread, paragraph, turn on your stove”&lt;/em&gt; but this is more like a step by step tutorial, it would be better if you use a list to describe it, something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; Steps to make a toast &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ol&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Take out your bread&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Turn on your stove &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt; 
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Put the pan &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt; 
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Put the bread into the pan&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt; 
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Wait 2 to 5 minutes &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt; 
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Remove the bread&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;/ol&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the same text, a screen-reader now we can go something like this: &lt;em&gt;“paragraph steps to make a toast, ordered list, first take out your bread, second turn on your stove”&lt;/em&gt; this will make more sense to the user that is reading the content with this assistance. But this not only applies with content related to text, you also need it to take into account at the moment of creating the layout of the page and use the appropriate tags.&lt;/p&gt;

&lt;p&gt;If you want to create a header, don’t use the generic with a class &lt;code&gt;&amp;lt;div class="header" &amp;gt;&lt;/code&gt; prefer to use the header tag &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; so for the user it is clearer where they are standing. There are around 100 semantic elements but you can start with the basics on how to create a basic layout with these tags: &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;. To start creating understanding on how to structure a complete page. &lt;/p&gt;

&lt;h2&gt;
  
  
  Guarantee similar experience with screen-readers
&lt;/h2&gt;

&lt;p&gt;When navigating on our page it is common to have hidden elements, when you hide elements you are thinking in hiding it just visually and neglect that you need to hide it as well for people that don’t operate the website in the same way as the rest. In order to hide it you need to use &lt;strong&gt;ARIA &lt;em&gt;(Accessible Rich Internet Applications)&lt;/em&gt; attributes&lt;/strong&gt;, those are HTML attributes devoted to accessibility that indicates the state or give more information about an element, there are a lot of attributes that you are able to use, if you want to look a more complete list you can look at the documentation in &lt;strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes"&gt;MDN about ARIA states and properties&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this case where we want to hide an element apart from hiding from the screen we need to use &lt;code&gt;aria-hidden&lt;/code&gt; and this attribute receive a boolean value so you need to use it in this way &lt;code&gt;&amp;lt;div class="card" aria-hidden="true" /&amp;gt;&lt;/code&gt; so this element is skipped by the reading sequence of assistive technologies.&lt;/p&gt;

&lt;p&gt;But other scenario where you can use it is to give more information to the user about what is about this part of the page you can use something like &lt;code&gt;aria-label&lt;/code&gt; and &lt;code&gt;aria-description&lt;/code&gt; to indicate an user what is this part about, if you have a carousel about the products that you are selling, you can use these tags to give more context about where they are navigating.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; 
  &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"carrusel"&lt;/span&gt;
  &lt;span class="na"&gt;aria-description=&lt;/span&gt;&lt;span class="s"&gt;"List of the best selling products"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding more information and helping to guide a larger audience will make your application easy to use for them. The best way to guarantee a similar experience is to get the basics to navigate with a screen-reader and navigate through your app and see if there is a similar experience with what you see with the way you are navigating with the screen-reader technology. &lt;/p&gt;

&lt;p&gt;If you never used a screen-reader before you can start using it in Windows and Mac, in Windows there is a pre-installed program called narrator that you can turn on and off using the shortcut &lt;em&gt;Windows logo key + Ctrl + Enter&lt;/em&gt; if you want more information you can access the official documentation here. In Mac exist voice over&lt;/p&gt;

&lt;h2&gt;
  
  
  Have a good contrast in your text
&lt;/h2&gt;

&lt;p&gt;Sometimes we want to be super creative with the colors of our website and we forget to make the texts readable and the texts are super important because it is the main content that you see when you enter a website. Could you imagine how the app of your bank would look like without the text? Or how would the app that allows you to buy a ticket for a flight look like? It would look really confusing without the text.&lt;/p&gt;

&lt;p&gt;So in order to help the people that go to the website include good contrast in your text and to do it you can use a metric called &lt;em&gt;contrast ratio.&lt;/em&gt; This number indicates how much difference  exists between the background and text. If you want to check this number you can use this tool: &lt;a href="https://coolors.co/contrast-checker"&gt;color contrast checker&lt;/a&gt; to be able to know this number, you can start with a minimum of 4 of contrast, but if you want to be really great you need a contrast ratio of 7.&lt;/p&gt;

&lt;p&gt;As you see, texts are important so take care of them in order to guide the people that come to your website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Guarantee that the focusable sequence between elements makes sense and is similar as the default experience
&lt;/h2&gt;

&lt;p&gt;Yeah this is a long title but I didn’t come up with an idea that expresses those two things at the same time. Sadly most of evaluation of something to be accessible is a manual process, this is the reason that if you want to become great in accessibility you need to be able to use some screen reader or be able to navigate a website with just your keyboard because in that way you are able to verify by yourself if the experience is the same across different type of people.&lt;/p&gt;

&lt;p&gt;For example, modals, this is a polemic component to get done well, one of the aspects that could go wrong is this: have you ever encountered a modal that does not have a close button? Or worse yet the button is so tiny that it is almost impossible to click on it? Now imagine how the experience is for the people that are not able to see a screen and do not have a button to close the modal. For them not having a closing button would make it more difficult to navigate in that kind of website.&lt;/p&gt;

&lt;p&gt;And the same applies for elements that are not visible, when something is out of the screen or shouldn’t be visible there is an attribute that you can use in order to hide it called aria-hidden, if you have an element in the page but is not displaying at the moment use this property to help other type of users to skip that content, that would make them more satisfied with the navigation of your website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use LightHouse to measure and get further accessibility improvements
&lt;/h2&gt;

&lt;p&gt;If You Can’t Measure It, You Can’t Improve It, this is the basis of any quality control management so be pragmatic with this matter and use a tool like LightHouse that helps you with puntual suggestions that make the experience for any type of user better. If you know about another tool I’m open to hear it.&lt;/p&gt;

&lt;p&gt;So leverage from the existing tools, if you have an project use a static analyzer in order to prevent earlier any problem with the HTML of your website, you can check on this plugin that you can add to your linter called &lt;a href="https://www.npmjs.com/package/eslint-plugin-jsx-a11y"&gt;eslint plugin JSX a11y&lt;/a&gt; for React that help you at detect those errors. For other libraries or frameworks you can check this &lt;a href="https://www.digitala11y.com/free-accessibility-linters-to-automate-accessibility-workflow/"&gt;accessibility list of linters&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Last thoughts
&lt;/h2&gt;

&lt;p&gt;For me studying about accessibility help me to understand better how other people are able to use this websites, this features were added to help people with some kind of limitation like someone blind but this improvements shouldn’t apply only to them, imagine if you have some kind of problem with your mouse and now you are only able to use a website with your keyboard or think about how difficult some programs were difficult to use just because the text has small fonts or low contrast. So this is not only for this kind of person, it is to help out a larger range of people that you don’t know how this is going to impact.&lt;/p&gt;

&lt;p&gt;In general, thinking of different types of people using your product will help you to reach a broader audience.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>a11y</category>
      <category>html</category>
    </item>
    <item>
      <title>Developer Weekly Blog #2 - Documentation</title>
      <dc:creator>Jean Paul</dc:creator>
      <pubDate>Thu, 12 Oct 2023 16:01:59 +0000</pubDate>
      <link>https://dev.to/jeanpaulyps/developer-weekly-log-2-2jmg</link>
      <guid>https://dev.to/jeanpaulyps/developer-weekly-log-2-2jmg</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This week I was working in my talk that is going to be presented to university students, this week I review the topic about documentation on the book software engineering at Google, also I assisted to the first Pioneras Conf in my city Medellin, this Conf was targeted to girls that want to start their careers in tech, there was a great attendance and come people from everywhere, PionerasDev is an NGO in my city that aims to include more women in tech and help growing their careers, definitely check on that it’s an impressive initiative. Maybe in future entries I include some of the topics that I learned at the Conf.&lt;/p&gt;

&lt;p&gt;This week I’m going to talk about documentation. How to manage? How to write?  Why is it important? What type of public read documentation? What type of policies do you need to include to manage documentation? So let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Documentation
&lt;/h2&gt;

&lt;p&gt;Documentation is a serious topic that nobody wants to speak about, most of the engineers hate to do this task the have many reasons for this like: the extra effort in writing about the code, engineers tend to think that they are not capable of writing good documentation or think that writing as a different skill to acquire. But we should insist on increasing the amount of documentation and the way to accomplish that is to take documentation seriously.&lt;/p&gt;

&lt;p&gt;The way to make documentation serious is to treat it like code, this means to create tasks related to documentation, making pair reviews, create a version history and prioritize on your sprints. &lt;strong&gt;It sounds like a lot of work but this is an investment that will pay over time&lt;/strong&gt;, there are many benefits when you write it: helps you to remember what the code was about in the first place, reduce questions when someone else read it, force you to think if the code makes sense and signals that is a professional codebase and well maintained. Once the culture of writing documentation is established more people will get into it. So the next question is: how do we write good docs?&lt;/p&gt;

&lt;h3&gt;
  
  
  How to write documentation
&lt;/h3&gt;

&lt;p&gt;When writing you should always ask yourself: &lt;strong&gt;for who I am writing for?&lt;/strong&gt; The number one mistake when we are writing is to think from our perspective and doing so makes the text biased towards our own perspective, we consider that everyone shares our context but they do not. For this reason it is always recommended to make a pair review (like code) so you guarantee that other people are also able to understand what you write.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;“Optimize for the reader”&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Software Engineering at Google&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you do not know where to start is a good idea to make these questions in order to get understanding the context of your topic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why were these design decisions made?&lt;/li&gt;
&lt;li&gt;Why did we implement this code in this manner?&lt;/li&gt;
&lt;li&gt;Why did I implement this code in this manner? And imagine you’re looking to your code two years later&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So when writing the documentation on your code, focus on the questions: what does this code do? And why was it implemented in that way? Those are the common questions a future reader will have when reading the code. But if you want to go deeper you can ask yourself more questions to get more information.&lt;/p&gt;

&lt;p&gt;There are common questions that help you to include all the possible information around a topic, I am referring to the 5 w’s and h, these questions are: what? why? when? Who? where? And how? Asking this questions helps you to gather information on any topic, for example you can ask yourself the following questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is this doc for?&lt;/li&gt;
&lt;li&gt;When was created?&lt;/li&gt;
&lt;li&gt;Who is going to read this?&lt;/li&gt;
&lt;li&gt;Where does the doc be saved?&lt;/li&gt;
&lt;li&gt;Why does this document exist?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With those questions answered you are able to check if your documentation is precise and have all of the information needed to make it. But until this moment we didn’t ask ourselves about what kind of readers exist. So let's see what kind of readers we can encounter using our documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of audience
&lt;/h3&gt;

&lt;p&gt;There are different types of audience depending on the level of engagement in the project. We can classify people in 3 types and we’re going to imagine who is these people if you were creating a library:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;People working on the code:&lt;/strong&gt; these people are programmers related to the project and are experts in the programming language. In your library they would be the maintainers of the library.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consumers:&lt;/strong&gt; people related with the functions that the code or the API provides and only consume what is there. They are the people who download your library and use it in their code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Specific task&lt;/strong&gt;: people that are looking for how to accomplish a task. They are the people that don't want to go deep in your library but need it to do some specific task.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keeping in mind for who you writing for helps you to focus what are the topics you need to write about, because consumers of a library doesn’t want to know the specifics about how you implement a thing, but for a maintainer want to go deep in the specifics because maybe that helps them to fix something in the future, meanwhile for the people who wants to do something specific just need to find how to do their task. And you need not only to consider the level of engagement also the way they are searching information.&lt;/p&gt;

&lt;p&gt;The searchers navigating your content could be classified by two types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Seekers:&lt;/strong&gt; this is the kind of people who know what they want. To help them to get what they want quickly, give them a good structure easy to scan through the document&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stumblers:&lt;/strong&gt; they don’t know what they want. To help them, give it a summary at the start or the end of the document to know what the document is about&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Giving a good structure and summarizing your docs help to different kinds of people to be guided through the document. But you think that only comments on your code are the only documentation needed? There are many types of documents that you are able to include in your projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Types of documentation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There is more documentation than just commenting your code and we are going to explore what other kinds of other documents you could include inside your project. We could say that there are these types of documentation: code comments, design docs, tutorials, conceptual documentation and landing pages. Let’s see each one of them.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Code comments&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is what pops out of our mind when we think about documentation, this is the most fundamental way to document and it is a good idea to include these activities into our workflow to improve maintainability over time. A lot of programming languages had their own syntax to create documentation that facilitates this job. For example JavaScript has JSDocs and Python has PyDoc to document. Getting to know how it works those standards is beneficial to you and your team to use it and read it properly.&lt;/p&gt;

&lt;p&gt;And what to include in our code documentation? The question is a little bit uncomfortable, you can consider asking yourself the following questions to write about: &lt;em&gt;what does this code do? What was the reason to create this function, class or whatever? What is the expected result? What is the main use case or use cases to use this? What does this module include? What are the edge cases?&lt;/em&gt; Depending on the type you are describing it is nice to have some things, for example classes it is beneficial to write about the purpose of the class and important methods of the class. Functions should start with a verb because they do something and is a good place to describe parameters, return value and exceptional cases. To see it let’s take a look at an example.&lt;/p&gt;

&lt;p&gt;Let’s take as an example this piece of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;## Maybe include an example of code
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wheels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seats&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wheels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wheels&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;seats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;seats&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_on&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;accelerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;brake&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_on&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_on&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;paint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newColor&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newColor&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; vehicle with 
               &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wheels&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; wheels and 
               &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;seats&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; seats&lt;/span&gt;&lt;span class="sh"&gt;""""&lt;/span&gt;&lt;span class="s"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s clear enough but let see how becomes more easy to read with some documentation and put on the perspective of someone that use this module or doesn’t want to know the specifics of your code and the people that will read this code in the future:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
  Represents a vehicle into the game, the user is able to
  personalize color, wheels and seats. When the user drives 
  is able to change speed and turn on or off the car whenever 
  they want to. 

  In order to change speed of the car you need to `acelerate()` or 
  `brake()` to increment or reduce speed.

  To be able to use the car you are able to use `start()` and when 
  you are done use `turnOff()`. 

  To change color use `paint()` to assign new color. 
  &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wheels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seats&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Initializes the vehicle with the given color, wheels and seats.

    color: string - RGB color of the vehicle
    wheels: number - number of wheels of the vehicle 
    seats: number - number of seats of the vehicle
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wheels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wheels&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;seats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;seats&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_on&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;accelerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Increments the speed of the vehicle by 1.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;brake&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Reduces the speed of the vehicle by 1.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Turns on the vehicle.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_on&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;turnOff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Turns off the vehicle.
    &lt;/span&gt;&lt;span class="sh"&gt;"""""&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_on&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_on&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;paint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newColor&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Changes the color of the vehicle to the newColor.

    color: string - RGB color of the vehicle
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newColor&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Return a text with the description of the vehicle

    Returns: string - a string representation of the vehicle
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; vehicle with 
               &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wheels&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; wheels and 
               &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;seats&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; seats&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are not familiar with Python docstrings you can read more &lt;a href="https://www.datacamp.com/tutorial/docstrings-python"&gt;here&lt;/a&gt;. At the start we include the use case for this piece of code and describe what actions to perform at the definition of the class. In each method we describe what is the action expected, a key here is to describe what is this method doing but don’t explain how, the how is the code. And for functions with a return funciton like the last function we describe what is the return type expected. These comments will help you and others in the future to better understanding.&lt;/p&gt;

&lt;p&gt;When you include this as a common practice this increases usability because you indicate what this module does and when someone else is using this, the code editor will tell you what is the goal of each thing. The end result is a larger file but overall it is a great improvement. If you see the first code was not bad but with the documentation it shines and will improve collaboration with the rest of the team.&lt;/p&gt;

&lt;h4&gt;
  
  
  Design docs
&lt;/h4&gt;

&lt;p&gt;These documents are a good way to create a register about the design decisions and discuss with other engineers, you can think about the design docs like the planes of the building, they describe what we’re going to do without making all the effort on creating the thing. In these texts you are going to talk about the goals of a new project and implementation details, strategies, pros and cons of each strategy and anything you need to take into account. &lt;strong&gt;These types of documents are required to start a new project at Google, imagine the importance of these.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So you can consider doing this type of document when you want to start a new project or doing a great effort and you need to think deeply on how to do it. To facilitate things I am going to include a template of the design doc made by @charlieBot a former engineer at Google, that you can check at the &lt;a href="https://github.com/charliesbot/design-docs/tree/main/english"&gt;design doc template here&lt;/a&gt;. Using the template will make easier to start using it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conceptual documentation
&lt;/h4&gt;

&lt;p&gt;Sometimes you need to introduce new ideas that are not trivial when someone reads your code. A conceptual documentation could be the key to guide new people to get familiar with new terminology that they don’t know. In this type of documentation you can explain what that concept is about? How to use it? Why was the origin of that? Why is it necessary? And maybe how to facilitate things when using it? This documentation is useful when comments in code are not enough to elaborate certain ideas that go beyond you possible write in a comment.&lt;/p&gt;

&lt;h4&gt;
  
  
  Tutorials
&lt;/h4&gt;

&lt;p&gt;How-to guides are valuable, the most important guide that you need in your project is how to set up and get started in your project, this way new people are able to start to contribute to your project quickly, this kind of guides are straightforward to write because you need to describe step-by-step what the user should follow.&lt;/p&gt;

&lt;p&gt;When write tutorials is good to follow this tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add numbers to each step&lt;/li&gt;
&lt;li&gt;Add a new step when user input is required&lt;/li&gt;
&lt;li&gt;Clarify if a pre-condition is needed to meet in order to do some step correctly&lt;/li&gt;
&lt;li&gt;Give a clear indication of what the user needs to perform at each step&lt;/li&gt;
&lt;li&gt;Show what is the expected output&lt;/li&gt;
&lt;li&gt;When done with tutorial, try it to verify that the steps execute correctly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Following these guidelines will make it easier to write clear tutorials to end users.&lt;/p&gt;

&lt;h4&gt;
  
  
  Landing page
&lt;/h4&gt;

&lt;p&gt;A landing page is perfect to organize your information and add navigation to what you document in your project. You need to make this right because maybe it is the first contact with the project for so many people so having a good structure facilitates users to navigate through the information easily. So check that it is easy to navigate through the documentation.&lt;/p&gt;

&lt;p&gt;But every documentation comes to an end, let’s see how to deprecate a documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Deprecation of a document&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Like software, documentation also has its own life cycle and when documentation is no longer useful you need a way to indicate the end of their life by adding some comment at the top that says: &lt;strong&gt;“this not longer works!”&lt;/strong&gt; and redirect to recent documentation if appropriate. But please don’t let deprecated documentation go freely without people knowing that it is not useful any more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Useful policies for documentation
&lt;/h3&gt;

&lt;p&gt;The best way to maintain good documentation is to treat documentation like code. So there are some policies that will help you to increase ownership on documentation on your team:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Documentation needs to have version control:&lt;/strong&gt; in order to have a good control on what you did and to recover something when you need to.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clear ownership:&lt;/strong&gt; assign a responsible to maintain a doc. when people are able to give feedback to someone is easy that get fixed when there is a responsible to do it&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do pair review:&lt;/strong&gt; when a new change is going to be published it is necessary that someone else review the new changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Have issues tracked:&lt;/strong&gt; like a code when a bug appears is registered in your task manager, when something needs to be improved on documentation put it on your task manager and do a follow-up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Periodically evaluate:&lt;/strong&gt; time to time review that the documentation is accurate with the information, this is critical for something like set-up tutorial&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main idea is to leverage from the established process to use it with your documentation so it is easy to maintain the workflow and not do an extra process just for documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;I was impressed by one idea of the book that states something like the &lt;strong&gt;state of documentation in 2010 was the same as testing in the 1980's&lt;/strong&gt;, this means poor tooling and almost no worries about this topic. With the implementation of policies mentioned before there was a good improvement at Google but still there is a good improvement margin in this area. For example some new tools are appearing like &lt;a href="https://storybook.js.org/"&gt;Storybook&lt;/a&gt; for UI components is something fresh that is going to become a standard in all JavaScript projects but I could imagine this is going to happen in other types of similar projects in other languages.&lt;/p&gt;

&lt;p&gt;So investing time in integrating better tooling to document is going to make things easier and things like LLM (Large Language Models) like GitHub Copilot will make this tedious task more easy to the developers bringing to them a better experience in the future.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Developer Weekly Blog #1 - Programming vs. Software Engineer</title>
      <dc:creator>Jean Paul</dc:creator>
      <pubDate>Mon, 02 Oct 2023 15:18:05 +0000</pubDate>
      <link>https://dev.to/jeanpaulyps/developer-weekly-log-1-3i5i</link>
      <guid>https://dev.to/jeanpaulyps/developer-weekly-log-1-3i5i</guid>
      <description>&lt;p&gt;This week I was reading about software engineering. I'm preparing a talk directed to university students studying this area. So the concept to my talk was directed by a primary question: what is Software Engineering anyways? The concept that I got when I was studying at the university was something like: software engineering it’s something like creating diagrams, trying to satisfy the client (because he doesn’t know what they want,) make a well structured plan and use agile methodologies.&lt;/p&gt;

&lt;p&gt;But for the preparation of my new talk I challenged my view to the emphasis on the planning side of a project and try to focus more on the day to day side of things in software engineering that are more trickier to master than just planning an ideal thing that maybe doesn’t see the light.&lt;/p&gt;

&lt;p&gt;So I decided to review some literature about the topic. And I found something that fit into what I wanted, a book I already knew, called: &lt;strong&gt;Software Engineering at Google.&lt;/strong&gt; I read two chapters that I selected to prepare my topics, more specifically chapter about &lt;em&gt;what software engineering?&lt;/em&gt; and &lt;em&gt;code review,&lt;/em&gt; I absolutely love how developed the topics there. First of all that I need to mention about this book, contrary of what you expect this is not a book about rules written in stone, it’s more about a series of essays about topics around daily practices used by Google Engineers in their day to day life.&lt;/p&gt;

&lt;p&gt;So this week the main ideas that I gather from my readings are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Programming vs Software Engineering&lt;/li&gt;
&lt;li&gt;Software engineering is programming integrated over time&lt;/li&gt;
&lt;li&gt;It’s better to upgrade your codebase in tiny beats than large scale changes&lt;/li&gt;
&lt;li&gt;Hyrum’s law: &lt;em&gt;“all observable behaviors on your system will be depended on by somebody”&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Think about the trade-offs&lt;/li&gt;
&lt;li&gt;Code review it’s one of the more valuable things to guarantee clean and maintainable software&lt;/li&gt;
&lt;li&gt;Code review it’s more effective when it’s small (less than 200 lines of code) and most of the time it’s done by one person to be more efficient&lt;/li&gt;
&lt;li&gt;Programming it’s an individual effort and software engineering it’s a team effort&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So let me explain a little bit about some of them&lt;/p&gt;

&lt;h2&gt;
  
  
  Programming vs Software Engineering
&lt;/h2&gt;

&lt;p&gt;There is a critical difference that you need to understand explained in the chapter &lt;em&gt;What is software engineering?&lt;/em&gt; about programming and software engineering. Programming is an individual effort and software engineering is a team effort. But saying that is something simplistic, there are more aspects that you need to take into account:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Programming 👨‍💻&lt;/th&gt;
&lt;th&gt;Software Engineering 🤝&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Number of people&lt;/td&gt;
&lt;td&gt;It’s individual&lt;/td&gt;
&lt;td&gt;Team effort&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scale&lt;/td&gt;
&lt;td&gt;The number of lines that one person is able to write&lt;/td&gt;
&lt;td&gt;Maybe hundreds of lines written by different teammates everyday&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lifespan of a project&lt;/td&gt;
&lt;td&gt;Maybe a couple months&lt;/td&gt;
&lt;td&gt;Years, even decades&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;External dependencies&lt;/td&gt;
&lt;td&gt;In that short lifespan is not critical to upgrade dependencies&lt;/td&gt;
&lt;td&gt;With time is common to need to upgrade dependencies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Policies&lt;/td&gt;
&lt;td&gt;A couple of established guidelines&lt;/td&gt;
&lt;td&gt;A lot of rules to ensure quality code and maintainability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Modification&lt;/td&gt;
&lt;td&gt;Low need for modification&lt;/td&gt;
&lt;td&gt;High need for modification&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Maintenance&lt;/td&gt;
&lt;td&gt;Low need for maintenance&lt;/td&gt;
&lt;td&gt;High need for maintenance&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This table summarizes what it’s the difference between programming and software engineering, you need to think in higher lifespans, complex inter-dependencies that evolve over time and a greater scales of lines of code integrated over time. There is a quote that you need to keep in mind when talking about this: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Software Engineering is the set of policies, practices, and tools&lt;/strong&gt; necessary to make that code useful for as long as it needs to be used and allowing collaboration across a team&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Is a delicate balance that allow teams to keep alive projects in the long run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Software engineering is programming integrated over time
&lt;/h2&gt;

&lt;p&gt;When we are learning programming most of our projects only have a short lifespan, maybe two or four months, but in projects that will last for many years (even decades) you can’t think with the same mindset that you work when you developed these projects with shorter life.&lt;/p&gt;

&lt;p&gt;If your project survives over time you come to realize some challenges that you didn’t imagine in the first place, with time every tiny decision has an impact on later modification and these little technical debts become a huge mortgage that you don’t know how to pay later. It is not an invitation to panic, it’s a recommendation to think about your code on a larger scale in every aspect: in time, in resource consumption or modification. Get your first guess and think of a 1.000x or 100.000x greater scale so you can see a glimpse of future problems. You don’t have to address them right away but definitely need to keep in mind to mitigate most important problems.&lt;/p&gt;

&lt;p&gt;Maybe some examples clarify this topic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You’re creating validations in your app, at some point you need to validate an email for creating a user, you thought &lt;em&gt;“hmm? I just going to create a validation for this field in this section to validate this email”&lt;/em&gt; but then later on you need to create the feature of editing this email but at the moment there is another teammate working on that and he re-implements a function to validate email, at the end the feature it’s uploaded and everything seems fine. Weeks later it’s created a bug mentioning that the email: &lt;a href="mailto:myorg@company.org"&gt;myorg@company.org&lt;/a&gt; works fine on the user creation but not for editing, so what’s happened here? Because there are two different implementations on email validations in one it works and in another doesn’t work resulting in duplicate logic and the risk of having incoherent behavior.&lt;/li&gt;
&lt;li&gt;Another scenario, you imagine your application to work with a MySQL database but in some moment the people realized that there are use cases where PostgreSQL it’s better to develop new features that will be important in the future. So you now are migrating your data from MySQL to PostgreSQL but due to lack of good abstractions your code it’s tightly coupled to the original selected database so it’s going to cost more effort to be able to even start the migration process and ending writing the app from scratch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Maybe you’re clever enough to imagine those scenarios but at some point all of us were so naive to even think that the database engine will never change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Think in your code in terms of clean and maintainable and not in hacky or clever
&lt;/h2&gt;

&lt;p&gt;When we are working on something difficult we are attracted to using some hacky thing that we found in StackOverflow and using in our code. But later on when something else needs to change in that file you don’t even remember what was the hack about because it’s written in an incomprehensible way that now looks like a hieroglyph or some dead language no longer used by humanity.&lt;/p&gt;

&lt;p&gt;So in those cases when something difficult exists don’t write your code in terms of something that just works, prioritize something that indicates what are the steps performed and what is the meaning of every step clearly. Luckily nowadays there is no limitation on the length of the variables or functions to write our code so we can be as expressive as we want to.&lt;/p&gt;

&lt;p&gt;For this example I was looking for old archive of previous programs to demonstrate this point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Code in Python
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
  &lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="n"&gt;V&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="n"&gt;V&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;V&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;inputs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Luckily this piece of code isn’t doing something so difficult but definitely doesn’t indicate too much about what it’s doing or the context of it. But with some rewriting reveals what was the original intention:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Code in Python
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;readScores&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
  &lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;scores&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;readScores&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this re-writing it’s more clear what we are doing: we are reading the scores of different matches of one user. The first section we were reading the user input to store a variable number of matches, then we read the scores and stored them in an array. The domain in which you are working it’s always useful to name things and you shouldn’t underestimate at the moment to write better code.&lt;/p&gt;

&lt;p&gt;But is there a chance to improve even further? What if we need to read a different size of user scores repeatedly? Then maybe we can put this into a function that it’s able to read different sizes and also create a function to store the way to read user inputs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Code in Python
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;readUserInput&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;readScores&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;readUserInput&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;scores&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;readUserInput&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;readScores&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This scales even better! So you need not only to create correct code, you also need to create code that it’s understandable by others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code review it’s one of the more valuable things to guarantee clean and &lt;strong&gt;maintainable&lt;/strong&gt; software
&lt;/h2&gt;

&lt;p&gt;When you have another one that review your code you’re able to get an opinion that doesn’t share your same biases, so it’s valuable to have another point of view that helps you to ensure that other people are able to understand what you write in the first place (or at least is most probable that other people are able to.)&lt;/p&gt;

&lt;p&gt;This is another big difference between programming and software engineering, as engineering is a team effort. You count on your teammates to help you with this kind of thing and reduce our personal biases in our code and be more consistent with the style of overall code.&lt;/p&gt;

&lt;p&gt;When doing code review it’s helpful to have this things in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do it timely: when code review request is created try to do the review in the next 24 hours&lt;/li&gt;
&lt;li&gt;Be polite and professional: don’t involve personal aspects in the code review, be assertive and point out the aspects of the code that doesn’t work&lt;/li&gt;
&lt;li&gt;Submit small changes: in order to don’t overwhelm your reviewer do small changes (less than 200 lines of code) to the get an effective feedback&lt;/li&gt;
&lt;li&gt;Write good change descriptions: in the first line describe the type of change you did (bug, feature, hot fix, etc.) and why you did it. When something is not approved, change the description if necessary.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Following these directives helps you to do great code review, giving feedback to other people it’s always difficult but it’s necessary for other people and ourselves to grow. The key to give great feedback is not to involve the being (like you’re disorganized, you're a bad communicator, etc.) it’s to talk about punctual actions (like in this section the variable names are ambiguous.) So we’re always talking about something near to reality and not from our personal biases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;The book &lt;strong&gt;Software Engineering at Google&lt;/strong&gt; it’s a good recommendation to read if you want to grow far beyond just programming. The best thing about this book is that it’s free only to read right now, you can access it by following this &lt;a href="https://abseil.io/resources/swe-book/html/toc.html"&gt;link&lt;/a&gt;. At this moment I’m more excited to know about this because it is a problem that arises more frequently now that I’m more involved in larger codebases and I’m more confident writing code. If you want to improve in other aspects different from just writing a syntactically correct program this book is for you.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>blog</category>
      <category>bestpractices</category>
      <category>diary</category>
    </item>
  </channel>
</rss>
