<?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: Giacomo Lombardi</title>
    <description>The latest articles on DEV Community by Giacomo Lombardi (@lomby92).</description>
    <link>https://dev.to/lomby92</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%2F262971%2F8cb41be7-e627-4b6e-933c-2f69584936f5.png</url>
      <title>DEV Community: Giacomo Lombardi</title>
      <link>https://dev.to/lomby92</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lomby92"/>
    <language>en</language>
    <item>
      <title>First time with Flutter: build a simple app</title>
      <dc:creator>Giacomo Lombardi</dc:creator>
      <pubDate>Fri, 15 Jul 2022 17:19:07 +0000</pubDate>
      <link>https://dev.to/lomby92/first-time-with-flutter-build-a-simple-app-192c</link>
      <guid>https://dev.to/lomby92/first-time-with-flutter-build-a-simple-app-192c</guid>
      <description>&lt;p&gt;I'm always excited to try new libraries/languages/tools (who don't be?) and some time ago I create my first app with Flutter: DoRPA.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DoRPA&lt;/strong&gt; stands for &lt;strong&gt;Do&lt;/strong&gt;wnload &lt;strong&gt;R&lt;/strong&gt;icevute &lt;strong&gt;P&lt;/strong&gt;ortale &lt;strong&gt;A&lt;/strong&gt;lloggiati. &lt;br&gt;
Portale Alloggiati: it's the Police portal which turist's structures must send daily data about who is arrived.&lt;br&gt;
Ricevute (receipt): daily PDF to download that certifies the right sending of data&lt;/p&gt;

&lt;p&gt;TLDR: see the repo &lt;a href="https://github.com/lomby92/download-ricevute-portale-alloggiati"&gt;https://github.com/lomby92/download-ricevute-portale-alloggiati&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  📍 Context
&lt;/h2&gt;

&lt;p&gt;Each turist's structure need to send data every day, o download the receipt from the Portale Alloggiati and to keep the receipt for 5 years. Also: receipts are available for 30 days in the Portale and then there is no way to download them.&lt;/p&gt;

&lt;p&gt;Early this year, the Police has published the Web-Service to send data without login in the Portale, that was no so accessible and user-friendly. Many PMS added the possibility to send data but the staff member of the hotel still need to access in the Portale to download receipts.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎉 Solution
&lt;/h2&gt;

&lt;p&gt;Let's make a very simple app to download receipts!&lt;/p&gt;

&lt;h2&gt;
  
  
  🧑‍💻 Development
&lt;/h2&gt;

&lt;p&gt;I started to follow the official guide, it's well done and easy to jump-in: &lt;a href="https://docs.flutter.dev/get-started/install"&gt;https://docs.flutter.dev/get-started/install&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the first steps I choose the UI and how it should work:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;login page: the user need to insert required data and non-sensitive data should be saved for subsequent logins&lt;/li&gt;
&lt;li&gt;download page: one input for the date and a simple submit button&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you can see, the UX is very simple, following the initial purpose.&lt;/p&gt;

&lt;p&gt;Internally, the app doesn't have too much logic. There is a service to handle HTTP calls to the Web-Service and to handle errors.&lt;/p&gt;

&lt;p&gt;I develop the app under Linux but for now it's available only for Windows. The power of Flutter: add MacOS and Linux will be really easy, without change the app itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  🖼️ UI
&lt;/h2&gt;

&lt;p&gt;The login page:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R1aENn2O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uf97jjxhr8g0au8z382l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R1aENn2O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uf97jjxhr8g0au8z382l.png" alt="Image description" width="880" height="767"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The download page and the date picker:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EopoLRkL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpw2vflczn7qndt4a87u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EopoLRkL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpw2vflczn7qndt4a87u.png" alt="Image description" width="876" height="763"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bZoGGwD2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7md3qab2qalvl6a0bs84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bZoGGwD2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7md3qab2qalvl6a0bs84.png" alt="Image description" width="874" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  📦 Release
&lt;/h2&gt;

&lt;p&gt;I played with GitHub Actions and in few minutes I was able to create the package needed to release the app. And, it's free!&lt;/p&gt;

&lt;p&gt;Release pipeline: &lt;a href="https://github.com/lomby92/download-ricevute-portale-alloggiati/actions/workflows/release.yml"&gt;https://github.com/lomby92/download-ricevute-portale-alloggiati/actions/workflows/release.yml&lt;/a&gt;&lt;br&gt;
Release page: &lt;a href="https://github.com/lomby92/download-ricevute-portale-alloggiati/releases"&gt;https://github.com/lomby92/download-ricevute-portale-alloggiati/releases&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  💭 Conclusion
&lt;/h2&gt;

&lt;p&gt;It was my first app, even if it's simple it was a pleasure to build it and release it. There always some work to do but for now it works and it's used at least for one hotel (every day) and this is a win experience for me!&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>crossplatform</category>
      <category>opensource</category>
    </item>
    <item>
      <title>From WordPress to Gastby</title>
      <dc:creator>Giacomo Lombardi</dc:creator>
      <pubDate>Thu, 30 Jun 2022 17:37:26 +0000</pubDate>
      <link>https://dev.to/lomby92/from-wordpress-to-gastby-4j86</link>
      <guid>https://dev.to/lomby92/from-wordpress-to-gastby-4j86</guid>
      <description>&lt;p&gt;In the past I had to take over the management of the family hotel website, a site created with &lt;strong&gt;WordPress&lt;/strong&gt; in the distant past (not from me) and never properly maintained.&lt;/p&gt;

&lt;p&gt;In order to not reinvent the wheel, I chose to keep the existing technology stack, renewing it in terms of: UI, functionality and performance.&lt;br&gt;
The results were poor, with a site soon becoming unmanageable and with an ever-growing fear of making significant changes.&lt;/p&gt;

&lt;p&gt;The pinnacle was reached when we had to use a plugin to manage the restaurant menu in order to "simplify" the input from the end user. The plugin, inevitably, was very limited and could only expose a couple of UIs (not properly done).&lt;/p&gt;




&lt;p&gt;After accumulating some experience with &lt;strong&gt;GatsbyJS&lt;/strong&gt; (this is the second time I go into production with it) I decided to do a graphic makeover, a simplification of the UX and a better manageability of the contents.&lt;/p&gt;

&lt;p&gt;📜 The menu is now generated from a simple JSON that dynamically creates the web page based on the contents. Changing the content has become too easy and the UI has been created ad-hoc (clean and readable), respecting the wishes of the owner.&lt;/p&gt;

&lt;p&gt;⭐ Review ratings on major online portals are now displayed from a JSON file. Before, I had to create images by hand with the reported vote, at each change of vote. Now this process can be automated.&lt;br&gt;
Bonus: the review collection is a component, reusable in the whole website avoiding copy-past errors.&lt;/p&gt;

&lt;p&gt;📝 The writing of the articles has been converted to simple &lt;strong&gt;markdown&lt;/strong&gt; files which then allow you to generate web pages according to a predefined template. The latter is essential because it allows you to have consistent and error-free pages. Again, it prevents to have strange copy-past errors of WordPress pages.&lt;/p&gt;

&lt;p&gt;⚡ The performances, needless to say, shot up. This is because a static site builder offers many features: progressive image loading, page loading speed, and general optimizations.&lt;br&gt;
Here you can find &lt;a href="https://dev.to/lomby92/progressive-image-loading-with-gatsby-2ldi"&gt;my article&lt;/a&gt; about progressive image loading.&lt;/p&gt;

&lt;p&gt;💻 Let's not forget that as a developer the goal is always to optimize time and having created the site with Gatsby made it possible for me to have excellent security and speed in releases and updates, because I can try the site on my PC before make a release (automated of course). This thing on WordPress was unthinkable, I would have had to provide myself with a staging site, make the changes and then replicate them on production.&lt;/p&gt;




&lt;p&gt;For the more curious, this is the site: &lt;a href="https://www.hotelmodernoassisi.com/"&gt;https://www.hotelmodernoassisi.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>wordpress</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Progressive image loading with Gatsby</title>
      <dc:creator>Giacomo Lombardi</dc:creator>
      <pubDate>Fri, 12 Mar 2021 22:13:08 +0000</pubDate>
      <link>https://dev.to/lomby92/progressive-image-loading-with-gatsby-2ldi</link>
      <guid>https://dev.to/lomby92/progressive-image-loading-with-gatsby-2ldi</guid>
      <description>&lt;h1&gt;
  
  
  Images on web pages
&lt;/h1&gt;

&lt;p&gt;If you think about a classic/typical website there are some components that surely you imagine like the navbar and the hero.&lt;br&gt;
The hero component typically has a large image that could impacts on the website performances (see &lt;a href="https://web.dev/vitals/"&gt;Google Web Vitals&lt;/a&gt;).&lt;/p&gt;
&lt;h2&gt;
  
  
  GatsbyJS
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.gatsbyjs.com/"&gt;GatsbyJS&lt;/a&gt; is one of the most famous static site generator that belongs to the &lt;a href="https://jamstack.org/"&gt;JAMStack movement&lt;/a&gt;.&lt;br&gt;
It has many plugins (to do almost anything) and one of the most used is the &lt;code&gt;gatsby-image&lt;/code&gt; plugin that shipped great performances to handle images, specially when used in combination with &lt;code&gt;gatsby-plugin-sharp&lt;/code&gt;.&lt;br&gt;
As GatsbyJS reached the &lt;a href="https://www.gatsbyjs.com/docs/reference/release-notes/v3.0/"&gt;3rd version&lt;/a&gt;, they released a new plugin for images: &lt;code&gt;gatsby-plugin-image&lt;/code&gt;.&lt;br&gt;
We will not talk about these changes in this post since my intentions is to show only &lt;strong&gt;how Gatsby can automatically handle images preloading&lt;/strong&gt; and &lt;strong&gt;how it's powerful&lt;/strong&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  Gatsby website configuration
&lt;/h1&gt;

&lt;p&gt;The new &lt;code&gt;gatsby-plugin-image&lt;/code&gt; used in combination with the &lt;code&gt;gatsby-plugin-sharp&lt;/code&gt; can be really really powerful.&lt;br&gt;
The only thing a website programmer or a content creator should think about is: &lt;em&gt;upload an high quality image prior to the extension and the size&lt;/em&gt;.&lt;br&gt;
The sharp plugin can be configured to automatically generate new file extensions that will be handled by the &lt;code&gt;gatsby-plugin-image&lt;/code&gt;. Doing this, the client will use the best extension you provide and it will have great performances.&lt;/p&gt;
&lt;h2&gt;
  
  
  Image placeholders
&lt;/h2&gt;

&lt;p&gt;Placeholders are important for two reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;score on tools like Google Lighthouse&lt;/li&gt;
&lt;li&gt;UX&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The plugin already ship the first point as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To ensure that the layout does not jump around, a placeholder is displayed before the image loads&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By default the placeholder is set to DOMINANT_COLOR but to have a better UX we should need to change it.&lt;/p&gt;

&lt;p&gt;Now the question is: what it is the best choice?&lt;br&gt;
There are few options: DOMINANT_COLOR, BLURRED, TRACED_SVG and NONE.&lt;/p&gt;
&lt;h4&gt;
  
  
  NONE
&lt;/h4&gt;

&lt;p&gt;In my opinion you should not display NONE as placeholder because it could lead to have large empty spaces before the image is loaded. These spaces could be confusing for an user as at first sight seems that the layout is broken.&lt;/p&gt;
&lt;h4&gt;
  
  
  DOMINANT_COLOR
&lt;/h4&gt;

&lt;p&gt;The default choice is too easy and generates a flat colored area that is not able to communicate what the image will contains.&lt;br&gt;
NOTE: this is a personal opinion, maybe you could love this setting.&lt;/p&gt;
&lt;h4&gt;
  
  
  BLURRED
&lt;/h4&gt;

&lt;p&gt;It shows the whole image but it is "animated" from blurred to sharpened, gradually. I like this solution because is like focusing a subject with a camera.&lt;/p&gt;
&lt;h5&gt;
  
  
  TRACED_SVG
&lt;/h5&gt;

&lt;p&gt;It is the most complicated solution but is the one I really love because it generates a sequence of images that lead the user to think that there is a painter that is painting in front of the user: starting from the main shapes of the image.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to choose
&lt;/h3&gt;

&lt;p&gt;How I should choose between BLURRED and TRACED_SVG?&lt;br&gt;
Even if I put some personal opinions in the previous section, what I really need is rational decision: &lt;strong&gt;based on data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So, I produced a local build of the website and performed some checks with the Lighthouse tab of Google Chrome dev tools.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gatsby build &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; gatsby serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will report only the &lt;em&gt;performance&lt;/em&gt; score as the image loading doesn't impact &lt;em&gt;accessibility&lt;/em&gt;, &lt;em&gt;best practice&lt;/em&gt; or &lt;em&gt;SEO&lt;/em&gt; scores.&lt;/p&gt;

&lt;h4&gt;
  
  
  Results
&lt;/h4&gt;

&lt;p&gt;BLURRED on mobile: &lt;strong&gt;82&lt;/strong&gt;&lt;br&gt;
TRACED_SVG on mobile: &lt;strong&gt;77&lt;/strong&gt;&lt;br&gt;
BLURRED on desktop: &lt;strong&gt;99&lt;/strong&gt;&lt;br&gt;
TRACED_SVG on desktop: &lt;strong&gt;98&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Note: each score is calculated as the mean of 10 tests.&lt;br&gt;
Note 2: GatsbyJS serve without HTTP/2 that lowers the score&lt;br&gt;
Note 3: the website is a work in progress and there are other things to touch to have better performances&lt;/p&gt;

&lt;p&gt;And the winner is... &lt;strong&gt;BLURRED&lt;/strong&gt;!&lt;br&gt;
It's clear that it has better performances on mobile than the other option.&lt;/p&gt;
&lt;h3&gt;
  
  
  gatsby-conf.js
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="c1"&gt;// ... some plugins before&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`gatsby-plugin-sharp`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;defaults&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="na"&gt;formats&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                        &lt;span class="s2"&gt;`auto`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="s2"&gt;`webp`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="s2"&gt;`avif`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="na"&gt;quality&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="na"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blurred&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="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="c1"&gt;// ... some plugins after&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;I choose "blurred" as placeholder but I also explicitly choose to generate AVIF and WEBP images to take advantage of the best possible compression available for the web.&lt;/p&gt;
&lt;h3&gt;
  
  
  Bonus
&lt;/h3&gt;

&lt;p&gt;All images in the website will have the BLURRED placeholder by default but it can be overwritten if you need.&lt;br&gt;
This is the case of the logo in the navbar: since the image contains only a bird with a background I have chosen to use a TRACED_SVG placeholder. In my opinion this solution is more artistic.&lt;/p&gt;
&lt;h2&gt;
  
  
  The result
&lt;/h2&gt;

&lt;p&gt;Navbar logo: TRACED_SVG&lt;br&gt;
Main image: BLURRED&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qdu1izINIhs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>javascript</category>
      <category>jamstack</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Test an Electron built snap package</title>
      <dc:creator>Giacomo Lombardi</dc:creator>
      <pubDate>Sat, 30 Jan 2021 12:55:38 +0000</pubDate>
      <link>https://dev.to/lomby92/test-an-electron-built-snap-package-1lio</link>
      <guid>https://dev.to/lomby92/test-an-electron-built-snap-package-1lio</guid>
      <description>&lt;h3&gt;
  
  
  Context
&lt;/h3&gt;

&lt;p&gt;Electron is a very powerful tool to develop cross-platform apps. It also simplify the building process thanks to the &lt;a href="https://www.electron.build/"&gt;electron-builder&lt;/a&gt; that targets Windows, MacOS and Linux.&lt;/p&gt;

&lt;p&gt;Linux builds have many choices, &lt;em&gt;rpm&lt;/em&gt; and &lt;em&gt;deb&lt;/em&gt; are the most common ones as they target Debian and Red-Hat distros.&lt;/p&gt;

&lt;p&gt;In 2014 Canonical started to develop a new package manager, &lt;a href="https://en.m.wikipedia.org/wiki/Snap_(package_manager)"&gt;snap&lt;/a&gt; that now is supported by all main distributions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;One release to rule them all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The electron-builder creates a &lt;strong&gt;.snap&lt;/strong&gt; file, but it is not executable.&lt;/p&gt;




&lt;h3&gt;
  
  
  Test the .snap file
&lt;/h3&gt;

&lt;p&gt;A snap file is basically a single compressed filesystem using SquashFS. In order to test it we need to mount/uncompress the file.&lt;/p&gt;

&lt;p&gt;1) unpack the snap file: &lt;strong&gt;unsquashfs -d /tmp/ &amp;lt;folder that will be created&amp;gt; &amp;lt;.snap file&amp;gt;&lt;/strong&gt;&lt;br&gt;
2) move to the newly created folder with unpacked data&lt;br&gt;
3) the app should be in the root, just execute it&lt;/p&gt;

&lt;p&gt;Note: i choose /tmp folder but anyone can choose where to unpack the snap file&lt;/p&gt;




&lt;p&gt;Try a snap file is really really easy but nowhere I found how to do it, hope that this short post will help you.&lt;/p&gt;

&lt;p&gt;Maybe more posts about snap will follow&lt;/p&gt;

</description>
      <category>linux</category>
      <category>snap</category>
      <category>electron</category>
      <category>testing</category>
    </item>
    <item>
      <title>How to (not) develop a public web service</title>
      <dc:creator>Giacomo Lombardi</dc:creator>
      <pubDate>Sat, 04 Apr 2020 16:53:55 +0000</pubDate>
      <link>https://dev.to/lomby92/how-to-not-develop-a-public-web-service-h50</link>
      <guid>https://dev.to/lomby92/how-to-not-develop-a-public-web-service-h50</guid>
      <description>&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;In Italy we have a public organization called INPS, it is an institution for people's pensions.&lt;br&gt;
Every citizen can access to this service and he can handle its data about pension and some other information. There are several different ways to login to this service, one of these is through a simplified code.&lt;br&gt;
Although using a simple PIN is not too safe, the simplified method was introduced due to the COVID-19 event. Many citizens now, can request a discount of 600€ from taxes since they cannot work due to the virus.&lt;br&gt;
The INPS thought of scale servers to support multiple requests, but they failed and this is the result: &lt;a href="https://www.ilpost.it/2020/04/01/malfunzionamenti-sito-inps/"&gt;News in the Italian language&lt;/a&gt;.&lt;br&gt;
This news leads me to look at the front-end Javascript code of their new pages, we will talk about it below...&lt;/p&gt;
&lt;h2&gt;
  
  
  JS hell
&lt;/h2&gt;

&lt;p&gt;The page I want to talk about is this one: &lt;a href="https://www.inps.it/nuovoportaleinps/modelliNuovo/assets/js/app.js"&gt;use 😎 to keep your eyes safe&lt;/a&gt;.&lt;br&gt;
&lt;em&gt;What is right on this page?&lt;/em&gt; &lt;strong&gt;Nothing&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;What is wrong on this page?&lt;/em&gt; &lt;strong&gt;Take a 🍵 and follow me&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Single JS file for the whole website
&lt;/h3&gt;

&lt;p&gt;Even if you are a newbie coder you should never produce a file with &lt;em&gt;4005&lt;/em&gt; lines of code. This file contains all Javascript functions used in the whole website.&lt;br&gt;
This means that if you go to the home page you will load the JS script and only a small subset of this one will be useful.&lt;br&gt;
Also, if you create a new page with this file as a dependency, you could have some weird behavior if you don't pay attention to HTML ids and classes. Even worse: you could need to add a very simple JS function for the new page and where you can place the new function? Into the app.js file obviously! 😆&lt;/p&gt;
&lt;h3&gt;
  
  
  Minification? What's this?
&lt;/h3&gt;

&lt;p&gt;As you can see if you access the link above, you easily find that the file is not minified. Minification is a very important step since it reduces the file size of the script.&lt;br&gt;
With 1 minute of work, I opened the first website found with a simple Google search: &lt;a href="https://javascript-minifier.com/"&gt;https://javascript-minifier.com/&lt;/a&gt;&lt;br&gt;
The original file size is &lt;em&gt;146.5 kB&lt;/em&gt; and the minified one is &lt;em&gt;84.9 kB&lt;/em&gt;. 💣&lt;br&gt;
Why reducing the size is soo important? I will not talk about it here but it should be clear to everyone developer. (If you don't have the answer: ask Google 😉)&lt;/p&gt;
&lt;h3&gt;
  
  
  Add comments to code
&lt;/h3&gt;

&lt;p&gt;Comments are fundamental for a maintainable code since they can lead a new developer to understand why the code is here and how it works.&lt;br&gt;
Pay attention: you too will be a new developer after a few months that you have written that code.&lt;br&gt;
How comments are used in the file?&lt;br&gt;
&lt;em&gt;Comments with strange meaning&lt;/em&gt;: I don't know why they use these comments&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//C6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Comments with dates&lt;/em&gt;: why? Git should be enough...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//28-11-2018
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Comments with unused code&lt;/em&gt;: what should we do with this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//$(menuContestuale).parent().attr('style', 'height:auto;');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Do not mix 🇮🇹 with 🇬🇧
&lt;/h3&gt;

&lt;p&gt;One of the things that also a student should never do is to mix languages to write code. Instead, the file contains thousands of mixed language variables. Some variables are in English and others in Italian but also exist some variable like this: &lt;strong&gt;heightPadreFigli&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;height: 🇬🇧&lt;/li&gt;
&lt;li&gt;padre: 🇮🇹 -&amp;gt; it means father&lt;/li&gt;
&lt;li&gt;figli: 🇮🇹 -&amp;gt; it means children&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Naming
&lt;/h3&gt;

&lt;p&gt;I'm not a naming stylist, I think it is an innate gift but I always try to find the right names. The app.js file has a long list of how to not choose names:&lt;br&gt;
They use &lt;em&gt;pippo&lt;/em&gt;, it's the Italian name of the Disney character: Goofy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var pippo = window.location.href.replace('lang=EN', '').replace('lang=IT', '').replace('lang=ES', '').replace('lang=FR', '').replace('lang=DE', '');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They use &lt;em&gt;prova&lt;/em&gt; that is &lt;em&gt;test&lt;/em&gt; in English. We cannot understand what should represent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var prova = "";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They use &lt;em&gt;context2padre&lt;/em&gt;, ignoring the mix of language we should think that this variable contains the father of context2 var. No, it calls jQuery parent() function 4 times!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var context2padre = $(context2).parent().parent().parent().parent();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Unused variables
&lt;/h3&gt;

&lt;p&gt;There are many unused variables, they should be removed, all the more reason that the file is very long.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function changeStatusHover(hover, selected, hiddenfieldhover, hiddenfieldselected) {
    var spanHover = $("#" + hover);
    var spanSelected = $("#" + selected);
    var spanHiddenHover = $("#" + hiddenfieldhover);
    var spanHiddenSelected = $("#" + hiddenfieldselected);

    if (!$(spanHiddenHover[0]).hasClass("changed")) {
        spanHover[0].setAttribute("style", spanHiddenSelected[0].value);
        $("#" + hiddenfieldhover).addClass("changed");
    }
    else {
        spanHover[0].setAttribute("style", spanHiddenHover[0].value);
        $("#" + hiddenfieldhover).removeClass("changed");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;spanSelected&lt;/em&gt; is not used inside the function so it's not needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Some other 💩
&lt;/h3&gt;

&lt;p&gt;There are many other shits inside this file, feel free to find these and add to comments section.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6BeVCvAg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.gyazo.com/80c4db126d4035bd31af018bb848f991.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6BeVCvAg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.gyazo.com/80c4db126d4035bd31af018bb848f991.png" alt="alt text for accessibility" width="436" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;A simple conclusion: make the code open source and all the above 💩s, hopefully, will never exist. Or, at least, use Webpack.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>covid19</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
