<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://imjufu.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://imjufu.github.io/" rel="alternate" type="text/html" /><updated>2023-12-04T20:08:44+00:00</updated><id>https://imjufu.github.io/feed.xml</id><title type="html">imjufu</title><subtitle>Je m'appelle Julien Fusco. Je suis un artisan du web. Je fais des sites web et des applications mobiles. J'aime aussi faire un peu de devops.
</subtitle><author><name>Julien Fusco</name></author><entry><title type="html">Automatise tes déploiements vers Dokku avec GitLab CI</title><link href="https://imjufu.github.io/automatise-tes-deploiements-vers-dokku-avec-gitlab-ci" rel="alternate" type="text/html" title="Automatise tes déploiements vers Dokku avec GitLab CI" /><published>2017-02-03T00:00:00+00:00</published><updated>2017-02-03T00:00:00+00:00</updated><id>https://imjufu.github.io/automatise-tes-deploiements-vers-dokku-avec-gitlab-ci</id><content type="html" xml:base="https://imjufu.github.io/automatise-tes-deploiements-vers-dokku-avec-gitlab-ci">&lt;p&gt;J’ai longtemps déployé mon code hébergé sur &lt;a href=&quot;https://www.github.com/&quot;&gt;Github&lt;/a&gt; vers &lt;a href=&quot;https://www.heroku.com/&quot;&gt;Heroku&lt;/a&gt;. Et d’ailleurs, je continue de le faire.&lt;br /&gt;
Je suis totalement tombé amoureux des &lt;a href=&quot;https://devcenter.heroku.com/articles/pipelines&quot;&gt;pipelines Heroku&lt;/a&gt; afin de gérer plusieurs environnements. En dehors des traditionnels environnements de staging et de production, on a également aussi les &lt;a href=&quot;https://devcenter.heroku.com/articles/github-integration-review-apps&quot;&gt;review apps&lt;/a&gt;. En deux mots, cela te permet d’avoir un environnement de testing dédié à chaque pull request sur Github. Le truc parfait quand tu veux faire tester une nouvelle feature au product owner sans avoir à pourrir l’environnement de staging.&lt;br /&gt;
Tout ça c’est sympa et très bien intégré si tu es sur Github et Heroku. Toutefois, j’ai quelques projets qui sont sur &lt;a href=&quot;https://www.gitlab.com/&quot;&gt;Gitlab&lt;/a&gt;. Et Heroku, c’est bien mais des fois, j’ai besoin d’auto-héberger des projets.&lt;/p&gt;

&lt;p&gt;Histoire de m’amuser un peu, j’ai essayé de reproduire toute la magie autour de cette intégration parfaite entre Github et Heroku.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/automatise-tes-deploiements-vers-dokku-avec-gitlab-ci/gitlab-ci-dokku.png&quot; alt=&quot;GitLab CI et Dokku pour tout automatiser&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;au-fait-pourquoi-automatiser-tes-déploiements-&quot;&gt;Au fait, pourquoi automatiser tes déploiements ?&lt;/h2&gt;

&lt;p&gt;En deux mots :&lt;/p&gt;

&lt;h3 id=&quot;productivité&quot;&gt;Productivité&lt;/h3&gt;

&lt;p&gt;Je préfère largement prendre un peu de temps, au début du projet, pour écrire des scripts que tout le monde pourra utiliser et maintenir, plutôt que d’écrire une documentation, qui ne sera jamais à jour, expliquant comment mettre en production.&lt;br /&gt;
En plus de ça, je vais pouvoir ré-utiliser mes scripts.&lt;br /&gt;
« Combien de déploiements sont effectués chaque année, sur combien de serveurs et combien de systèmes » permet de se faire une idée de la charge de travail.&lt;/p&gt;

&lt;h3 id=&quot;fiabilité&quot;&gt;Fiabilité&lt;/h3&gt;

&lt;p&gt;Automatiser permet de réduire les erreurs liées aux interventions humaines. Cela permet également de traçer les différentes opération.&lt;br /&gt;
Si le déploiement est bien fait, on peut également limiter les impacts négatifs sur la production, l’arrêt d’une application métier pendant une journée ouvrable par exemple.&lt;br /&gt;
L’utilisation d’outils permet de coupler plus facilement les tâches de déploiement et des tâches de mises à jour des environnements. Ces dernières sont souvent disjointes quand elles sont effectuées manuellement.&lt;/p&gt;

&lt;h2 id=&quot;dokku-le-heroku-auto-hébergé&quot;&gt;Dokku, le Heroku auto-hébergé&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://dokku.viewdocs.io/dokku/&quot;&gt;Dokku&lt;/a&gt; te permet de mettre en place un &lt;a href=&quot;https://en.wikipedia.org/wiki/Platform_as_a_service&quot;&gt;PaaS&lt;/a&gt; très rapidement. Et en plus, ça tombe bien, il s’appuie sur &lt;a href=&quot;https://imjufu.github.io/docker&quot;&gt;Docker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Pour faire tourner Dokku, je l’ai installé sur un Ubuntu serveur 16.04, le tout hébergé sur un serveur dédié &lt;a href=&quot;https://www.online.net/&quot;&gt;Online.net&lt;/a&gt; à ~10 € par mois.&lt;br /&gt;
En une ligne de commande et quelques configurations, Dokku est opérationnel.&lt;/p&gt;

&lt;h3 id=&quot;quelques-commandes-utiles-pour-la-suite&quot;&gt;Quelques commandes utiles pour la suite&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;dokku apps &lt;span class=&quot;c&quot;&gt;# Lister les applications existantes&lt;/span&gt;
dokku apps:create &amp;lt;app&amp;gt; &lt;span class=&quot;c&quot;&gt;# Créer une application&lt;/span&gt;
dokku apps:destroy &amp;lt;app&amp;gt; &lt;span class=&quot;c&quot;&gt;# Détruire une application&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Installer un plugin&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   Quelques exemples de plugins depuis https://github.com/dokku :&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     dokku-letsencrypt : Mettre en place automatiquement des certificats Let's Encrypt TLS&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     dokku-postgres : Plugin postgres&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     dokku-mysql : Plugin mysql&lt;/span&gt;
dokku plugin:install &amp;lt;git-url&amp;gt; 

dokku config &amp;lt;app&amp;gt; &lt;span class=&quot;c&quot;&gt;# Récupérer les variables d'environnement de l'application&lt;/span&gt;
dokku config:set &amp;lt;app&amp;gt; &lt;span class=&quot;nv&quot;&gt;KEY1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;VALUE1 &lt;span class=&quot;c&quot;&gt;# Définir une variable d'environnement pour l'application&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;gitlab-ci-pour-tester-builder-et-déployer-vers-dokku&quot;&gt;GitLab CI pour tester, builder et déployer vers Dokku&lt;/h2&gt;

&lt;p&gt;GitLab CI est une réponse de Gitlab aux différents outils d’intégration continue qui gravitent et sont pleinement intégrés avec Github.&lt;/p&gt;

&lt;h3 id=&quot;pipelines&quot;&gt;Pipelines&lt;/h3&gt;

&lt;p&gt;On retrouve la notion de pipeline proposée par Heroku.&lt;br /&gt;
Celle-ci va nous permettre de définir différentes actions réparties sur différentes étapes avant la mise en production de l’application. On peut imaginer avoir les étapes suivantes :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Test
    &lt;ul&gt;
      &lt;li&gt;Exécuter les tests unitaires&lt;/li&gt;
      &lt;li&gt;Exécuter un linter&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Staging
    &lt;ul&gt;
      &lt;li&gt;Déployer une nouvelle version du code&lt;/li&gt;
      &lt;li&gt;Migrer la base de données&lt;/li&gt;
      &lt;li&gt;Avertir (par mail, slack…) les personnes du projet de la mise en staging&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Production (débloquer par une validation manuelle)
    &lt;ul&gt;
      &lt;li&gt;Déployer une nouvelle version du code&lt;/li&gt;
      &lt;li&gt;Migrer la base de données&lt;/li&gt;
      &lt;li&gt;Avertir (par mail, slack…) les personnes du projet de la mise en production&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Si l’étape test échoue, alors le pipeline s’arrête. Sinon, on passe à l’étape staging puis, en cliquant sur un bouton sur l’interface de Gitlab, on passe à l’étape production.&lt;/p&gt;

&lt;p&gt;Et tout cela se configure via un simple fichier &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gitlab-ci.yml&lt;/code&gt; à la racine du projet.&lt;br /&gt;
Voici un premier exemple pour lancer les tests automatiquement à chaque intégration sur &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; ou à chaque merge request :&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;na&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ruby:2.3.3&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;stages&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;rspec&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;mysql:5.7&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;variables&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_RANDOM_ROOT_PASSWORD&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;yes'&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_DATABASE&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hello_world_test&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_USER&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hello_world_test&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_PASSWORD&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hello_world_test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle install&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;cp config/database.gitlab-ci.yml config/database.yml&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle exec rspec&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;rubocop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle install&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle exec rubocop&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;automatiser-la-mise-en-staging&quot;&gt;Automatiser la mise en staging&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Première étape&lt;/strong&gt;, la création de l’application Dokku :&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;dokku apps:create hello-world
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Mon projet &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hello-world&lt;/code&gt; a besoin d’une base de données MySQL :&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;# Installation du plugin mysql&lt;/span&gt;
dokku plugin:install https://github.com/dokku/dokku-mysql.git
&lt;span class=&quot;c&quot;&gt;# Création de la base de données&lt;/span&gt;
dokku mysql:create hello-world-database
&lt;span class=&quot;c&quot;&gt;# Création du lien de la base de données avec mon application&lt;/span&gt;
dokku mysql:link hello-world-database hello-world
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Deuxième étape&lt;/strong&gt;, autoriser GitLab à communiquer avec mon serveur Dokku.&lt;br /&gt;
Sur GitLab, il suffit de définir une variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH_PRIVATE_KEY&lt;/code&gt; qui contient la valeur d’une clé privée créée uniquement pour cet usage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Troisième étape&lt;/strong&gt;, compléter le fichier &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gitlab-ci.yml&lt;/code&gt; :&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;na&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ruby:2.3.3&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;stages&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;staging&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;rspec&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;mysql:5.7&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;variables&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_RANDOM_ROOT_PASSWORD&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;yes'&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_DATABASE&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hello_world_test&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_USER&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hello_world_test&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_PASSWORD&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hello_world_test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle install&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;cp config/database.gitlab-ci.yml config/database.yml&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle exec rspec&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;rubocop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle install&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle exec rubocop&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;deploy_staging&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;staging&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;before_script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;mkdir -p ~/.ssh&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;echo &quot;$SSH_PRIVATE_KEY&quot; | tr -d '\r' &amp;gt; ~/.ssh/id_rsa&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;chmod 600 ~/.ssh/id_rsa&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh-keyscan -H 'mon-serveur.com' &amp;gt;&amp;gt; ~/.ssh/known_hosts&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;git push dokku@mon-serveur.com:hello-world master&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;staging&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://hello-world.mon-serveur.com&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;only&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;master&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;À partir de là, à chaque intégration de code dans &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;, le code va être testé, validé puis déployé automatiquement en staging.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quatrième étape&lt;/strong&gt;, gérer les actions post-déploiement. Par exemple, la migration de la base de données. Rien de plus simple, il suffit de créer un fichier de configuration &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.yml&lt;/code&gt; à la racine du projet pour expliquer à Dokku les actions à effectuer suite au déploiement. Par exemple :&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;scripts&quot;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;dokku&quot;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;postdeploy&quot;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bundle&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;exec&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rails&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;db:migrate&quot;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;addons&quot;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;dokku-mysql&quot;&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;bonus-les-review-apps&quot;&gt;Bonus, les review apps&lt;/h2&gt;

&lt;p&gt;Avant l’intégration d’une merge request dans &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;, je vois deux points à valider :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Le code est-il de bonne qualité ? Cela sera déterminé suite à la relecture de la branche par un membre de l’équipe technique.&lt;/li&gt;
  &lt;li&gt;La fonctionnalité répond-t-elle au besoin ? Cela sera déterminé par le product owner.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Toutefois, le product owner ne va pas s’amuser à regarder la code pour valider ça. Il a besoin d’un environnement pour tester la fonctionnalité. C’est là qu’interviennent les review apps.&lt;/p&gt;

&lt;p&gt;Imagine une merge request nommée &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ajout-du-prenom&lt;/code&gt; qui permet de rajouter le prénom de l’utilisateur sur l’interface de l’application &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hello-world&lt;/code&gt;.&lt;br /&gt;
Le product owner pourrait se rendre sur http://ajout-du-prenom.mon-serveur.com pour tester et valider la fonctionnalité.&lt;/p&gt;

&lt;h3 id=&quot;comment-faire-ça-&quot;&gt;Comment faire ça ?&lt;/h3&gt;

&lt;p&gt;Très simple, il suffit d’ajouter une étape dans notre fichier de configuration &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gitlab-ci.yml&lt;/code&gt; afin de lui expliquer quoi faire lors de merge request.&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;na&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ruby:2.3.3&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;stages&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;review&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;staging&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;rspec&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;mysql:5.7&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;variables&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_RANDOM_ROOT_PASSWORD&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;yes'&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_DATABASE&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hello_world_test&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_USER&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hello_world_test&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;MYSQL_PASSWORD&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;hello_world_test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle install&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;cp config/database.gitlab-ci.yml config/database.yml&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle exec rspec&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;rubocop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle install&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bundle exec rubocop&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;start_review&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;review&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;before_script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;mkdir -p ~/.ssh&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;echo &quot;$SSH_PRIVATE_KEY&quot; | tr -d '\r' &amp;gt; ~/.ssh/id_rsa&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;chmod 600 ~/.ssh/id_rsa&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh-keyscan -H 'mon-serveur.com' &amp;gt;&amp;gt; ~/.ssh/known_hosts&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh dokku@mon-serveur.com apps:create $CI_BUILD_REF_SLUG&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh dokku@mon-serveur.com config:set $CI_BUILD_REF_SLUG MYSQL_DATABASE_SCHEME=mysql2&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh dokku@mon-serveur.com mysql:create $CI_BUILD_REF_SLUG-database&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh dokku@mon-serveur.com mysql:link $CI_BUILD_REF_SLUG-database $CI_BUILD_REF_SLUG&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;git push dokku@mon-serveur.com:$CI_BUILD_REF_SLUG HEAD:refs/heads/master&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;review/$CI_BUILD_REF_NAME&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://$CI_BUILD_REF_SLUG.mon-serveur.com&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;on_stop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;stop_review&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;only&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;branches&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;master&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;stop_review&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;review&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;before_script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;mkdir -p ~/.ssh&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;echo &quot;$SSH_PRIVATE_KEY&quot; | tr -d '\r' &amp;gt; ~/.ssh/id_rsa&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;chmod 600 ~/.ssh/id_rsa&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh-keyscan -H 'mon-serveur.com' &amp;gt;&amp;gt; ~/.ssh/known_hosts&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh dokku@mon-serveur.com apps:destroy $CI_BUILD_REF_SLUG --force&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh dokku@mon-serveur.com mysql:destroy $CI_BUILD_REF_SLUG-database --force&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;variables&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;GIT_STRATEGY&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;manual&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;review/$CI_BUILD_REF_NAME&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;action&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;stop&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;only&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;branches&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;master&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;deploy_staging&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;staging&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;before_script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;mkdir -p ~/.ssh&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;echo &quot;$SSH_PRIVATE_KEY&quot; | tr -d '\r' &amp;gt; ~/.ssh/id_rsa&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;chmod 600 ~/.ssh/id_rsa&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh-keyscan -H 'mon-serveur.com' &amp;gt;&amp;gt; ~/.ssh/known_hosts&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;git push dokku@mon-serveur.com:hello-world master&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;staging&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://hello-world.mon-serveur.com&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;only&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;master&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;À chaque merge request, GitLab va automatiquement :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Créer une nouvelle application&lt;/li&gt;
  &lt;li&gt;Créer et faire le lien d’une nouvelle base de données à l’application&lt;/li&gt;
  &lt;li&gt;Déployer le code de la branche sur cette application&lt;/li&gt;
  &lt;li&gt;Migrer la base de données&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Une fois la merge request intégrée dans master, GitLab va automatiquement :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Supprimer l’application&lt;/li&gt;
  &lt;li&gt;Supprimer la base de données&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quelques points à noter :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$CI_BUILD_REF_SLUG&lt;/code&gt; est une variable disponible automatiquement dans le runner GitLab. Il s’agit du nom de la branche en minuscule, de maximum 63 octets, et comportant uniquement des caractères valides pour une url.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh dokku@mon-serveur.com&lt;/code&gt; permet de piloter Dokku à travers ssh. On a accès à toutes les commandes Dokku disponibles directement depuis la ligne de commande mais en ssh.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Julien Fusco</name></author><summary type="html">J’ai longtemps déployé mon code hébergé sur Github vers Heroku. Et d’ailleurs, je continue de le faire. Je suis totalement tombé amoureux des pipelines Heroku afin de gérer plusieurs environnements. En dehors des traditionnels environnements de staging et de production, on a également aussi les review apps. En deux mots, cela te permet d’avoir un environnement de testing dédié à chaque pull request sur Github. Le truc parfait quand tu veux faire tester une nouvelle feature au product owner sans avoir à pourrir l’environnement de staging. Tout ça c’est sympa et très bien intégré si tu es sur Github et Heroku. Toutefois, j’ai quelques projets qui sont sur Gitlab. Et Heroku, c’est bien mais des fois, j’ai besoin d’auto-héberger des projets.</summary></entry><entry><title type="html">Blend Web Mix 2016</title><link href="https://imjufu.github.io/blend-web-mix-2016" rel="alternate" type="text/html" title="Blend Web Mix 2016" /><published>2016-11-02T00:00:00+00:00</published><updated>2016-11-02T00:00:00+00:00</updated><id>https://imjufu.github.io/blend-web-mix-2016</id><content type="html" xml:base="https://imjufu.github.io/blend-web-mix-2016">&lt;p&gt;&lt;em&gt;Petit compte rendu de Blend Web Mix 2016.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;duik--histoire-dun-logiciel-libre-le-coût-de-la-gratuité&quot;&gt;Duik – Histoire d’un logiciel libre, le coût de la gratuité&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://www.blendwebmix.com/programme/duik-histoire-d-un-logiciel-libre-le-cout-de-la-gratuite.html&quot;&gt;Résumé sur blendwebmix.com&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;La boîte à outils complète d’animation et de setup pour After Effects !&lt;br /&gt;
&lt;a href=&quot;https://rainboxprod.coop/fr/outils/duik/&quot;&gt;rainboxprod.coop&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Démarrage en 2009 avec 1000 lignes de code.&lt;br /&gt;
En 2015, 15000 lignes de code.&lt;/p&gt;

&lt;p&gt;C’est codé en js.&lt;/p&gt;

&lt;p&gt;822 téléchargements (~6Go) par jour.&lt;br /&gt;
Utilisé au niveau mondial.&lt;/p&gt;

&lt;p&gt;320000 téléchargements par an.&lt;br /&gt;
10000 ouvertures quotidiennes.&lt;/p&gt;

&lt;p&gt;Logiciel libre (mais pas gratuit).&lt;br /&gt;
À la base, le développeur principal n’est pas codeur, il s’est formé tout seul au code.&lt;/p&gt;

&lt;h3 id=&quot;pourquoi-a-t-il-choisi-le-libre-&quot;&gt;Pourquoi a-t-il choisi le libre ?&lt;/h3&gt;

&lt;p&gt;Vendre un logiciel, c’est compliqué :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Rédiger une licence&lt;/li&gt;
  &lt;li&gt;Créer une boutique en ligne&lt;/li&gt;
  &lt;li&gt;Lutter contre le piratage&lt;/li&gt;
  &lt;li&gt;Réparer les bugs&lt;/li&gt;
  &lt;li&gt;Aider les utilisateurs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il est sous GPLv3 :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Liberté d’utiliser le logiciel à n’importe quelle fin&lt;/li&gt;
  &lt;li&gt;Modifier le programme pour l’adapter à ses besoins&lt;/li&gt;
  &lt;li&gt;Redistribuer des copies à ses amis&lt;/li&gt;
  &lt;li&gt;Partager avec les autres ses modifications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choisir une licence libre, c’est avant tout des valeurs, une vision du monde.&lt;br /&gt;
C’est une manière de remercier ceux qui nous ont inspirés.&lt;/p&gt;

&lt;p&gt;Tout cela prend du temps et coûte de l’argent :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Développement&lt;/li&gt;
  &lt;li&gt;Support (forum, emails)&lt;/li&gt;
  &lt;li&gt;Documentation&lt;/li&gt;
  &lt;li&gt;Tutoriels&lt;/li&gt;
  &lt;li&gt;Frais technique (hébergement web)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;comment-financer-tout-ça-&quot;&gt;Comment financer tout ça ?&lt;/h3&gt;

&lt;p&gt;Commencer par se poser la question “Quel est le coût du logiciel ?”.&lt;/p&gt;

&lt;p&gt;2 visions pour définir la valeur :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;par le travail&lt;/li&gt;
  &lt;li&gt;par ce que l’utilisateur est prêt à payer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Actuellement, il faut 15000 € au minimum pour maintenir le logiciel.&lt;br /&gt;
Plusieurs moyens de financement :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;La pub -&amp;gt; pas éthique&lt;/li&gt;
  &lt;li&gt;“Choisissez votre prix” -&amp;gt; incompatible avec le logiciel libre&lt;/li&gt;
  &lt;li&gt;Location -&amp;gt; pas libre&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il reste le crowdfunding et la vente de produits dérivés.&lt;/p&gt;

&lt;p&gt;En 2015, 7175 € (258 contributeurs). Ce qui est faible en nombre de contributeurs.
Vente de produits dérivés en 2016 : 1000 €.&lt;/p&gt;

&lt;p&gt;Vivre du logiciel libre, ça fonctionne mais il ne faut pas vouloir gagner des millions d’euros.&lt;br /&gt;
Mais en terme d’ego, c’est très gratifiant. Il est contacté par Nickelodeon, Dreamworks…&lt;/p&gt;

&lt;p&gt;Il existe des plateformes comme &lt;a href=&quot;https://www.patreon.com/&quot;&gt;patreon.com&lt;/a&gt; pour financer le développement.&lt;/p&gt;

&lt;p&gt;Idée de projet du développeur :&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Ce serait top d’avoir une plateforme de crowdfunding uniquement dédiée au logiciel libre.&lt;br /&gt;
On fincance sans contrepartie et une fois le seuil atteint, le développeur commence à coder.&lt;br /&gt;
Pendant cette phase, les utilisateurs peuvent participer aux beta tests.&lt;br /&gt;
Une fois terminé, distibution en licence libre.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Voir &lt;a href=&quot;https://opencollective.com/&quot;&gt;opencollective.com&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;de-start-up-à-scale-up-les-leçons-devernote&quot;&gt;De Start-up à Scale-up: les leçons d’Evernote&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://www.blendwebmix.com/programme/de-start-up-a-scale-up-les-lecons-d-evernote.html&quot;&gt;Résumé sur blendwebmix.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Plusieurs étapes dans la création d’une startup :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Formation : phase de création&lt;/li&gt;
  &lt;li&gt;Validation : phase de rentabilité&lt;/li&gt;
  &lt;li&gt;Growth : phase de recrutement et de développement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Le speaker est Product Manager. Il est entre la techno, le design et le business.
Il a travaillé chez Evernote et maintenant chez SirupeLab.&lt;/p&gt;

&lt;p&gt;5 minutes -&amp;gt; temps pour convaincre de revenir.&lt;/p&gt;

&lt;p&gt;3 leçons :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Collectez vos data : pour faire de l’apprentissage, prendre des décisions stratégiques&lt;/li&gt;
  &lt;li&gt;Experimentez : le produit est le laboratoire, testez sur des échantillons d’utilisateurs&lt;/li&gt;
  &lt;li&gt;Restez simple : se concentrer sur ce qui fonctionne et jeter le reste&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;designer-pour-linconscient&quot;&gt;Designer pour l’inconscient&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://www.blendwebmix.com/programme/designer-pour-l-inconscient.html&quot;&gt;Résumé sur blendwebmix.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;L’attention se focalise plus facilement sur des éléments en mouvement.&lt;br /&gt;
Plus on est stressé et plus le locus de l’attention rétrécit.&lt;br /&gt;
La mémoire n’apparait que si il y a attention.&lt;/p&gt;

&lt;p&gt;Si on veut obtenir quelque chose de nos utilisateurs il faut attirer l’attention dessus.&lt;br /&gt;
Exemple du formulaire et du message d’erreur en haut d’écran.&lt;/p&gt;

&lt;p&gt;Le subconscient est la zone où les habitudes se développent.&lt;br /&gt;
Exemple : la marche, conduire&lt;/p&gt;

&lt;p&gt;Le bouton “back” Android ne marche pas car il ne respecte pas les attentes utilisateurs.&lt;/p&gt;

&lt;p&gt;La fenêtre modal ne fonctionne pas car c’est un automatisme que notre cerveau développe et du coup, on clique sans vraiment le vouloir.&lt;br /&gt;
Solution : pas de modal de confirmation mais un bouton annuler.&lt;/p&gt;

&lt;p&gt;Le multi-tâche est un mythe.&lt;br /&gt;
Si je marche en écoutant de la musique et en mangeant un sandwich et en réfléchissant à un problème mathématique. En vrai, seul le problème de mathématique capte mon attention. Le reste est en mode automatique.&lt;/p&gt;

&lt;p&gt;État de flow : buts clairs à chaque étape, un retour immédiat à chaque action, l’activité devient une fin en soi. On devrait tendre vers ça.&lt;/p&gt;

&lt;p&gt;Technologie calme, elle ne sur-sollicite pas mon attention. On devrait tendre vers ça.&lt;/p&gt;

&lt;p&gt;Conférence inspirée du livre &lt;a href=&quot;https://en.wikipedia.org/wiki/The_Humane_Interface&quot;&gt;The Human Interface&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;les-progressive-web-apps-expliquées-aux-décideurs&quot;&gt;Les Progressive Web Apps expliquées aux décideurs&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://www.blendwebmix.com/programme/les-progressive-web-apps-expliquees-aux-decideurs.html&quot;&gt;Résumé sur blendwebmix.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Les apps natives ont plus de fonctionnalités et sont plus solides que les sites web mais touchent moins d’utilisateurs que les sites web mobiles.&lt;/p&gt;

&lt;p&gt;PWA = site web mobile enrichi.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pourquoi progressif ?&lt;/strong&gt;&lt;br /&gt;
Car j’ai une logique progressive de l’application. Je vais délivrer la meilleure expérience possible à mon utilisateur final.&lt;br /&gt;
Safari sur iOS ne sait pas gérer correctement les PWA pourtant le site est opérationnel.
Chrome sur Android sait gérer le offline, les notifications… et du coup propose tout ça aux utilisateurs finaux.&lt;/p&gt;

&lt;p&gt;The Washington Post -&amp;gt; pionier des PWA : 80ms de temps de chargement d’un article.&lt;br /&gt;
Flipkart : accès au contenu en hors-ligne et dans les zones de mauvaise connexion réseau.&lt;/p&gt;

&lt;h3 id=&quot;quelles-sont-les-limites-&quot;&gt;Quelles sont les limites ?&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;HTTPS obligatoire&lt;/li&gt;
  &lt;li&gt;PWA pas disponible sur iPhone mais cela fonctionne quand même&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pourquoi-strlen--1-&quot;&gt;Pourquoi strlen(“🍕”) != 1 ?&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://www.blendwebmix.com/programme/pourquoi-strlen-1.html&quot;&gt;Résumé sur blendwebmix.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ASCII publié en 1963. 7 bits par caractère, 127 possibilités pour encoder du texte.
Avant ASCII, c’était le chaos !&lt;/p&gt;

&lt;p&gt;Autrement dit, uniquement les caractères américains. Du coup, très problématique pour le reste du monde.&lt;/p&gt;

&lt;p&gt;Ajout d’1 bit par la suite pour gérer plus de caractères.&lt;/p&gt;

&lt;p&gt;Puis internet arriva. Deviner l’encodage d’un document, c’est pas top et hacker ASCII a ses limites.&lt;/p&gt;

&lt;p&gt;L’âge d’or du Mojibake. Problème d’encodage, c’est compliqué.&lt;/p&gt;

&lt;p&gt;Unicode publié en 1991. “Un encodage pour les gouverner tous”.&lt;/p&gt;

&lt;p&gt;Unicode 1.0 stocké sur 16bits, 1 caractère = 2 octets.&lt;br /&gt;
Adopté par JS, C, Java.&lt;br /&gt;
Mais toujours pas assez de caractères !&lt;/p&gt;

&lt;p&gt;UTF et Unicode 2, publié en 1996.&lt;br /&gt;
On ne parle plus de caractères mais de code point.&lt;br /&gt;
Unicode = la liste des caractères.&lt;br /&gt;
UTF = l’encodage.&lt;/p&gt;

&lt;p&gt;3 différents UTF,&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;UTF8 : le plus connus et utilisé en europe&lt;/li&gt;
  &lt;li&gt;UTF16 : compatible unicode 1&lt;/li&gt;
  &lt;li&gt;UTF32 : pas utilisé&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Les emojis sont des caractères unicode et ont été ajouté en 2010.&lt;/p&gt;

&lt;p&gt;JS est resté sur le standard en 16bits (UTF16).&lt;/p&gt;

&lt;h3 id=&quot;tips&quot;&gt;Tips&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Ne pas limiter les caractères valides&lt;/li&gt;
  &lt;li&gt;Attention à la normalisation&lt;/li&gt;
  &lt;li&gt;Attention aux homoglyphes (github s’est fait attaquer comme ça)&lt;/li&gt;
  &lt;li&gt;Attention au charset UTF8 dans mysql, il faut utiliser utf8mb4 !&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ne-mourrez-pas-bêtes-faites-des-jeux-vidéo&quot;&gt;Ne mourrez pas bêtes, faites des jeux vidéo&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://www.blendwebmix.com/programme/ne-mourrez-pas-betes-faites-des-jeux-video.html&quot;&gt;Résumé sur blendwebmix.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nous, les développeurs web, nous sommes le côté sérieux et chiant de l’informatique.&lt;br /&gt;
Le bingo Blend Web Mix 2016 : phygital, scale-up, design thinking, venture capital…&lt;/p&gt;

&lt;p&gt;Les préjugés sur le monde du jeu vidéo :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Truc de graphistes&lt;/li&gt;
  &lt;li&gt;Truc de programmeurs&lt;/li&gt;
  &lt;li&gt;Complexe &amp;amp; inaccessible&lt;/li&gt;
  &lt;li&gt;La créativité&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il faut se lancer même si les premiers jeux qu’on fait sont pourris ! C’est normal et c’est pas grave !&lt;/p&gt;

&lt;p&gt;La productivité, c’est :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Efficacité&lt;/li&gt;
  &lt;li&gt;Force de proposition&lt;/li&gt;
  &lt;li&gt;Innovation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dans nos travails respectifs, on rentre dans une routine car on est bon dans ce qu’on fait et personne ne va nous demander de faire autre chose.&lt;/p&gt;

&lt;p&gt;La spécialisation est mauvaise. On s’enferme nous même dans un monde de routine.
Et en plus c’est dangereux, un langage ça disparait…&lt;/p&gt;

&lt;p&gt;La meilleure manière d’avancer, d’apprendre c’est de se vautrer !&lt;/p&gt;

&lt;p&gt;Le but n’est pas de tout plaquer pour devenir game developer mais bien de faire du jeu vidéo pour s’amuser et s’améliorer.&lt;/p&gt;

&lt;p&gt;Voir &lt;a href=&quot;https://itch.io/&quot;&gt;itch.io&lt;/a&gt; pour quelques exemples de jeux vidéo simples et fun.&lt;/p&gt;

&lt;p&gt;Quelques vidéos intéressantes :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Indie Game : The movie&lt;/li&gt;
  &lt;li&gt;Minecraft : The story of Mojang&lt;/li&gt;
  &lt;li&gt;Double Fine Adventure (sur Youtube)&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Julien Fusco</name></author><summary type="html">Petit compte rendu de Blend Web Mix 2016.</summary></entry><entry><title type="html">Paris Web 2016</title><link href="https://imjufu.github.io/paris-web-2016" rel="alternate" type="text/html" title="Paris Web 2016" /><published>2016-09-29T00:00:00+00:00</published><updated>2016-09-29T00:00:00+00:00</updated><id>https://imjufu.github.io/paris-web-2016</id><content type="html" xml:base="https://imjufu.github.io/paris-web-2016">&lt;p&gt;&lt;em&gt;Petit compte rendu de Paris Web 2016.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;anatomie-dune-désintoxication-au-web-sous-surveillance&quot;&gt;Anatomie d’une désintoxication au Web sous surveillance&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/anatomie-dune-desintoxication-au-web-sous-surveillance.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Monétisation de la donnée, de la vie privée.&lt;/p&gt;

&lt;p&gt;DataBrokers : courtiers en données -&amp;gt; Acxiom, DataLogics, Mediaposte…&lt;br /&gt;
Leur but est de scraper le web, d’acheter des fichiers et de revendre les données.&lt;br /&gt;
Ils ont une base de 500 millions d’individus.&lt;/p&gt;

&lt;p&gt;Au passage, la &lt;a href=&quot;http://www.acxiom.fr/a-propos-d-acxiom/deontologie/&quot;&gt;page de déontologie d’Acxiom&lt;/a&gt; est stupide et hypocrite !&lt;/p&gt;

&lt;p&gt;Que peut-on faire avec des données ? Les exploiter et prédire des comportements.&lt;/p&gt;

&lt;p&gt;À lire : Dataclisum, livre sur l’analyse des données et qui explique comment faire ressortir des choses intéressantes.&lt;/p&gt;

&lt;p&gt;Service gratuit -&amp;gt; publicité ! Affichage de pub prédictif via des études de comportement par les GAFAs.&lt;/p&gt;

&lt;p&gt;Principale information exploitée par les GAFAs : la liste des pages que l’on visite. Le tracking…&lt;/p&gt;

&lt;p&gt;LightBeam est une application Mozilla qui permet de visualiser la relation entre les sites visités. C’est effrayant !&lt;/p&gt;

&lt;p&gt;Toutes données personnelles sont des données sensibles alors que la loi française ne concidère pas cela.&lt;/p&gt;

&lt;p&gt;Une donnée peut être sensible, anodine ou indirectement sensible.&lt;br /&gt;
Exemple : Une adresse publiée sur societe.com pour un indépendant qui sort avec une policière. Pour le premier, l’info est anodine, pour le deuxième, c’est très sensible.&lt;/p&gt;

&lt;p&gt;Pour arrêter de collaborer avec les GAFAs, il faut dératiser les sites :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Supprimer les scripts google analytics et les remplacer par des solutions d’analyse d’audience perso : logstash, kibana, piwik…&lt;/li&gt;
  &lt;li&gt;Supprimer les boutons de partage : twitter, facebook&lt;/li&gt;
  &lt;li&gt;Supprimer les fonts : google fonts (alternative : auto-hébergement)&lt;/li&gt;
  &lt;li&gt;Supprimer les maps : google maps (alternative : open street map)&lt;/li&gt;
  &lt;li&gt;Supprimer les CDN (alternative : auto-héberger ses ressources)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Disqus est un service super pratique mais à éviter !&lt;/p&gt;

&lt;p&gt;Concept à intégrer :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Privacy by design : par défaut, la vie privée est respectée&lt;/li&gt;
  &lt;li&gt;Chiffrement obligatoire&lt;/li&gt;
  &lt;li&gt;Débloquer Tor&lt;/li&gt;
  &lt;li&gt;Stockage des données : d’un côté les données non sensibles et de l’autre les données sensibles&lt;/li&gt;
  &lt;li&gt;Recueil des données : récolter que des choses utiles et demander vraiment l’autorisation aux utilisateurs&lt;/li&gt;
  &lt;li&gt;Stockage des mots de passe. Conférence intéressante à ce sujet : &lt;a href=&quot;https://sudweb.fr/2011/post/Comment-stocker-les-mots-de-passe-de-vos-utilisateurs&quot;&gt;Comment stocker les mots de passe de vos utilisateurs ?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Respecter la loi&lt;/li&gt;
  &lt;li&gt;Non-conservation : ne revender pas les données de vos utilisateurs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Se poser la question de “Peut-on afficher de la pub tout en respectant la vie privée des utilisateurs ?”, cela revient à se demander “Peut-on perdre du poids en mangeant que du Kouign Amann ?”.&lt;/p&gt;

&lt;h2 id=&quot;ya-pas-davancement-pas-de-grimaces-&quot;&gt;Y’a pas d’avancement, pas de grimaces !&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/ya-pas-davancement-pas-de-grimaces.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dans l’étude de Nielsen, les sites ayant travaillé leur utilisabilité ont amélioré de 135% le taux de conversion. Voilà des arguments économique en faveur d’une aproche orienté utilisateur. C’est pour ces raisons évoquées par Nielsen que l’équipe de 1001pharmacies a engagé un travail de refonte.&lt;/p&gt;

&lt;p&gt;Le livre “Qualité web : La référence des professionnels du Web” de Elie Sloïm a beaucoup aidé.&lt;/p&gt;

&lt;p&gt;Ils ont fait des interviews et des tests utilisateurs pour voir les blocages. Et voici les actions qu’ils ont méné :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Réassurrance sur le paiement sécurisé&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Les bonnes pratiques et la qualité ne sont pas une fin en soi. Il faut tendre vers. À lire : “La dette technique” par Bastien Jaillot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Réassurance : contact sav / support&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Réassurance : délai de livraison, mode..&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;La livraison est critique, il faut être vigilant là-dessus. Le prix, le mode, qui… ? C’est important pour l’utilisateur.&lt;/p&gt;

&lt;p&gt;Il faut avoir des étapes claires.&lt;/p&gt;

&lt;p&gt;Les formulaires sont très importants. Il faut les rendre utilisable.&lt;br /&gt;
La saisie d’adresse est très angoissante pour un utilisateur ! Attention à la multiplication des champs compliqués.&lt;br /&gt;
Les champs nom / prénom séparés ne sont pas utilisables.&lt;br /&gt;
Attention au contrôle sur les champs de type email, c’est insupportable pour un utilisateur.&lt;/p&gt;

&lt;p&gt;L’authentification sur les sites de ecommerce n’est pas une bonne pratique. Cela fait fuire les gens.&lt;/p&gt;

&lt;p&gt;Une fois la commande terminée, il faut prendre soin de l’utilisateur.&lt;br /&gt;
Le simple message “Votre commande a bien été prise en compte”, c’est insuffisant ! Et les emails marketing ne fonctionnent pas.&lt;/p&gt;

&lt;p&gt;Le suivi de commande est très important :&lt;br /&gt;
Attente de préparation -&amp;gt; Préparation en cours -&amp;gt; Attente d’expédition -&amp;gt; Expédié -&amp;gt; En cours d’acheminement -&amp;gt; En livraison -&amp;gt; Facture disponible.&lt;/p&gt;

&lt;h2 id=&quot;lancer-son-site-à-linternational-facile--oui-si-lon-pense-à-tout-&quot;&gt;Lancer son site à l’international, facile ? Oui, si l’on pense à tout !&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/lancer-son-site-a-linternational-facile-oui-si-lon-pense-a-tout.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;la-base-la-traduction&quot;&gt;La base, la traduction&lt;/h3&gt;

&lt;p&gt;Passer par des Outils I18N.&lt;/p&gt;

&lt;h3 id=&quot;les-prix&quot;&gt;Les prix&lt;/h3&gt;

&lt;p&gt;Gestion des devises, utilisation d’api pour la conversion euro -&amp;gt; dollar, gestion de la TVA, des frais de douane…&lt;/p&gt;

&lt;h3 id=&quot;les-dates&quot;&gt;Les dates&lt;/h3&gt;

&lt;p&gt;Respecter la norme ISO 8601 et stocker en UTC.&lt;/p&gt;

&lt;p&gt;Attention, plusieurs timezones par pays.&lt;br /&gt;
Il faut savoir que les heures été / hiver sont très mal gérés par les gouvernements.&lt;/p&gt;

&lt;h3 id=&quot;contrôle-des-champs&quot;&gt;Contrôle des champs&lt;/h3&gt;

&lt;p&gt;Attention aux contrôles des champs surtout pour les pays asiatiques : nom, prénom, email, téléphone, état (pour les États-Unis)…&lt;/p&gt;

&lt;h3 id=&quot;divers&quot;&gt;Divers&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Les reCaptcha (google) sont bloqués en chine et empêchent la commande&lt;/li&gt;
  &lt;li&gt;Le design doit etre retravaillé : sens de lecture des pays arabes&lt;/li&gt;
  &lt;li&gt;Contenu textuel des images&lt;/li&gt;
  &lt;li&gt;Utiliser une font supportant tous les alphabets disponibles&lt;/li&gt;
  &lt;li&gt;Cartographie (maps, openstreetmap, bing)&lt;/li&gt;
  &lt;li&gt;Paiement (braintree, worldpay, stripe…)&lt;/li&gt;
  &lt;li&gt;Opportunités business “régionalisées” (exemple : uber)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;seo&quot;&gt;SEO&lt;/h3&gt;

&lt;p&gt;C’est un point sensible.&lt;br /&gt;
Google n’est pas numéro 1 partout dans le monde. Il est inexistant en chine et il n’est pas le premier au japon.&lt;br /&gt;
Le partage social n’est pas un automatisme.&lt;/p&gt;

&lt;h3 id=&quot;aspect-légal&quot;&gt;Aspect légal&lt;/h3&gt;

&lt;p&gt;Attention à la loi !&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;âge de majorité différent selon les pays&lt;/li&gt;
  &lt;li&gt;serveur physique obligatoire dans certains pays (exemple : chine)&lt;/li&gt;
  &lt;li&gt;interdit de stocker le numéro CB des clients&lt;/li&gt;
  &lt;li&gt;collecte d’impôts régionaux (exemple : airbnb en france)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pour résumer,&lt;/strong&gt;&lt;br /&gt;
Il faut prévoir l’internationalisation dès le départ au maximum.&lt;br /&gt;
Beaucoup de petites adaptations à faire ! Vous allez avoir pleins de questions et c’est normal !&lt;/p&gt;

&lt;h2 id=&quot;la-blockchain-quand-lindividu-sert-au-collectif-malgré-lui&quot;&gt;La blockchain, quand l’individu sert au collectif… malgré lui&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/la-blockchain-quand-lindividu-sert-au-collectif-malgre-lui.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On fait beaucoup (trop ?) confiance aux intermédaires.&lt;br /&gt;
Et ils aiment bien en abuser !&lt;/p&gt;

&lt;p&gt;La blockchain est là pour éviter les intermédiaires de confiance.&lt;br /&gt;
Tout a commencé avec la finance et notamment le bitcoin.
Satochi Nakamoto est l’inventeur du bitcoin mais il est inconnu.&lt;/p&gt;

&lt;p&gt;Blockchain = P2P + Crypto asymétrique + Preuve de travail&lt;/p&gt;

&lt;p&gt;Blockchain s’appuie sur le P2P.&lt;br /&gt;
Tout le monde fait une copie de la donnée. Bitcoin réplique le registre comptable sur tous les noeuds p2p.&lt;/p&gt;

&lt;p&gt;Blockchain s’appuie sur la crypto asymétrique pour sécuriser les échanges de données.&lt;br /&gt;
La crypto permet de signer un message pour assurer l’identité (privé -&amp;gt; public) mais aussi pour chiffrer un message à communiquer (public -&amp;gt; privé)&lt;/p&gt;

&lt;p&gt;Blockchain s’appuie sur la preuve de travail.&lt;br /&gt;
Cela permet d’ordonner les transactions pour éviter de tricher sur les échanges de données.&lt;/p&gt;

&lt;p&gt;Pour avoir le droit de publier son bloc de transaction, il faut avoir beaucoup de “0000” en début de SHA256 du bloc. Du coup, beaucoup de chance, beaucoup de travail -&amp;gt; preuve de travail.&lt;br /&gt;
Cela coûte et est fait par des “mineurs”.&lt;/p&gt;

&lt;p&gt;Du coup, avec tout ça, pas besoin de faire confiance à tout le monde. Les moutons noirs sont éliminés direct car les blocs frauduleux sont remplacés par des vrais blocs.&lt;br /&gt;
La sécurité est assuré par le nombre. Si plus de la moitié des mineurs jouent franc-jeu, la blockchain est sûre.&lt;/p&gt;

&lt;p&gt;Notion de smartcontract. Exemples :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Bitproof.io permet de certifier conforme un document. Cela évite de faire appel à des notaires ultra cher&lt;/li&gt;
  &lt;li&gt;Slock.it pour ouvrir les appartements sur une durée donnée&lt;/li&gt;
  &lt;li&gt;La Zooz est une alternive à Blablacar&lt;/li&gt;
  &lt;li&gt;La DAO est une société de capital risqueur&lt;/li&gt;
  &lt;li&gt;Storj est un cloud distribué en utilisant les HDD des utilisateurs de la blockchain&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On appelle cela des “decentralized apps” ou “DApps”.&lt;/p&gt;

&lt;p&gt;Ethereum = Blockchain apps platform&lt;br /&gt;
&lt;em&gt;Voir le projet “Zero dollar homepage” de marmelab.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Attention aux réponses asynchrones, le minage prend du temps !&lt;br /&gt;
Il faut interroger le réseau pour savoir si la blockchain est diffusé&lt;/p&gt;

&lt;p&gt;Attention. Une fois diffusé, un bloc ne peut pas être corrigé !&lt;/p&gt;

&lt;p&gt;Pour le minage, il faut l’accompagner d’un peu d’ether.
Pour information, Marmelab a obtenu 5 ethers en 5 jours sur un EC2 qui leur a couté 50 dollars. Et cet ether peut être revendu 55 dollars.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Toutefois !&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;La blockchain n’est pas prete. La documentation n’est pas à jour, les exemples de code sont KO.&lt;br /&gt;
Les smartcontracts sont stupides. Pas d’appel à des api externes. Il faut tout pousser dans les smartcontracts.&lt;br /&gt;
C’est très compliqué. Les DApps sont ultra-buggés ! En moyenne, 1 bug toutes les 10 lignes de code.&lt;br /&gt;
Cela manque de sécurité car le code est la loi, et du coup, si il y a bug, le hacker n’est pas responsable !&lt;br /&gt;
Beaucoup de gaspillage. 1 bloc accepté toutes les 10 minutes. 99% des calculs sont rejetés. C’est très coûteux. Et ce sont les utilisateurs de la blockchain qui payent.
C’est très lent les blockchains. Il faut attendre 1h sur la blockchain pour valider d’un point de vue sécurité 1 bloc.
À noter également, si supression des intermédiaires, pas de business model !&lt;/p&gt;

&lt;p&gt;Actuellement, 1 bitcoin = 600 dollars. Mais c’est très variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion de l’orateur&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Voir Bitnation.&lt;br /&gt;
Beaucoup de problèmes mais il faut parier dessus.&lt;/p&gt;

&lt;h2 id=&quot;organisez-des-cryptoparties-&quot;&gt;Organisez des cryptoparties !&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/organisez-des-cryptoparties.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;https://dascritch.net/vrac/Supports/1609-PARISWEB-CRYPTO/1_presentation.html#/&lt;/p&gt;

&lt;p&gt;Août 2012, Asher Wolf déclare “Il faut des cryptoparties !”&lt;br /&gt;
Octobre 2012, première cryptopartie à toulouse.&lt;br /&gt;
Décembre 2012, première cryptopartie faite par Snowden à Hawai.&lt;/p&gt;

&lt;h3 id=&quot;pourquoi-&quot;&gt;Pourquoi ?&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;apprendre à nous exprimer publiquement&lt;/li&gt;
  &lt;li&gt;évangéliser les bonnes pratiques&lt;/li&gt;
  &lt;li&gt;valoriser nos métiers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;C’est compliqué, il faut aider le néophyte et être humble.&lt;/p&gt;

&lt;h3 id=&quot;recettes&quot;&gt;Recettes&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;restez simple&lt;/li&gt;
  &lt;li&gt;pas de prosélythisme politique&lt;/li&gt;
  &lt;li&gt;pas de prosélythisme technologique&lt;/li&gt;
  &lt;li&gt;dédramatiser les choses et faites les avec humour&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;sensibiliser&quot;&gt;Sensibiliser&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;syndrôme du “rien à cacher” (OK, tu me donnes ta CB ?)&lt;/li&gt;
  &lt;li&gt;pertes des données / souvenirs&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;sujets-simples&quot;&gt;Sujets simples&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;les métadonnées&lt;/li&gt;
  &lt;li&gt;réseau informatique&lt;/li&gt;
  &lt;li&gt;internet ?&lt;/li&gt;
  &lt;li&gt;https / email chiffré ?&lt;/li&gt;
  &lt;li&gt;chiffrement / confidentialité&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;fictions&quot;&gt;Fictions&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Cryptonomicon (romans)&lt;/li&gt;
  &lt;li&gt;Media entity (bd)&lt;/li&gt;
  &lt;li&gt;Antitrust (film)&lt;/li&gt;
  &lt;li&gt;Person of interest (série)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ux-et-éthique&quot;&gt;UX et éthique&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/ux-et-ethique.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Les CGV.&lt;br /&gt;
Temps de lecture moyen : 7 secondes… :-D&lt;/p&gt;

&lt;p&gt;Les cookies.&lt;br /&gt;
Personne ne prend le temps de lire l’avertissement.&lt;/p&gt;

&lt;p&gt;À voir : Ateliers de co-conceptions.&lt;br /&gt;
Très intéressant mais conflit d’intérets !&lt;/p&gt;

&lt;p&gt;À voir : code de conduite UXPA.&lt;/p&gt;

&lt;h2 id=&quot;web-security-by-design&quot;&gt;Web security by design&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/web-security-by-design.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yahoo : 500 millions d’utilisateurs dans la nature.&lt;br /&gt;
Linkedin : 100 millions de comptes piratés.
Castorama : le moteur de recherche suggère des choses bizarres (hacking via injection).&lt;/p&gt;

&lt;p&gt;Le règlement européen pousse au “Privacy by design”.&lt;/p&gt;

&lt;h3 id=&quot;les-mauvaises-pratiques&quot;&gt;Les mauvaises pratiques&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;contrôle des données en entrée&lt;/li&gt;
  &lt;li&gt;mauvais usage du chiffrement&lt;/li&gt;
  &lt;li&gt;absence de framework&lt;/li&gt;
  &lt;li&gt;secrets en dur dans le code&lt;/li&gt;
  &lt;li&gt;manque de logs&lt;/li&gt;
  &lt;li&gt;des environnements différents : dev / prod&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Exemple du drone,&lt;br /&gt;
Il génère un wifi ouvert, accès telnet avec un accès root sans mdp.&lt;br /&gt;
Apps mobile qui donne des infos à des accès sur les apis des fabriquants.&lt;/p&gt;

&lt;p&gt;Beaucoup d’IOT sont problématiques : système d’alarme, caméra de surveillance…&lt;/p&gt;

&lt;p&gt;Pourquoi ?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;time to market ralenti&lt;/li&gt;
  &lt;li&gt;faible sensibilisation&lt;/li&gt;
  &lt;li&gt;mauvaise pratique de dev (top 10 des vulnérabilités)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;les-fondamentaux&quot;&gt;Les fondamentaux&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Disponibilité&lt;/li&gt;
  &lt;li&gt;Confidentialité&lt;/li&gt;
  &lt;li&gt;Intégrité des données&lt;/li&gt;
  &lt;li&gt;Traçabilité&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il faut avoir une approche par les risques. Raisonner en pas-à-pas.&lt;/p&gt;

&lt;h3 id=&quot;ressources&quot;&gt;Ressources&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;OWASP : exemples, fiches de bonne pratiques, outils…&lt;/li&gt;
  &lt;li&gt;Open SAMM : approche, méthode…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Revue manuelle -&amp;gt; Revues syntaxique -&amp;gt; Analyse statique -&amp;gt; Analyse dynamique -&amp;gt; Test d’intrusion.&lt;/p&gt;

&lt;h3 id=&quot;outils&quot;&gt;Outils&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Z Attack Proxy&lt;/li&gt;
  &lt;li&gt;Sonar Cube&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;éco-conception--mon-site-web-au-régime&quot;&gt;Éco-conception : mon site web au régime&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/eco-conception-mon-site-web-au-regime.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;greenit.fr&lt;br /&gt;
Le web a grandi mais il a grossi aussi.&lt;br /&gt;
Le poids d’une page a été multiplié par 115 en 20 ans.&lt;br /&gt;
De 2010 à 2015, il a été multiplié par 3.&lt;/p&gt;

&lt;p&gt;L’empreinte environnementale représente un sixième continent.&lt;/p&gt;

&lt;p&gt;On a besoin d’une démarche de conception responsable des services numériques.&lt;/p&gt;

&lt;p&gt;Cela fait 15 ans qu’on éco-conçoit du matériel.&lt;br /&gt;
On peut s’appuyer dessus pour la conception de site web.&lt;/p&gt;

&lt;p&gt;À lire : “Vers la sobriété heureuse” de Pierre Rabhi.&lt;/p&gt;

&lt;p&gt;Il faut dégraisser les sites, revenir au fondamental.&lt;/p&gt;

&lt;h3 id=&quot;mise-en-oeuvre&quot;&gt;Mise en oeuvre&lt;/h3&gt;

&lt;p&gt;Les impacts sont situés essentiellement au niveau des terminaux.&lt;/p&gt;

&lt;p&gt;Constitution d’un référentiel.&lt;br /&gt;
Cf. livre de l’écoconception en 115 bonnes pratiques.&lt;/p&gt;

&lt;p&gt;Il existe une toute jeune certification d’éco-conception.&lt;/p&gt;

&lt;p&gt;Outils d’évaluation : ecoindex.fr&lt;/p&gt;

&lt;p&gt;L’écoconception passe avant tout par le fonctionnel afin de dégraisser l’interface, le graphisme…&lt;/p&gt;

&lt;p&gt;Il existe une liste sur opquast liée à l’écoconception.&lt;/p&gt;

&lt;p&gt;Pas de prise de conscience sur l’écoconception car on leur a vendu l’aspect immatériel.
Le gouvernement a à peine conscience des problèmes d’accessibilités…&lt;/p&gt;

&lt;h2 id=&quot;il-ny-a-pas-que-class-et-id-dans-la-vie&quot;&gt;Il n’y a pas que class et id dans la vie&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/il-ny-a-pas-que-class-et-id-dans-la-vie.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;quelques-toolkits&quot;&gt;Quelques toolkits&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Atomic-css&lt;/li&gt;
  &lt;li&gt;Tachyons&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;quelques-conseils&quot;&gt;Quelques conseils&lt;/h3&gt;

&lt;p&gt;Écrire des classes à responsabilités uniques.&lt;/p&gt;

&lt;p&gt;Ben Frain, en 2014, a prouvé que la contre-performance des sélecteurs, c’est faux.&lt;/p&gt;

&lt;h3 id=&quot;sélecteurs-pestiférés&quot;&gt;Sélecteurs pestiférés&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;sélecteur universel : *&lt;/li&gt;
  &lt;li&gt;sélecteur attr complexe&lt;/li&gt;
  &lt;li&gt;sélecteur adjacence et de parenté&lt;/li&gt;
  &lt;li&gt;sélecteur éléments surqualifiés&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Auteur intéressant : Heydon Pickering.&lt;/p&gt;

&lt;p&gt;Framework de Dropbox à regarder : Scooter.&lt;/p&gt;

&lt;h2 id=&quot;quand-les-militaires-se-prennent-au-jeu-du-design-sprint&quot;&gt;Quand les militaires se prennent au jeu du design sprint&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/quand-les-militaires-se-prennent-au-jeu-du-design-sprint.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Design Sprint : processus de 5 jours durant lequel on cherche à résoudre un problème par le design. Créé par Google depuis 2010.&lt;/p&gt;

&lt;p&gt;Exemple de Design Sprint :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Lundi  : découvrir&lt;/li&gt;
  &lt;li&gt;Mardi : rechercher&lt;/li&gt;
  &lt;li&gt;Mercredi : décider&lt;/li&gt;
  &lt;li&gt;Jeudi : prototyper&lt;/li&gt;
  &lt;li&gt;Vendredi : tester&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Le but est de s’assurer le plus tôt possible que le service est viable.&lt;/p&gt;

&lt;p&gt;Prototype : croquis -&amp;gt; maquette -&amp;gt; photoshop -&amp;gt; Marvelab (intéractivité).&lt;/p&gt;

&lt;h3 id=&quot;quelques-conseils-1&quot;&gt;Quelques conseils&lt;/h3&gt;

&lt;p&gt;Il faut libérer la parole. Le “Tu” est de rigueur.&lt;br /&gt;
Mettre en place un petit jeu au départ pour détendre l’atmosphère.&lt;br /&gt;
La prise de décision rapide est importante, il faut être en présence des décisionnaires sinon ça ne marche pas.&lt;br /&gt;
La phase de préparation d’un design sprint est très importante. Il faut gérer toute la logistique : nourriture, boisson, organisation, répartition des rôles, gestion du planning…&lt;/p&gt;

&lt;h2 id=&quot;laccessibilité-décomplexée---ce-quelle-peut-faire-pour-vous&quot;&gt;L’accessibilité décomplexée - ce qu’elle peut faire pour vous&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/laccessibilite-decomplexee---ce-quelle-peut-faire-pour-vous.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;L’accessibilité est très allocentrée (centrée sur les autres).&lt;/p&gt;

&lt;p&gt;En essayant de penser “égocentré”, l’accessibilité permet aussi de faire progresser ses propres compétences.&lt;br /&gt;
Exemple : van11y.net.&lt;/p&gt;

&lt;h2 id=&quot;ne-passons-pas-à-côté-des-choses-simples&quot;&gt;Ne passons pas à côté des choses simples&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/ne-passons-pas-a-cote-des-choses-simples.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;usages&quot;&gt;Usages&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Prototypage&lt;/li&gt;
  &lt;li&gt;Présentation de contenu&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Si besoin de contributions par des non-techniciens, il existe des “Headless CMS”. Exemple : Forestry.io. Il s’appuie sur des APIs pour éviter aux contributeurs d’apprendre git, github…&lt;/p&gt;

&lt;p&gt;JAMStack : Javascript, APIs and Markup.&lt;br /&gt;
Générateurs : Jekyll, Hugo, Middleman, Gatsby.&lt;/p&gt;

&lt;h2 id=&quot;kit-de-survie-en-atelier-de-co-conception-fonctionnelle-ux&quot;&gt;Kit de survie en atelier de co-conception fonctionnelle UX&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/kit-de-survie-en-atelier-de-co-conception-fonctionnelle-ux.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Kit de survie 4 objectifs : se protéger, se signaler, s’hydrater, se nourrir.&lt;/p&gt;

&lt;h3 id=&quot;se-protéger&quot;&gt;Se protéger&lt;/h3&gt;

&lt;p&gt;Bien comprendre le contexte, anticiper les récalcitrants.&lt;br /&gt;
Service Design Toolkit.&lt;br /&gt;
DrawTast : apporte une cynergie de groupe au départ de l’atelier.&lt;/p&gt;

&lt;h3 id=&quot;alerter&quot;&gt;Alerter&lt;/h3&gt;

&lt;p&gt;Expliquer, répéter, laisser de la place aux participants, bien restituer la démarche.&lt;/p&gt;

&lt;h3 id=&quot;shydrater-se-nourrir&quot;&gt;S’hydrater, se nourrir&lt;/h3&gt;

&lt;p&gt;Assister à d’autres ateliers, établir un feedback.&lt;/p&gt;

&lt;h2 id=&quot;html51--web-platform-apis&quot;&gt;HTML5.1 + web platform APIs&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/html51-web-platform-apis.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;push-api&quot;&gt;Push API&lt;/h3&gt;

&lt;p&gt;C’est encore un brouillon.&lt;br /&gt;
Compatible : Chrome, Firefox.&lt;br /&gt;
Cela permet de pousser des notifications via des webapps.&lt;br /&gt;
Cela s’appuie sur les services workers.&lt;br /&gt;
Le navigateur a juste besoin d’être actif pour que ça fonctionne. Pas besoin d’avoir le focus sur la page.&lt;/p&gt;

&lt;h3 id=&quot;gamepad-api&quot;&gt;Gamepad API&lt;/h3&gt;

&lt;p&gt;Cela permet d’utiliser des gamepads pour interagir avec Canvas, WebGL.&lt;br /&gt;
Compatible avec les gamepads de Nintendo, Xbox, Playstation.&lt;/p&gt;

&lt;h3 id=&quot;vibration-api&quot;&gt;Vibration API&lt;/h3&gt;

&lt;p&gt;Super simple et permet de faire vibrer le téléphone.&lt;br /&gt;
Cela ne fonctionne pas sur Apple car pas d’accès au matériel.&lt;/p&gt;

&lt;h3 id=&quot;pointer-lock-api&quot;&gt;Pointer Lock API&lt;/h3&gt;

&lt;p&gt;Cela permet de réagir avec l’intégralité de la souris.&lt;/p&gt;

&lt;h3 id=&quot;web-speech-api&quot;&gt;Web Speech API&lt;/h3&gt;

&lt;p&gt;Cela permet de faire des apps avec lesquels on peut parler.&lt;br /&gt;
Possibilité de faire de la saisie avec la voie mais aussi de synthétiser du texte en vocal.&lt;/p&gt;

&lt;h3 id=&quot;html51&quot;&gt;HTML5.1&lt;/h3&gt;

&lt;p&gt;Ajout de balises : picture, srcset.&lt;br /&gt;
“images responsives”&lt;/p&gt;

&lt;p&gt;details et summary
super utile pour afficher, masquer du texte&lt;/p&gt;

&lt;p&gt;input type week, month, datetime-local&lt;br /&gt;
oncopy, oncut, onpaste&lt;/p&gt;

&lt;h2 id=&quot;progressive-web-apps--le-futur-du-web-arrive&quot;&gt;Progressive Web Apps : le futur du web arrive&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/progressive-web-apps-le-futur-du-web-arrive.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;avantages&quot;&gt;Avantages&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Linkable : pas d’apps à installer&lt;/li&gt;
  &lt;li&gt;Responsive&lt;/li&gt;
  &lt;li&gt;Safe : https!&lt;/li&gt;
  &lt;li&gt;Connectivity independent : offline first !&lt;/li&gt;
  &lt;li&gt;Fresh : toujours à jour !&lt;/li&gt;
  &lt;li&gt;App-like interactions : archi “application shell”&lt;/li&gt;
  &lt;li&gt;Re-engageable : l’amener à réutiliser l’app (via des notifications)&lt;/li&gt;
  &lt;li&gt;Discoverable : possible d’etre indexer via manifest.json&lt;/li&gt;
  &lt;li&gt;Installable : via le manifest.json les navs proposent de mettre l’apps sur la page d’accueil&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;service-workers&quot;&gt;Service Workers&lt;/h3&gt;

&lt;p&gt;C’est une sorte de proxy programmable dans le navigateur.&lt;br /&gt;
Uniquement en https. Et c’est bien normal, ça intercepte toutes les requêtes !&lt;br /&gt;
Nouvelle api de cache : Le Cache.&lt;br /&gt;
Nouvelle api de requettage (ne pas utiliser XHR car peut-être asynchrone !) : fetch(url) qui retourne une promise.&lt;/p&gt;

&lt;p&gt;Exemple : interception pour envoyer des notifications en push.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://pwa.rocks/&quot;&gt;pwa.rocks&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;leboncoin-les-coulisses-dune-refonte-responsive&quot;&gt;Leboncoin, les coulisses d’une refonte responsive&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pourquoi le fond jaune moche ? Pour une question de lisibilité et de confort de lecture.&lt;/p&gt;

&lt;h3 id=&quot;ux-dabord-responsive-après&quot;&gt;UX d’abord, responsive après&lt;/h3&gt;

&lt;p&gt;En 2016, 40% visiteurs uniques sur mobile et le taux de conversion est très mauvais.&lt;/p&gt;

&lt;p&gt;Carte blanche sur cette refonte graphique.&lt;br /&gt;
Brief de lancement : “Faites ce que vous voulez”.&lt;br /&gt;
Passage d’un cycle en V à plus d’agilité, équipe multi-compétences.&lt;/p&gt;

&lt;p&gt;Accompagnement par Alsacréations.&lt;/p&gt;

&lt;h3 id=&quot;chiffres&quot;&gt;Chiffres&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Sixième site français&lt;/li&gt;
  &lt;li&gt;54% des internautes sont français&lt;/li&gt;
  &lt;li&gt;24 millions d’utilisateurs&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bonnes-idées&quot;&gt;Bonnes idées&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Site de beta (beta.leboncoin.fr) pour tester l’interface avec des vrais utilisateurs proposé à 1 user sur 1000&lt;/li&gt;
  &lt;li&gt;refonte par parcours plutôt que par page&lt;/li&gt;
  &lt;li&gt;recrutement des beta-testeurs en activant la proposition de bandeau à 100% des utilisateurs&lt;/li&gt;
  &lt;li&gt;possibilité de revenir à l’ancienne version à tout moment&lt;/li&gt;
  &lt;li&gt;sondage aux utilisateurs en 4 questions (dont champ libre)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;-&amp;gt; 70000 réponses obtenues à analyser à la  main.&lt;/p&gt;

&lt;h3 id=&quot;résultat&quot;&gt;Résultat&lt;/h3&gt;

&lt;p&gt;5-6 mois de lancement maitrisé.&lt;br /&gt;
Pas de bugs majeurs, utilisateurs contents.&lt;/p&gt;

&lt;p&gt;Lancement retardé et expliqué par la loi de brooks : “Ajouter des personnes à un projet en retard accroît son retard”.&lt;/p&gt;

&lt;h2 id=&quot;wcagnext---where-do-we-go-from-here&quot;&gt;WCAG.next - where do we go from here?&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/wcagnext-where-do-we-go-from-here.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;WCAG 1.0 : mai 1999.&lt;br /&gt;
3 niveaux de conformité : A, AA, AAA.&lt;/p&gt;

&lt;p&gt;WCAG 2.0 : décembre 2008.&lt;br /&gt;
4 grands principes :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;pouvoir etre percu par tout le monde&lt;/li&gt;
  &lt;li&gt;manipulation du contenu (souris, clavier…)&lt;/li&gt;
  &lt;li&gt;compréhensibilité du contenu&lt;/li&gt;
  &lt;li&gt;robustesse&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;UAAG 2.0 : mêmes principes.&lt;/p&gt;

&lt;h3 id=&quot;atag-20&quot;&gt;ATAG 2.0&lt;/h3&gt;

&lt;p&gt;En 2016, Web page vs web app.
Il faut mixer les 3 standars : WCAG, UAAG, ATAG.&lt;/p&gt;

&lt;p&gt;AG = Accessibility Guidelines&lt;/p&gt;

&lt;p&gt;w3.org travaille sur le projet “Silver”. Il devrait prendre 5 à 7 ans.&lt;br /&gt;
Du coup, WCAG 2.x !&lt;/p&gt;

&lt;h2 id=&quot;lactivation-de-fonctionnalités-en-production-chez-blablacar&quot;&gt;L’activation de fonctionnalités en production chez BlaBlaCar&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.paris-web.fr/2016/conferences/lactivation-de-fonctionnalites-en-production-chez-blablacar.php&quot;&gt;Résumé sur paris-web.fr&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;état-de-léquipe&quot;&gt;État de l’équipe&lt;/h3&gt;

&lt;p&gt;100 personnes à la technique qui codent, testent et délivrent du code.&lt;br /&gt;
C’était un gros bordel.&lt;br /&gt;
Beaucoup de problématiques pour delivrer les nouvelles fonctionnalités.&lt;/p&gt;

&lt;p&gt;3 problèmes :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Déployer des grosses fonctionnalités&lt;/li&gt;
  &lt;li&gt;Tester une fonctionnalité avec 25M d’utilisateurs&lt;/li&gt;
  &lt;li&gt;L’effet capital&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mise en place des “feature flags”.&lt;br /&gt;
Un “feature flag” permet d’activer une fonctionnalité ou de la désactiver en production.&lt;/p&gt;

&lt;p&gt;Cela va permettre de faire :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;des tests en interne&lt;/li&gt;
  &lt;li&gt;permettre le roll-out&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;implémentation&quot;&gt;Implémentation&lt;/h3&gt;

&lt;p&gt;Stockage des fonctionnalités + librairie&lt;/p&gt;

&lt;p&gt;Exemples de lib PHP :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;etsy/features&lt;/li&gt;
  &lt;li&gt;joshuaestes/feature-toggle&lt;/li&gt;
  &lt;li&gt;opensoft/rollout&lt;/li&gt;
  &lt;li&gt;qandidate/toggle&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ils ont choisis la solution de qandidate.&lt;/p&gt;

&lt;p&gt;Storages :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Redis -&amp;gt; stockage principal&lt;/li&gt;
  &lt;li&gt;APCu -&amp;gt; cache&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stratégies :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Unanimous : toutes les strats soient remplies&lt;/li&gt;
  &lt;li&gt;Affirmative : au moins une soit remplie&lt;/li&gt;
  &lt;li&gt;Majority : une majorité des conditions soient remplies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour les apps natives, dépôt d’un json sur un S3 récupéré par les apps qui implémentent en natif.&lt;/p&gt;

&lt;h2 id=&quot;quelques-éléments-de-rd-en-vrac&quot;&gt;Quelques éléments de R&amp;amp;D en vrac&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;restlet&lt;/li&gt;
  &lt;li&gt;window.speechSynthesis&lt;/li&gt;
  &lt;li&gt;makey makey&lt;/li&gt;
  &lt;li&gt;node-red&lt;/li&gt;
  &lt;li&gt;code de conduite UXPA&lt;/li&gt;
  &lt;li&gt;service Design Toolkit&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Julien Fusco</name></author><summary type="html">Petit compte rendu de Paris Web 2016.</summary></entry><entry><title type="html">Mix-IT 2016</title><link href="https://imjufu.github.io/mix-it-2016" rel="alternate" type="text/html" title="Mix-IT 2016" /><published>2016-04-21T00:00:00+00:00</published><updated>2016-04-21T00:00:00+00:00</updated><id>https://imjufu.github.io/mix-it-2016</id><content type="html" xml:base="https://imjufu.github.io/mix-it-2016">&lt;p&gt;&lt;em&gt;Cet article est une prise de notes du Mix-IT 2016 qui a eu lieu à CPE Lyon.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;La conférence avec des crêpes et du cœur. &lt;a href=&quot;https://www.mix-it.fr&quot;&gt;mix-it.fr&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;tester-et-valider-ses-déploiements&quot;&gt;Tester et valider ses déploiements&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.mix-it.fr/session/2752/&quot;&gt;Résumé sur mix-it.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Plusieurs outils pour déployer et monitorer son code :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;SaltStack -&amp;gt; Déploiement (alternative : ansible, chef, puppet)&lt;/li&gt;
  &lt;li&gt;Shinken -&amp;gt; Monitoring mais Sensu est bien mieux pour les API Rest&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Les devs mettent en place des tests UF, font du TDD… Mais en tant que sysops, c’est assez pénible de tester les scripts de déploiements.&lt;/p&gt;

&lt;h3 id=&quot;plusieurs-niveaux-de-vérifications-&quot;&gt;Plusieurs niveaux de vérifications :&lt;/h3&gt;

&lt;p&gt;1 - Syntaxe&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;ansible-playbook foo.yml &lt;span class=&quot;nt&quot;&gt;--check&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;2 - Script&lt;/p&gt;

&lt;p&gt;Utiliser un serveur jetable : préparer une machine virtuelle via VirtualBox et Vagrant, faire une conf, puis exécuter&lt;/p&gt;

&lt;p&gt;3 - Supervision&lt;/p&gt;

&lt;p&gt;Exécuter des vérifications périodiquement et envoyer des alertes en cas de problème.&lt;/p&gt;

&lt;p&gt;Tout cela peut être intégrer dans un Jenkins.&lt;/p&gt;

&lt;h3 id=&quot;test-driven-infrastructure&quot;&gt;Test Driven Infrastructure&lt;/h3&gt;

&lt;p&gt;Mise en place des checks -&amp;gt; Checks négatifs -&amp;gt; Déploiement -&amp;gt; Checks positifs&lt;/p&gt;

&lt;p&gt;Checks de supervision + configuration de déploiement = Validation des déploiements&lt;/p&gt;

&lt;p&gt;Implémentation de déploiement du serveur de supervision :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Config de déploiement du serveur de supervision&lt;/li&gt;
  &lt;li&gt;Config de déploiement du service&lt;/li&gt;
  &lt;li&gt;Config de déploiement de la supervision du service&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Exécution :&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Déploiement de la supervision&lt;/li&gt;
  &lt;li&gt;Checks -&amp;gt; négatif&lt;/li&gt;
  &lt;li&gt;Déploiement service&lt;/li&gt;
  &lt;li&gt;Checks -&amp;gt; positif&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;go-from-zero-to-hero&quot;&gt;Go, from Zero to Hero&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.mix-it.fr/session/3282/&quot;&gt;Résumé sur mix-it.fr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Très proche de Python ou Ruby mais plus rapide car compilé.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;JSON encoding&lt;/li&gt;
  &lt;li&gt;HTTP server&lt;/li&gt;
  &lt;li&gt;Types&lt;/li&gt;
  &lt;li&gt;Interfaces&lt;/li&gt;
  &lt;li&gt;Goroutines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On peut apprendre les concepts de Go en 2h.&lt;/p&gt;

&lt;p&gt;Livre à lire : Site Reliability Engineering&lt;/p&gt;

&lt;h2 id=&quot;http2-pour-le-développeur-web&quot;&gt;HTTP/2 pour le développeur Web&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.mix-it.fr/session/2872/&quot;&gt;Résumé sur mix-it.fr&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;les-problèmes-de-http1&quot;&gt;Les problèmes de HTTP/1&lt;/h3&gt;

&lt;p&gt;Problème de latence. La bande passante n’est plus le problème.&lt;/p&gt;

&lt;p&gt;Techniques de contournement :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Domain sharding&lt;/li&gt;
  &lt;li&gt;Concaténation des assets&lt;/li&gt;
  &lt;li&gt;Sprites&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;http2&quot;&gt;HTTP/2&lt;/h3&gt;

&lt;p&gt;Ancêtre de HTTP/2 : SPDY&lt;/p&gt;

&lt;p&gt;Plusieurs améliorations :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Une seule connexion TCP&lt;/li&gt;
  &lt;li&gt;Multiplexing : plusieurs requêtes = une seule connexion&lt;/li&gt;
  &lt;li&gt;Binary framing&lt;/li&gt;
  &lt;li&gt;Flow control&lt;/li&gt;
  &lt;li&gt;HPACK&lt;/li&gt;
  &lt;li&gt;TLS obligatoire&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Informations utiles :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;les frames sont visibles dans les net-internals de chrome&lt;/li&gt;
  &lt;li&gt;Nginx supporte HTTP/2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stream prioritization&lt;/p&gt;

&lt;p&gt;Amélioration de TCP sur les serveurs :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Linux kernel 3.2+&lt;/li&gt;
  &lt;li&gt;Cache-Control &amp;amp; Etag&lt;/li&gt;
  &lt;li&gt;Gzip / deflate&lt;/li&gt;
  &lt;li&gt;Image compression&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dev toolset :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;NSSKeyLog&lt;/li&gt;
  &lt;li&gt;Wireshark&lt;/li&gt;
  &lt;li&gt;DevToolBar (possibilité d’ajouter de la latence)&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Julien Fusco</name></author><summary type="html">Cet article est une prise de notes du Mix-IT 2016 qui a eu lieu à CPE Lyon.</summary></entry><entry><title type="html">Javascript, gardez le meilleur !</title><link href="https://imjufu.github.io/javascript-gardez-le-meilleur" rel="alternate" type="text/html" title="Javascript, gardez le meilleur !" /><published>2015-02-27T00:00:00+00:00</published><updated>2015-02-27T00:00:00+00:00</updated><id>https://imjufu.github.io/javascript-gardez-le-meilleur</id><content type="html" xml:base="https://imjufu.github.io/javascript-gardez-le-meilleur">&lt;p&gt;Javascript est un langage remarquablement puissant. C’est une sorte de Lisp revêtu des habits du C.&lt;/p&gt;

&lt;p&gt;Javascript est basé sur de très bonnes idées : fonctions, couplage lâche, objets dynamiques, notation littérale expressive des objets… et quelques mauvaises : modèle de programmation axé sur les variables globales.&lt;/p&gt;

&lt;h2 id=&quot;typage-faible&quot;&gt;Typage faible&lt;/h2&gt;

&lt;p&gt;Javascript est un langage faiblement typé. Contrairement aux langages à typage fort, les compilateurs Javascript ne détectent pas les erreurs de type. Cela peut inquiéter mais est en fait libérateur. Il permet d’éviter des hiérarchies de classes complexes, de se battre avec le transtypage…&lt;/p&gt;

&lt;h2 id=&quot;héritage&quot;&gt;Héritage&lt;/h2&gt;

&lt;p&gt;Il existe plusieurs patterns d’héritage en Javascript.&lt;/p&gt;

&lt;h3 id=&quot;pseudo-classique&quot;&gt;Pseudo-classique&lt;/h3&gt;

&lt;p&gt;Ce pattern est destiné à paraître orienté objet.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Mammal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;Mammal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;Mammal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;says&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;saying&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myMammal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Mammal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Herb the Mammal&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myMammal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Herb the Mammal&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Cat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;saying&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;meow&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;Cat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Mammal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;Cat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;says&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myCat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Cat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Henrietta&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myCat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;says&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// meow&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myCat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// meow Henrietta&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Il n’y a pas de portée privée, toutes les propriétés sont publiques, il n’y a pas d’accès aux méthodes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;super&lt;/code&gt;.
Attention de ne pas oublier le prefix &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; lors de l’appel à la fonction constructeur sinon &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; n’est pas lié à un nouvel objet mais à l’objet global !&lt;/p&gt;

&lt;h3 id=&quot;prototypal&quot;&gt;Prototypal&lt;/h3&gt;

&lt;p&gt;Javascript possède un système d’objets sans classe dans lequel les objets héritent directement des propriétés d’autres objets.
C’est une relation dynamique. Si l’on ajoute une nouvelle propriété à un prototype, cette propriété est immédiatement visible dans tous les objets qui héritent de ce prototype.&lt;/p&gt;

&lt;p&gt;L’héritage pas prototype est plus simple que l’héritage classique. Commencez par créer un objet utile puis créer de nombreux objets analogues à ce premier.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myMammal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Herb the mammal&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;get_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;says&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;saying&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myCat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;myMammal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myCat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Henrietta&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myCat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;saying&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;meow&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myCat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;says&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On parle d’héritage différentiel.
Ce pattern n’offre pas de portée privée. Toutes les propriétés sont visibles.&lt;/p&gt;

&lt;h3 id=&quot;fonctionnel&quot;&gt;Fonctionnel&lt;/h3&gt;

&lt;p&gt;Appliquons ce pattern à notre exemple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mammal&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;mammal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{};&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;says&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;saying&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myMammal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;mammal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Herb&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;saying&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;meow&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;mammal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;says&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myCat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Henrietta&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;L’objet &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;spec&lt;/code&gt; contient toutes les informations dont le constructeur a besoin pour créer une instance.
Les propriétés sont maintenant complètement privées. Elles ne sont accessibles que par des méthodes.&lt;/p&gt;

&lt;p&gt;Un des avantages du pattern fonctionnel est de pouvoir invoquer les méthodes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;super&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;superior&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arguments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;coolcat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;super_get_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;superior&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;get_name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;like &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;super_get_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; baby&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myCoolCat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;coolcat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Bix&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myCoolCat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 'like meow Bix baby'&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Si tout est privé, l’objet est sécurisé. Les propriétés de l’objet peuvent être remplacées ou supprimées mais l’intégrité de l’objet n’est pas compromise.
Si toutes les méthodes de l’objet n’utilisent pas &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; ou &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;that&lt;/code&gt; alors l’objet est durable. Un objet durable ne peut pas être compromis. Un attaquant ne peut accéder à l’état interne de l’objet que par des méthodes définies.&lt;/p&gt;

&lt;h3 id=&quot;parties&quot;&gt;Parties&lt;/h3&gt;

&lt;p&gt;Un objet peut être construit grâce à un ensemble de parties. Une fonction peut très bien ajouter des fonctionnalités à un objet.&lt;/p&gt;

&lt;p&gt;Par exemple, on peut créer une fonction capable d’ajouter des fonctionnalités de traitement d’évènements simples à n’importe quel objet.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;eventuality&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;registry&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{};&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fire&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hasOwnProperty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;handler&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;nx&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;parameters&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;events&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;handler&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;parameters&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hasOwnProperty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;registry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;that&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;grammaire&quot;&gt;Grammaire&lt;/h2&gt;

&lt;h3 id=&quot;nombres&quot;&gt;Nombres&lt;/h3&gt;

&lt;p&gt;Javascript possède un seul type numérique représenté sous la forme d’un nombre 64 bits à virgule flottante, comme le &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;double&lt;/code&gt; Java. Il n’existe pas de type entier séparé, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.0&lt;/code&gt; correspondent à la même valeur. Il est toutefois possible d’étendre le type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Number&lt;/code&gt; pour contourner ce problème.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nb&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;integer&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ceiling&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;floor&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;integer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// -3&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;La valeur &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NaN&lt;/code&gt; est une réprésentation numérique d’une valeur non numérique. On l’obtient lorsqu’une opération numérique ne peut pas renvoyer de nombre.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NaN&lt;/code&gt; est différente de toute valeur, y compris d’elle-même. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NaN&lt;/code&gt; peut être détecté avec la fonction &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isNaN(nombre)&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;chaînes&quot;&gt;Chaînes&lt;/h3&gt;

&lt;p&gt;Tous les caractères en Javascript sont codés sur 16 bits. Les chaînes sont immuables. Une fois créée, une chaîne ne peut pas être changée.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\&lt;/code&gt; correspond au caractère d’échappement.
Les chaînes possèdent une propriété &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Il n’existe pas de méthode pour supprimer les espaces en début et fin de chaîne. Solution simple en étendant le type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; :&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;trim&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/^&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\s&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;+|&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\s&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;+$/g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;valeurs-égalent-à-false&quot;&gt;Valeurs égalent à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undefined&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;chaîne vide&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NaN&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Toutes les autres valeurs sont &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;, dont &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;, la chaîne &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt; et tous les objets.&lt;/p&gt;

&lt;h3 id=&quot;tableaux&quot;&gt;Tableaux&lt;/h3&gt;

&lt;p&gt;Les tableaux en Javascript sont sensiblement plus lent qu’un véritable tableau. Javascript convertit les indices de tableau en chaînes qui sont utilisées pour créer des propriétés. La récupération et la mise à jour fonctionnent comme avec les objets.
Les tableaux ont des méthodes intégrées de base très utiles.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;empty&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;zero&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;two&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;three&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Objet littéral :&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers_object&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;zero&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;two&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;three&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;empty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// O&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 4&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;L’objet littéral &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numbers_object&lt;/code&gt; produit un résultat similaire à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numbers&lt;/code&gt; : mêmes propriétés, même longueur.
Toutefois, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numbers_object&lt;/code&gt; hérite de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object.prototype&lt;/code&gt; alors que &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numbers&lt;/code&gt; hérite de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array.prototype&lt;/code&gt;. C’est pour cela qu’il n’est pas possible d’utiliser la propriété &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt; sur &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numbers_object&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Javascript permet aux tableaux de contenir n’importe quel type de valeurs.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;misc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;nested&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;NaN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;Infinity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;misc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 9&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;length&quot;&gt;length&lt;/h4&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt; n’est pas une limite supérieure en Javascript. Si un élément est stocké avec un indice supérieur à la valeur de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt;, alors la propriété &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt; est augmentée. Il n’y a pas d’erreur de limite. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt; correspond juste à l’index entier le plus grand du tableau + 1.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myArray&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 0&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 10001&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt; peut être définie de manière explicite. Si on l’augmente, cela n’alloue pas plus d’espace au tableau. Si on le diminue, cela supprime toutes les propriétés dont l’index est supérieur ou égal à la nouvelle valeur de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// numbers == ['zero']&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 2&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;delete&quot;&gt;delete&lt;/h4&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;zero&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;two&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;three&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// numbers == ['zero', 'one', undefined, 'three']&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;delete&lt;/code&gt; laisse un trou dans le tableau. Si on souhaite décaler les éléments du tableau, il faut préférer la méthode &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;splice&lt;/code&gt;.
Toutefois, cette méthode peut être lente pour les tableaux de grande taille.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;splice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Cela supprime 1 élément du tableau en partant de l'index 2&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// numbers == ['zero', 'one', 'three']&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;concat&quot;&gt;concat&lt;/h4&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;concat&lt;/code&gt; produit un nouveau tableau contenant une copie superficielle de ce tableau à laquelle sont ajoutés les éléments. Si un des éléments est un tableau, chacun de ses éléments est ajouté individuellement.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;concat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// c == ['a', 'b', 'c', 'x', 'y', 'z', true]&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;join&quot;&gt;join&lt;/h4&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;join&lt;/code&gt; permet de créer une chaîne à partir d’un tableau en concaténant ses éléments séparés par un séparateur. Par défaut, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;,&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// c == 'a-b-c'&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;push-et-pop&quot;&gt;push et pop&lt;/h4&gt;

&lt;p&gt;Ces méthodes permettent de faire fonctionner un tableau comme une pile. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pop&lt;/code&gt; supprimer et renvoie le dernier élément. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;push&lt;/code&gt; ajoute un élément à la fin et retourne la longueur du tableau.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// c == 'c'&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// a == ['a', 'b']&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// a == ['a', 'b', 'w']&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// b == 3&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;reverse&quot;&gt;reverse&lt;/h4&gt;

&lt;p&gt;Cette méthode inverse l’ordre des éléments d’un tableau et retourne le tableau.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// a == b == ['c', 'b', 'a']&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;shift&quot;&gt;shift&lt;/h4&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shift&lt;/code&gt; supprime et retourne le premier élément d’un tableau. Attention, cette méthode est bien plus lente que &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pop&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;shift&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// a == ['b', 'c']&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// c = 'a'&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;slice&quot;&gt;slice&lt;/h4&gt;

&lt;p&gt;Cette méthode crée une copie superficielle d’une portion d’un tableau. Elle copie de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tableau[début]&lt;/code&gt; à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tableau[fin - 1]&lt;/code&gt;. Par défaut, le paramètre &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fin&lt;/code&gt; est facultatif et il vaut &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tableau.length&lt;/code&gt;. Si un des paramètres est négatif, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tableau.length&lt;/code&gt; est ajouté afin de le rendre positif.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;slice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// b == ['a']&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;slice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// c == ['b', 'c']&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;sort&quot;&gt;sort&lt;/h4&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sort&lt;/code&gt; trie le contenu d’un tableau et le remplace. Elle présuppose que les éléments doivent être triés comme des chaînes. Elle ne vérifie pas le type des éléments avant de les comparer ce qui produit le résultat aberrant suivant :&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// n == [15, 16, 23, 4, 42, 8]&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Toutefois, la fonction de comparaison peut être remplacé. Celle-ci doit prendre deux paramètres et renvoyer :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;0 si égalité&lt;/li&gt;
  &lt;li&gt;un nombre négatif si le premier paramètre doit être placé en premier&lt;/li&gt;
  &lt;li&gt;un nombre positif si le second paramètre doit être placé en premier&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// n == [4, 8, 15, 16, 23, 42]&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Et on peut même rendre cette fonction de tri plus intelligente,&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;aa&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bb&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// m == [4, 8, 15, 16, 23, 42, 'a', 'aa', 'bb']&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;portée&quot;&gt;Portée&lt;/h2&gt;

&lt;p&gt;La portée contrôle la visibilité et les temps de vie des variables et des paramètres. Cela réduit les collisions de noms et fournit une gestion de la mémoire automatique.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// a == 3, b == 7, c == 11&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// a == 21, b == 7, c == 11&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// a == 21, b == 5&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;La plupart des langages disposent d’une portée de bloc. Les variables sont invisibles en dehors du bloc et sont libérées à la fin de l’exécution du bloc.&lt;/p&gt;

&lt;p&gt;Ce n’est pas le cas en Javascript. Il possède une portée de fonction. Les paramètres et les variables sont invisibles en dehors de la fonction. Il est préférable de déclarer toutes les variables utilisées dans une fonction en haut du corps de la fonction.&lt;/p&gt;

&lt;h3 id=&quot;closure&quot;&gt;Closure&lt;/h3&gt;

&lt;p&gt;Les fonctions internes ont accès aux paramètres et aux variables des fonctions à l’intérieur desquelles elles sont définies (à l’exception de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arguments&lt;/code&gt;). La fonction interne a accès aux variables elles-mêmes des fonctions externes et non à des copies. Cela est possible car la fonction a accès au contexte dans lequel elle a été créée.&lt;/p&gt;

&lt;p&gt;C’est une bonne chose car cela permet d’éviter le problème suivant :&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;// Objectif : Créer une fonction qui attribue correctement des fonctions de gestionnaire d'évènements à un tableau de noeuds. Lorsqu'on clique sur un noeud, une boîte d'alerte affiche l'ordinal du noeud.&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Mauvais exemple&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add_the_handlers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nodes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;nodes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;nodes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onclick&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Au lieu d'afficher l'ordinal du noeud, la boîte d'alerte va afficher le nombre de noeuds.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// La fonction échoue car les fonctions de gestionnaire sont liées à la variable i et non à la valeur de la variable i au moment où la fonction a été créée.&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Bon exemple&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add_the_handlers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nodes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;nodes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;nodes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onclick&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Au lieu d'attribuer une fonction à onclick, on invoque une fonction, en lui passant i, qui retourne une fonction de gestionnaire d'évènements liée à la valeur de i qui a été passée (et non au i défini dans add_the_handlers).&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;modules&quot;&gt;Modules&lt;/h2&gt;

&lt;p&gt;Grâce aux closures et aux fonctions, il est possible de créer des fonctions ou objets présentant une interface mais masquant son implémentation. C’est ce qu’on appelle un module.
Grâce aux fonctions pour produire des modules, il est possible d’éviter complètement les variables globales. Il est très efficace pour encapsuler des applications et produire des objets sécurisés.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;// Objectif : créer un objet qui produit des chaînes uniques composées d'un préfixe et d'un numéro de séquence.&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;serial_maker&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;prefix&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;set_prefix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;prefix&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;set_seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gensym&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;prefix&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}();&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;seqer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;serial_maker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;seqer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;set_prefix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;seqer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;set_seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;seqer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gensym&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Q1000&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Les méthodes n'utilisent pas this ou that. seqer ne peut donc pas être compromis. prefix ou seq ne peuvent pas être modifié en dehors des méthodes. seqer est mutable, ses méthodes peuvent être remplacées mais cela ne donne pas accès à prefix et seq. seqer est juste une collection de fonctions.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Si seqer.gensym est passé à une fonction tierce, cette fonction ne peut que générer des chaînes uniques.&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;objets&quot;&gt;Objets&lt;/h2&gt;

&lt;p&gt;Les types simples du Javascript sont les nombres, les chaînes, les booléens, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undefined&lt;/code&gt;. Toutes les autres valeurs sont des objets.
Les objets en Javascript sont des collections modifiables à clés. Les tableaux, les fonctions, les expressions régulières… sont des objets.
Les objets sont passés par référence. Ils ne sont jamais copiés.&lt;/p&gt;

&lt;p&gt;Les objets littéraux héritent de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object.prototype&lt;/code&gt;, un objet standard.&lt;/p&gt;

&lt;h3 id=&quot;récupération&quot;&gt;Récupération&lt;/h3&gt;

&lt;p&gt;La valeur d’un objet peut être récupérée en y accédant grâce à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[]&lt;/code&gt; ou &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 42&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bar&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 42&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;mise-à-jour&quot;&gt;Mise à jour&lt;/h3&gt;

&lt;p&gt;Une valeur d’un objet est mise à jour par attribution. Si l’objet ne possède pas déjà la propriété, il est augmenté.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;777&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;up&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;suppression&quot;&gt;Suppression&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;delete&lt;/code&gt; permet de supprimer la propriété d’un objet mais ne touche à aucun objet dans la chaîne des prototypes. Toutefois, la suppression d’une propriété d’un objet peut permettre à une propriété dans la chaîne des prototypes de ressurgir.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nx&quot;&gt;another_foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nickname&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 'Bart'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;another_foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nickname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;another_foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nickname&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Surnom du prototype : 'Homer'&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;fonctions&quot;&gt;Fonctions&lt;/h2&gt;

&lt;p&gt;Les fonctions héritent de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Function.prototype&lt;/code&gt;, qui hérite de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object.prototype&lt;/code&gt;. Elles disposent de deux propriétés supplémentaires : le contexte et le code qui implémente le comportement.&lt;/p&gt;

&lt;h3 id=&quot;patterns-dinvocation&quot;&gt;Patterns d’invocation&lt;/h3&gt;

&lt;p&gt;Il existe 4 patterns d’invocation de fonction :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pattern d’invocation de méthode&lt;/strong&gt;
Une fonction stockée sous forme de propriété d’un objet, autrement dit une méthode, est liée à cet objet lors de son invocation. Elle peut utiliser &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; pour accéder (et/ou modifier) le contexte de l’objet, elle est alors considéré comme “méthode publique”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pattern d’invocation de fonction&lt;/strong&gt;
En dehors d’un objet, une fonction est invoquée comme… une fonction ! Invoquée de cette manière, une fonction est liée à l’objet global, c’est une erreur de conception du langage. Cette erreur implique qu’une méthode ne peut pas employer de fonction interne pour l’aider car la fonction interne ne partage pas l’accès de la méthode à l’objet. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; est lié à la mauvaise valeur. Toutefois, il est possible de contourner cela en attribuant &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; à une autre variable dans la méthode. Par convention, cette variable s’appelle &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;that&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pattern d’invocation de constructeur&lt;/strong&gt;
Une fonction invoquée avec le préfixe &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; crée un nouvel objet. Par convention, ces fonctions sont affectées à des variables dont la première lettre est en majuscule.
Il est déconseillé d’utiliser ce type de fonction constructeur.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nickname&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;Foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_nickname&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nickname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myFoo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;myFoo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_nickname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// bar&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Pattern d’invocation avec &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apply&lt;/code&gt;&lt;/strong&gt;
La méthode &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apply&lt;/code&gt; permet de passer un tableau d’arguments à une fonction. Elle prend deux paramètres : la valeur qui doit être liée à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; et le tableau de paramètres.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// sum == 7&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;nicknameObject&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;nickname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Chuck&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;nickname&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_nickname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nicknameObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// status == 'Chuck'&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;arguments&quot;&gt;Arguments&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arguments&lt;/code&gt; donne à la fonction tous les arguments fournis à l’invocation.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arguments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arguments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 42&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arguments&lt;/code&gt; n’est pas un vrai tableau à cause d’une erreur de conception du langage. Il est dépourvu de toutes les méthodes de tableau sauf de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;return&quot;&gt;Return&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return&lt;/code&gt; peut être utilisé pour provoquer le retour anticipé de la fonction.
Une fonction renvoie toujours une valeur. Si elle n’est pas spécifiée, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undefined&lt;/code&gt; est retournée.&lt;/p&gt;

&lt;h2 id=&quot;exceptions&quot;&gt;Exceptions&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;throw&lt;/code&gt; interrompt l’exécution. Un objet &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exception&lt;/code&gt;, contenant les propriétés &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;message&lt;/code&gt;, est alors créé.
Si une exception est levée dans un bloc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;try&lt;/code&gt;, le contrôle passe à un unique bloc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;catch&lt;/code&gt; qui capture toutes les exceptions. Il faudra alors inspecter le nom de l’exception pour déterminer son type.&lt;/p&gt;

&lt;h2 id=&quot;bonnes-pratiques&quot;&gt;Bonnes pratiques&lt;/h2&gt;

&lt;h3 id=&quot;commentaires&quot;&gt;Commentaires&lt;/h3&gt;

&lt;p&gt;Il est préférable d’utiliser les commentaires de fin de ligne commençant par &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;//&lt;/code&gt;. Les commentaires de bloc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/* */&lt;/code&gt; ne sont pas sûrs. Par exemple, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/* var rm_a = /a*/.match(s); */&lt;/code&gt; provoque une erreur de syntaxe.&lt;/p&gt;

&lt;h3 id=&quot;variable-globale-par-application&quot;&gt;Variable globale par application&lt;/h3&gt;

&lt;p&gt;Les variables globales doivent être évitées.
L’un des moyens de minimiser leur utilisation consiste à créer une variable globale unique par application. Elle représente alors le conteneur de l’application.
Cela permettra de limiter les risques de conflits avec d’autres applications, modules ou bibliothèques. De plus, on y gagne en cohérence et lisibilité.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;MYAPP&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{};&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;MYAPP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;tableau-ou-objet-&quot;&gt;Tableau ou Objet ?&lt;/h3&gt;

&lt;p&gt;Javascript entretient lui-même une confusion entre les deux. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;typeof&lt;/code&gt; sur un tableau renvoit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;object&lt;/code&gt;.
Il est possible de corriger cela.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;is_array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// permet de rejeter null et false&lt;/span&gt;
         &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// vrai pour les objets, les tableaux et null&lt;/span&gt;
         &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// vrai pour les tableaux et généralement faux pour les objets&lt;/span&gt;
         &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;splice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// vrai pour les tableaux&lt;/span&gt;
         &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;propertyIsEnumerable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// length n'est pas énumérable (produit par une boucle for in ?) pour les tableaux&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Quoi qu’il en soit, lorsque les noms de propriété sont de petits entiers séquentiels, vous devez utiliser un tableau sinon, utilisez un objet.&lt;/p&gt;

&lt;h2 id=&quot;les-choses-pas-terribles&quot;&gt;Les choses pas terribles&lt;/h2&gt;

&lt;h3 id=&quot;variables-globales&quot;&gt;Variables globales&lt;/h3&gt;

&lt;p&gt;La pire de toute. Une variable globale est une variable visible dans toutes les portées. Elle peut être modifié à tout moment par n’importe quelle partie du programme. De plus, si des sous-programmes utilisent des variables globales dont le nom est identique, celles-ci risquent de s’interférer. Et malheureusement, Javascript ne fait pas que de les autoriser mais il en a besoin. Toutes les unités de compilation sont chargées dans un objet global commun.&lt;/p&gt;

&lt;h3 id=&quot;portée-1&quot;&gt;Portée&lt;/h3&gt;

&lt;p&gt;Javascript ne fournit pas de portée de bloc. Une variable déclarée dans un bloc est visible partout dans la fonction qui contient ce bloc. Il vaut alors mieux déclarer toutes les variables en haut de chaque fonction.&lt;/p&gt;

&lt;h3 id=&quot;insertion-du-point-virgule&quot;&gt;Insertion du point-virgule&lt;/h3&gt;

&lt;p&gt;Javascript vise à corriger les programmes erronés en insérant des &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;;&lt;/code&gt;. C’est assez horrible car il peut masquer des erreurs plus graves. Exemple pour l’instruction &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return&lt;/code&gt; :&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Ce code renvoie `undefined`&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Ce code renvoie `{ status: true }`&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;mots-réservés&quot;&gt;Mots réservés&lt;/h3&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;break&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;continue&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;instanceof&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;short&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;export&lt;/span&gt;
&lt;span class=&quot;kr&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;byte&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;super&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;native&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;synchronized&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;goto&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;private&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;transient&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;debugger&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;volatile&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;public&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;La plupart de ces mots ne sont pas utilisés dans le langage, toutefois, on ne peut y recourir pour nommer des variables ou des paramètres.&lt;/p&gt;

&lt;h3 id=&quot;parseint&quot;&gt;parseInt&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parseInt&lt;/code&gt; est une fonction qui convertit les chaînes en entier. Elle s’arrête lorsqu’elle voit un caractère qui n’est pas un chiffre. Du coup, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parseInt(&quot;16&quot;)&lt;/code&gt; est égal à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parseInt(&quot;16plop&quot;)&lt;/code&gt; sans nous alerter.
Si le premier caractère de la chaîne est “0”, la chaîne est évaluée en base 8 au lieu d’être en base 10. En base 8, 8 et 9 ne sont pas des chiffres. Du coup, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parseInt(&quot;08&quot;)&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parseInt(&quot;09&quot;)&lt;/code&gt; produisent le résultat 0. Cela est gênant quand on analyse des dates et des heures. Il est recommandé de toujours utiliser le paramètre de base de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parseInt&lt;/code&gt; pour éviter cette erreur. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parseInt(&quot;08&quot;, 10)&lt;/code&gt; vaut alors 8.&lt;/p&gt;

&lt;h3 id=&quot;virgule-flottante&quot;&gt;Virgule flottante&lt;/h3&gt;

&lt;p&gt;Les nombres binaires à virgule flottante ne sont pas capables de gérer les fractions décimales. Du coup, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.1 + 0.2&lt;/code&gt; n’est pas égal à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.3&lt;/code&gt;. Ceci est dû à l’adoption volontaire du standard IEEE 754. Cela convient à la majorité des applications mais va à l’encontre de ce que l’on a appris au collège.
Pour contourner ce problème, les valeurs monétaires peuvent être converties en valeur entières en centimes.&lt;/p&gt;</content><author><name>Julien Fusco</name></author><summary type="html">Javascript est un langage remarquablement puissant. C’est une sorte de Lisp revêtu des habits du C.</summary></entry><entry><title type="html">Gère tes tâches de fond avec Sidekiq</title><link href="https://imjufu.github.io/gere-tes-taches-de-fond-avec-sidekiq" rel="alternate" type="text/html" title="Gère tes tâches de fond avec Sidekiq" /><published>2015-01-18T00:00:00+00:00</published><updated>2015-01-18T00:00:00+00:00</updated><id>https://imjufu.github.io/gere-tes-taches-de-fond-avec-sidekiq</id><content type="html" xml:base="https://imjufu.github.io/gere-tes-taches-de-fond-avec-sidekiq">&lt;p&gt;&lt;a href=&quot;http://sidekiq.org/&quot;&gt;Sidekiq&lt;/a&gt; est un gestionnaire de tâches de fond écrit en Ruby. Il est parfois très intéressant de gérer des jobs en parallèle et de façon asynchrone.&lt;br /&gt;
Exemples : envoi de mailings, stockage de fichier en différé…&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/sidekiq/logo.png&quot; alt=&quot;Sidekiq&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;pourquoi-ne-pas-choisir-resque--il-est-plus-populaire-&quot;&gt;Pourquoi ne pas choisir Resque ? Il est plus populaire !&lt;/h2&gt;

&lt;p&gt;Certes.&lt;br /&gt;
Toutefois, contrairement à Sidekiq qui s’appuie sur du multithreading pour traiter les jobs, Resque fork un nouveau processus à chaque traitement. Pour effectuer le même travail, Resque a besoin de 10Gb de RAM alors que Sidekiq en utilise seulement 300Mb. Sidekiq ne consomme pas plus de CPU pour autant.&lt;/p&gt;

&lt;h2 id=&quot;ok-cest-cool-mais-comment-ça-marche-&quot;&gt;Ok, c’est cool. Mais comment ça marche ?&lt;/h2&gt;

&lt;p&gt;Sidekiq se décompose en trois parties : le serveur, le client et le stockage.&lt;br /&gt;
Le moteur de stockage utilisé est Redis. Une base clé-valeur simple mais très riche et performante.&lt;/p&gt;

&lt;h3 id=&quot;regardons-le-client-de-plus-près&quot;&gt;Regardons le client de plus près…&lt;/h3&gt;

&lt;p&gt;Le client tourne dans le même processus que notre application web (Rails). Il va nous permettre de pusher des tâches en fond.&lt;/p&gt;

&lt;p&gt;Prenons un worker simple :&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;# app/workers/hard_worker.rb&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HardWorker&lt;/span&gt;
  &lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Sidekiq&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Worker&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;perform&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Doing hard work'&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Si l’on souhaite programmer un job pour l’utilisateur &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PKoin&lt;/code&gt;, il suffit d’écrire :&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;HardWorker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;perform_async&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'PKoin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Notre worker va utiliser le client Sidekiq. Celui-ci va reçevoir un Hash qui représente le job à traiter.&lt;br /&gt;
La ligne du dessus peut également être écrite de la façon suivante :&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;# Lower-level generic API&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;Sidekiq&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'class'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;HardWorker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'args'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'PKoin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lorsqu’on pousse un job en background, le client reçoit une représentation du job sous forme d’un Hash, le sérialise en Json et le push dans une queue dans Redis.&lt;/p&gt;

&lt;p&gt;Étant donné que le client sérialise ses paramètres, ce dernier doit reçevoir des objets simples :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;numbers, strings, boolean, array, hash… &lt;strong&gt;OK!&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Date, Time, ActiveRecord instances… &lt;strong&gt;KO!&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;regardons-maintenant-le-serveur-de-plus-près&quot;&gt;Regardons maintenant le serveur de plus près…&lt;/h3&gt;

&lt;p&gt;Dans le but de gérer correctement le multithreading, Sidekiq s’appuie sur &lt;a href=&quot;https://github.com/celluloid/celluloid&quot;&gt;Celluloid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Quand on démarre le serveur Sidekiq, celui-ci crée un processus dans lequel il va créer plusieurs threads.&lt;br /&gt;
Il va initialiser un Manager Actor (controller). Ce Manager va initialiser un Fetcher Actor (connector) et N Processor Actor (worker).&lt;br /&gt;
Le N est configurable afin d’ajuster la concurrence souhaitée, autrement dit le nombre de jobs qui seront traités en parallèle.&lt;/p&gt;

&lt;p&gt;En vrai, ce n’est pas très compliqué. Voici un petit schéma pour illustrer tout ça.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/sidekiq/server.jpg&quot; alt=&quot;Serveur Sidekiq&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Le Fetcher Actor permet de maintenir une connexion unique et active avec Redis. Celui-ci va puller, à intervalle de temps régulier (par défaut 15 secondes), les jobs en attente de traitement.&lt;br /&gt;
Si il trouve un job en attente, il le récupère, le supprime de la base Redis et l’envoie au Manager Actor.&lt;/p&gt;

&lt;p&gt;Le Manager Actor va dispatcher les différents jobs, reçus du Fetcher, aux Processor Actors libres.&lt;/p&gt;

&lt;p&gt;Le Processor Actor reçoie un job en entrée, le traite et retourne une réponse positive ou négative au Manager. Dans le cas où le job échoue, il en profite pour mettre l’erreur dans des logs. Le Manager prendra alors la décision de renvoyer le job vers un Processor Actor (pas obligatoirement le même) afin de ré-essayer.&lt;/p&gt;

&lt;h3 id=&quot;regardons-ce-que-sidekiq-stocke-dans-redis&quot;&gt;Regardons ce que Sidekiq stocke dans Redis…&lt;/h3&gt;

&lt;p&gt;J’ai codé rapidement une petite application Rails pour faire des tests.&lt;br /&gt;
Cette application comporte 3 éléments notables :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;1 worker : &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app/workers/hard_worker.rb&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;1 tâche rake : &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lib/tasks/workers.rake&lt;/code&gt; pour nous aider à empiler des jobs&lt;/li&gt;
  &lt;li&gt;1 controller : &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app/controllers/welcome_controller.rb&lt;/code&gt; pour visualiser la base Redis&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;L’application est disponible sur github : &lt;a href=&quot;https://github.com/PKoin/sidekiq-wat-is-da-shit&quot;&gt;sidekiq-wat-is-da-shit&lt;/a&gt;. Lisez le README pour le faire tourner en local.&lt;/p&gt;

&lt;p&gt;Commençons par un test simple. Le serveur Sidekiq est éteint et on empile un job grâce à la commande :&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ bundle exec rake job:work_hard['PKoin',45]
# 55722c1724796339f0fd361b
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Dans notre application Rails de test, via l’interface Redis, on y retrouve :&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&amp;gt; COMMAND Redis: KEYS sidekiq-wat-da-shit*
sidekiq-wat-da-shit:queue:default : list
sidekiq-wat-da-shit:queues : set
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Le client a créé deux clés.&lt;br /&gt;
La première comporte la liste des jobs à dépiler dans la queue par défaut.&lt;br /&gt;
La seconde est un ensemble des différentes queues disponibles.&lt;/p&gt;

&lt;p&gt;Regardons maintenant ce que contient la queue par défaut.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&amp;gt; COMMAND Redis: LRANGE sidekiq-wat-da-shit:queue:default 0 -1
{&quot;retry&quot;:1,&quot;queue&quot;:&quot;default&quot;,&quot;class&quot;:&quot;HardWorker&quot;,&quot;args&quot;:[&quot;PKoin&quot;,&quot;45&quot;],&quot;jid&quot;:&quot;55722c1724796339f0fd361b&quot;,&quot;enqueued_at&quot;:1423177060.093096}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Bonne nouvelle, on retrouve bien notre job.&lt;/p&gt;

&lt;p&gt;Allumons maintenant le serveur afin de dépiler ce fameux job et voyons ce que contient Redis.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ bundle exec sidekiq
# 2015-02-05T23:06:21.850Z 17500 TID-ovfc0w2jk HardWorker JID-55722c1724796339f0fd361b INFO: start
# 2015-02-05T23:06:21.850Z 17500 TID-ovfc0w2jk HardWorker JID-55722c1724796339f0fd361b DEBUG: PKoin: I'm doing hard work… ZzZ
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Côté Redis,&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&amp;gt; COMMAND Redis: KEYS sidekiq-wat-da-shit*
sidekiq-wat-da-shit:MacBook-Air-de-Julien.local:17500 : hash
sidekiq-wat-da-shit:MacBook-Air-de-Julien.local:17500:workers : hash
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Deux nouvelles clés font leur apparition…&lt;br /&gt;
Regardons ce qu’elles contiennent.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&amp;gt; COMMAND Redis: HGETALL sidekiq-wat-da-shit:MacBook-Air-de-Julien.local:17500
[&quot;beat&quot;, &quot;1423177341.735065&quot;]
[&quot;info&quot;, &quot;{\&quot;hostname\&quot;:\&quot;MacBook-Air-de-Julien.local\&quot;,\&quot;started_at\&quot;:1423177276.662422,\&quot;pid\&quot;:17178,\&quot;tag\&quot;:\&quot;sidekiq-wat-is-da-shit\&quot;,\&quot;concurrency\&quot;:3,\&quot;queues\&quot;:[\&quot;default\&quot;],\&quot;labels\&quot;:[]}&quot;]
[&quot;busy&quot;, &quot;1&quot;]
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Cette première clé contient un Hash contenant les détails du serveur Sidekiq.&lt;br /&gt;
On peut également voir la variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;busy&lt;/code&gt; qui est égale à 1. Ce qui est tout à fait normal étant donné que le serveur traite notre job.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&amp;gt; COMMAND Redis: HGETALL sidekiq-wat-da-shit:MacBook-Air-de-Julien.local:17500:workers
[&quot;ovfc0w2jk&quot;, &quot;{\&quot;queue\&quot;:\&quot;default\&quot;,\&quot;payload\&quot;:{\&quot;retry\&quot;:1,\&quot;queue\&quot;:\&quot;default\&quot;,\&quot;class\&quot;:\&quot;HardWorker\&quot;,\&quot;args\&quot;:[\&quot;PKoin\&quot;,\&quot;45\&quot;],\&quot;jid\&quot;:\&quot;55722c1724796339f0fd361b\&quot;,\&quot;enqueued_at\&quot;:1423177560.7913868},\&quot;run_at\&quot;:1423177581}&quot;]
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Cette deuxième clé contient un Hash décrivant les workers en cours de traitement.&lt;br /&gt;
On peut retrouver ici notre job, qu’on a ajouté plus haut, avec une variable supplémentaire : &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;run_at&lt;/code&gt;.&lt;br /&gt;
On peut constater également que ce job n’existe plus dans la clé &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sidekiq-wat-da-shit:queue:default&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;# … 45 secondes plus tard, côté console …
2015-02-05T23:07:06.855Z 17500 TID-ovfc0w2jk HardWorker JID-55722c1724796339f0fd361b DEBUG: PKoin: IT'S OK. I'M NOT SLEEPING!
2015-02-05T23:07:06.856Z 17500 TID-ovfc0w2jk HardWorker JID-55722c1724796339f0fd361b INFO: done: 45.005 sec
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Côté Redis :&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&amp;gt; COMMAND Redis: GET sidekiq-wat-da-shit:stat:processed
1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Une nouvelle clé fait son apparition et contient un compteur des jobs terminés.&lt;/p&gt;

&lt;p&gt;Que se passe-t-il maintenant lorsqu’un worker échoue ?&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ bundle exec rake job:work_hard['britney',45]
# 1379216acfecac655c5c753f
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Côté Redis :&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&amp;gt; COMMAND Redis: ZRANGE sidekiq-wat-da-shit:retry 0 -1
{&quot;retry&quot;:1,&quot;queue&quot;:&quot;default&quot;,&quot;class&quot;:&quot;HardWorker&quot;,&quot;args&quot;:[&quot;britney&quot;,&quot;45&quot;],&quot;jid&quot;:&quot;1379216acfecac655c5c753f&quot;,&quot;enqueued_at&quot;:1423178069.9739678,&quot;error_message&quot;:&quot;Oops! I did it again.&quot;,&quot;error_class&quot;:&quot;RuntimeError&quot;,&quot;failed_at&quot;:1423178069.980392,&quot;retry_count&quot;:0}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Une nouvelle clé fait son apparition et contient les détails du job qui a échoué.&lt;br /&gt;
On retrouve le job id, le message d’erreur ainsi que la date à laquelle il a échoué.&lt;br /&gt;
Deux éléments importants :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;retry : nombre d’essai max pour notre job&lt;/li&gt;
  &lt;li&gt;retry_count : nombre d’essai total&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il me parait également important d’expliquer comment Sidekiq calcule le temps à attendre entre deux essais.&lt;br /&gt;
Entre chaque essai, Sidekiq temporise de manière exponentielle. En effet, il applique la formule suivante :&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;(retry_count ** 4) + 15 + (rand(30) * (retry_count + 1)) (i.e. 15, 16, 31, 96, 271, ... seconds + a random amount of time)
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Sidekiq va donc mettre approximativement 21 jours pour faire 25 essais sur un même job. 25 étant le nombre d’essai max par défaut. Cela nous laisse suffisamment de temps pour corriger le bug et déployer son correctif en production !&lt;/p&gt;

&lt;p&gt;Toutefois, que se passe-t-il si on atteint le nombre d’essai max ?&lt;/p&gt;

&lt;p&gt;Sidekiq fait mourir le job.&lt;/p&gt;

&lt;p&gt;Côté Redis :&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&amp;gt; COMMAND Redis: ZRANGE sidekiq-wat-da-shit:dead 0 -1
{&quot;retry&quot;:1,&quot;queue&quot;:&quot;default&quot;,&quot;class&quot;:&quot;HardWorker&quot;,&quot;args&quot;:[&quot;britney&quot;,&quot;45&quot;],&quot;jid&quot;:&quot;1379216acfecac655c5c753f&quot;,&quot;enqueued_at&quot;:1423178069.9739678,&quot;error_message&quot;:&quot;Oops! I did it again.&quot;,&quot;error_class&quot;:&quot;RuntimeError&quot;,&quot;failed_at&quot;:1423178069.980392,&quot;retry_count&quot;:1,&quot;retried_at&quot;:1423178103.004996}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Une nouvelle clé fait son apparition et contient les détails du job mort.&lt;/p&gt;

&lt;p&gt;Voilà globalement comment fonctionne Sidekiq.&lt;/p&gt;

&lt;h3 id=&quot;quelques-conseils&quot;&gt;Quelques conseils…&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Il faut absolument passer des objects simples aux workers. Ne passez pas directement vos instances Active Record !&lt;/li&gt;
  &lt;li&gt;Un worker doit être idempotent (peut être rejoué plusieurs fois) et transactionnel.&lt;/li&gt;
  &lt;li&gt;Plusieurs workers doivent pouvoir tourner en parallèle.&lt;/li&gt;
  &lt;li&gt;Utilisez un service d’erreur externe type Honeybadger, Airbrake, Rollbar, BugSnag, Sentry, Exceptiontrap, Raygun…&lt;/li&gt;
  &lt;li&gt;Monitorez vos serveurs qui font tourner Sidekiq. Par exemple, &lt;a href=&quot;http://contribsys.com/inspeqtor/&quot;&gt;Inspeqtor&lt;/a&gt; est très simple et fait parfaitement le job.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;pour-finir-quelques-avertissements&quot;&gt;Pour finir, quelques avertissements…&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Ne faites pas des dizaines de files. Sidekiq n’aime pas ça !&lt;/li&gt;
  &lt;li&gt;Il est impossible de traiter une queue en série.&lt;/li&gt;
  &lt;li&gt;Sidekiq ne garantit pas l’ordre de traitement des jobs dans une queue.&lt;/li&gt;
  &lt;li&gt;Sidekiq doit être redémarré quand le code source change.&lt;/li&gt;
  &lt;li&gt;Sidekiq fait du nettoyage tous les 6 mois : dead jobs…&lt;/li&gt;
  &lt;li&gt;Si Sidekiq part en segfault ou que la VM Ruby crash, tous les jobs qui étaient en cours d’exécution sont perdus !&lt;/li&gt;
  &lt;li&gt;Attention de bien configurer le pool de connexion d’ActiveRecord… ainsi que le nombre de connexion max du serveur de DB.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Julien Fusco</name></author><summary type="html">Sidekiq est un gestionnaire de tâches de fond écrit en Ruby. Il est parfois très intéressant de gérer des jobs en parallèle et de façon asynchrone. Exemples : envoi de mailings, stockage de fichier en différé…</summary></entry><entry><title type="html">Arrêtez d’utiliser la même clé ssh privée partout !</title><link href="https://imjufu.github.io/arretez-d-utiliser-la-meme-cle-ssh-privee-partout" rel="alternate" type="text/html" title="Arrêtez d’utiliser la même clé ssh privée partout !" /><published>2014-06-26T00:00:00+00:00</published><updated>2014-06-26T00:00:00+00:00</updated><id>https://imjufu.github.io/arretez-d-utiliser-la-meme-cle-ssh-privee-partout</id><content type="html" xml:base="https://imjufu.github.io/arretez-d-utiliser-la-meme-cle-ssh-privee-partout">&lt;p&gt;J’ai trop souvent vu des développeurs utiliser la même clé SSH pour se connecter à des services totalement différents.&lt;br /&gt;
Je suis loin d’être un expert dans le domaine mais utiliser des clés différentes n’est vraiment pas compliqué.&lt;/p&gt;

&lt;h2 id=&quot;pourquoi-ne-doit-on-pas-utiliser-le-même-couple-de-clé-ssh-publiqueprivée-de-partout-&quot;&gt;Pourquoi ne doit-on pas utiliser le même couple de clé SSH publique/privée de partout ?&lt;/h2&gt;

&lt;p&gt;Si vous utilisez une seule et même clé pour vous connecter à différents services (github, ovh, heroku…), le jour où quelqu’un dérobe votre clé privée, cette personne aura accès à tous les services en question. C’est plutôt gênant.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/meme-cle-ssh-privee/hackers-hackers-everywhere.jpg&quot; alt=&quot;Hackers everywhere!&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;quelques-recommandations&quot;&gt;Quelques recommandations&lt;/h2&gt;

&lt;p&gt;Afin de garantir un minimum de sécurité,&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Une clé est privée à un utilisateur et à une machine
    &lt;ul&gt;
      &lt;li&gt;Chacun à sa clé, les clés ne sont pas partagées entre plusieurs utilisateurs&lt;/li&gt;
      &lt;li&gt;Chaque machine d’un même utilisateur a sa propre clé&lt;/li&gt;
      &lt;li&gt;Ne pas stocker sa clé privée sur des machines intermédiaires&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Toutes les clés sont protégées par une passphrase (même si c’est chiant à taper !)
    &lt;ul&gt;
      &lt;li&gt;Les passphrases sont suffisamment complexes et différentes&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;comment-faire-&quot;&gt;Comment faire ?&lt;/h2&gt;

&lt;p&gt;Dans l’exemple qui suit, on va générer une paire de clé qui sera utilisé pour github.com uniquement.&lt;/p&gt;

&lt;h3 id=&quot;générer-une-paire-de-clé&quot;&gt;Générer une paire de clé&lt;/h3&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ssh-keygen &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; rsa &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; ~/.ssh/id_rsa,github.com &lt;span class=&quot;nt&quot;&gt;-C&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;mon_compte_github,mon_mba_2014&quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note : Il est possible de changer la passphrase ultérieurement,&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ssh-keygen &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; ~/.ssh/id_rsa,github.com &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Il faut ensuite impérativement changer les droits de la clé privée pour qu’elle soit uniquement accessible par vous.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;chmod &lt;/span&gt;600 ~/.ssh/id_rsa,github.com
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;N’oubliez pas d’associer à votre compte github la clé publique générée. &lt;a href=&quot;https://help.github.com/articles/generating-ssh-keys#step-3-add-your-ssh-key-to-github&quot;&gt;Github explique ça bien mieux que moi&lt;/a&gt; !&lt;/p&gt;

&lt;h3 id=&quot;configurer-le-client-ssh&quot;&gt;Configurer le client SSH&lt;/h3&gt;

&lt;p&gt;Il faut ensuite éditer le fichier &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.ssh/config&lt;/code&gt; pour y ajouter,&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;Host github.com
  Hostname github.com
  User mon_compte_github
  IdentityFile ~/.ssh/id_rsa,github.com
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;test-&quot;&gt;Test !&lt;/h3&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ssh &lt;span class=&quot;nt&quot;&gt;-vT&lt;/span&gt; git@github.com
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Cette commande va tenter de se connecter en SSH au serveur de github.&lt;br /&gt;
La sortie est assez verbeuse mais, normalement, vous devriez voir que votre client SSH utilise bien votre clé privée &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;id_rsa,github.com&lt;/code&gt; pour vous authentifier auprès du serveur de github,&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;debug1: Reading configuration data /Users/pkoin/.ssh/config
debug1: /Users/pkoin/.ssh/config line 5: Applying options for github.com
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.30.252.128] port 22.
debug1: Connection established.
# C'est la ligne suivante qui nous intéresse plus particulièrement
debug1: identity file /Users/pkoin/.ssh/id_rsa,github.com type 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Julien Fusco</name></author><summary type="html">J’ai trop souvent vu des développeurs utiliser la même clé SSH pour se connecter à des services totalement différents. Je suis loin d’être un expert dans le domaine mais utiliser des clés différentes n’est vraiment pas compliqué.</summary></entry><entry><title type="html">PHP Tour 2014</title><link href="https://imjufu.github.io/php-tour-2014" rel="alternate" type="text/html" title="PHP Tour 2014" /><published>2014-06-22T00:00:00+00:00</published><updated>2014-06-22T00:00:00+00:00</updated><id>https://imjufu.github.io/php-tour-2014</id><content type="html" xml:base="https://imjufu.github.io/php-tour-2014">&lt;p&gt;Le PHP Tour est une conférence organisée par l’AFUP. Elle se déroule sur deux jours et réunit des experts PHP ainsi que des conférenciers spécialistes dans leur domaine.&lt;/p&gt;

&lt;p&gt;L’édition 2014 s’est tenue à la Manufacture des Tabacs de Lyon, dans le 8ème arrondissement, le 23 et 24 juin.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/phptour-2014/phptour-2014.png&quot; alt=&quot;PHP Tour 2014&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Accompagné d’&lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#882&quot;&gt;Anne-Sophie&lt;/a&gt;, j’ai présenté &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1111&quot;&gt;comment l’équipe technique de «TEA, The Ebook Alternative» s’est montée&lt;/a&gt;.&lt;br /&gt;
Les slides sont disponibles &lt;a href=&quot;http://imjufu.github.io/on-a-monte-une-equipe-de-zero&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Accompagné de &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#883&quot;&gt;Pascal&lt;/a&gt;, j’ai également présenté &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1112&quot;&gt;comment on a fait pour améliorer la mise en place de notre environnement de développement chez TEA&lt;/a&gt;.&lt;br /&gt;
Les slides sont disponibles &lt;a href=&quot;http://imjufu.github.io/notre-env-de-dev-n-est-plus-un-bizutage&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;La liste des conférences, ainsi que les notes et commentaires donnés par le public, est disponible sur &lt;a href=&quot;https://joind.in/event/view/1705&quot;&gt;joind.in&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;coding-and-dreaming&quot;&gt;Coding and dreaming&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1076&quot;&gt;Résumé sur afup.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conférence donnée par &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#853&quot;&gt;Rasmus Lerdorf&lt;/a&gt;.&lt;br /&gt;
Slides disponibles &lt;a href=&quot;http://talks.php.net/phptour14#/&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Rasmus nous raconte les débuts de PHP : pourquoi, comment et dans quel contexte il a écrit PHP. Il nous explique aussi les débuts de l’écosystème PHP et à quel point l’ouverture du code à la communauté fut très compliqué pour lui. À chaque fois qu’un patch était soumis, il avait envie de le jeter et de le ré-écrire mais il a du faire des compromis pour le bien du langage.&lt;br /&gt;
Selon lui, à l’époque, les gens qui utilisaient PHP se foutaient de la syntaxe ou de l’écosystème autour du langage. Ils voulaient juste solutionner des problèmes. Quand il a écrit PHP, il se moquait des problématiques suivantes :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;les noms de fonction insensibles à la casse&lt;/li&gt;
  &lt;li&gt;l’inconsistance des nommages&lt;/li&gt;
  &lt;li&gt;les &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;globals&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;les &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;register_globals&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;les &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;magic_quotes&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il donne un exemple qui fait beaucoup rire les gens : l’inconsistance des paramètres &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$needle&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$haystack&lt;/code&gt; entre les fonctions de manipulation des tableaux et les fonctions de manipulation des strings,&lt;/p&gt;

&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# OMGWTFBBQ?&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_search&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$needle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$haystack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;strstr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$haystack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$needle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;in_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$needle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$haystack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;substr_count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$haystack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$needle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_key_exists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$needle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$haystack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;strchr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$haystack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$needle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Il passe ensuite sur une petite leçon de morale en nous expliquant que l’on ne devrait plus être en PHP 5.2 ou PHP 5.3. Nous devrions être au moins en PHP 5.4 !&lt;/p&gt;

&lt;p&gt;Il aborde ensuite les nouveautés de PHP 5.5 :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;les &lt;a href=&quot;http://www.php.net/manual/en/language.generators.php&quot;&gt;generators&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;les coroutines (cf. &lt;a href=&quot;http://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html&quot;&gt;article de Nikita Popov&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;le mot clé &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;finally&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;les fonctions de gestion des mots de passe
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;password_hash&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;password_verify&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Une documentation de migration très complète et fournie est disponible à l’adresse : &lt;a href=&quot;http://php.net/migration55&quot;&gt;php.net/migration55&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Il aborde ensuite les nouveautés de PHP 5.6 :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;l’amélioration de la syntaxe des fonctions variadiques&lt;/li&gt;
  &lt;li&gt;l’&lt;a href=&quot;https://wiki.php.net/rfc/argument_unpacking&quot;&gt;argument unpacking&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;les &lt;a href=&quot;https://wiki.php.net/rfc/const_scalar_exprs&quot;&gt;constant scalar expressions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;la vérification des certificats SSL par défaut (enfin !)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Une documentation de migration très complète est fourni et disponible à l’adresse : &lt;a href=&quot;http://php.net/migration56&quot;&gt;php.net/migration56&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Rasmus nous donne ensuite sa vison sur l’écosystème PHP actuel.&lt;br /&gt;
Il sépare les gens en 3 catégories : dreamer, hacker, coder.&lt;br /&gt;
Les dreamers rêvent à des choses incroyables. Ils voudraient que PHP soit 20 fois plus rapide. Ils ont beaucoup d’idées mais ils ne servent à rien.&lt;br /&gt;
Les coders sont très utiles mais trop opérationnels. Ils ne sont pas assez créatifs.&lt;br /&gt;
Les hakers dégagent des idées ultra intéressantes. Ils sont un peu fous et incontrôlables. Ils sont comme les dreamers à part qu’ils codent leurs idées.&lt;/p&gt;

&lt;h2 id=&quot;je-ne-suis-pas-quun-objet-&quot;&gt;Je ne suis pas qu’un objet !&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1090&quot;&gt;Résumé sur afup.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conférence donnée par &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#864&quot;&gt;Gérald Croes&lt;/a&gt;.&lt;br /&gt;
Slides disponibles &lt;a href=&quot;http://www.croes.org/gerald/conf/php/lyon/2014/je_ne_suis_pas_quun_objet.pdf&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Gérald nous annonce que le programme parfait n’existe pas et que le but de la conférence est d’essayer d’obtenir des applications plus solides, qui tournent et qui sont maintenables.&lt;/p&gt;

&lt;p&gt;La POO a pour but d’écrire du code ré-utilisable. Il doit être lisible par des collègues.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Any fool can write code that a computer can understand. Good programmers write code that humans can understand. &lt;strong&gt;Martin Fowler&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Un beau code est un code qui déclenche le moins de « WTFs/minute ».&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/phptour-2014/wtfm.jpg&quot; alt=&quot;WTFs/m&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Le code parfait est un code transparent. Il se comporte comme on s’y attend.&lt;/p&gt;

&lt;p&gt;Il faut choisir correctement les noms de classe, de variables…&lt;br /&gt;
Par exemple, une classe &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Services&lt;/code&gt; ne veut rien dire. Une variable nommée &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$i&lt;/code&gt; est inutile.&lt;br /&gt;
Il faut arrêter de croire que le code est lu dans sa totalité. Il est lu par morceaux.&lt;/p&gt;

&lt;p&gt;Le code est un jeu sérieux.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. &lt;strong&gt;Martin Golding&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Les commentaires sont un aveu de faiblesse.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Good code is its own best documentation. As you’re about to add a comment, ask yourself, “How can I improve the code so that this comment isn’t needed?” &lt;strong&gt;Steve McConnell&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Selon Gérald, la PHPDoc est inutile car personne ne la génère et qu’en plus elle ment très souvent.&lt;/p&gt;

&lt;p&gt;Il met en avant un paradoxe énorme en programmation : quand on commence à coder, on ne connait absolument pas le métier ! À cela, il met en avant deux concepts :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it&quot;&gt;YAGNI&lt;/a&gt; (You aren’t gonna need it)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/KISS_principle&quot;&gt;KISS&lt;/a&gt; (Keep it simple, stupid)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On programme objet mais ce n’est pas ça l’important, on n’a pas besoin d’objets. On a besoin d’une solution qui fonctionne. Il faut penser interactions.&lt;/p&gt;

&lt;p&gt;Gérald nous fait un bref rappel sur les Design Patterns : factory, decorator, adapter… Il s’agit d’un « catalogue d’architecture », d’une liste de problèmes et de solutions connus.&lt;/p&gt;

&lt;p&gt;Le principal problème des DP : avoir un marteau et penser que tous les problèmes sont des clous !&lt;/p&gt;

&lt;p&gt;Un problème récurrent chez les développeurs : Le code lasagne. Un code avec trop de couches, trop découplé.&lt;br /&gt;
Il nous conseille de ne découpler que ce dont on a besoin. Il met en avant le principe &lt;a href=&quot;http://en.wikipedia.org/wiki/SOLID&quot;&gt;SOLID&lt;/a&gt; (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion).&lt;/p&gt;

&lt;p&gt;Il fait une brève approche du &lt;a href=&quot;http://en.wikipedia.org/wiki/Domain-driven_design&quot;&gt;DDD&lt;/a&gt; (Domain Driven Design), en expliquant que le fait de parler métier avec le client permettra de leader l’architecture.&lt;/p&gt;

&lt;h2 id=&quot;introduction-à-docker-et-au-monde-des-containers&quot;&gt;Introduction à Docker et au monde des containers&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1009&quot;&gt;Résumé sur afup.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conférence donnée par &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#803&quot;&gt;Geoffrey Bachelet&lt;/a&gt;.&lt;br /&gt;
Slides disponibles &lt;a href=&quot;https://speakerdeck.com/ubermuda/introduction-a-docker&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Il nous explique la différence entre les VMs et les conteneurs. Cf. &lt;a href=&quot;http://imjufu.github.io/2013/12/19/docker.html&quot;&gt;article sur Docker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Il explique que si, dans un conteneur, aucun processus ne tourne en foreground, le conteneur n’a rien à faire et s’éteint. C’est pour cela qu’on parle de «service».&lt;/p&gt;

&lt;p&gt;Il explique brièvement les &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dockerfile&lt;/code&gt; pour éviter d’itérer à la main dans les conteneurs : modifier son conteneur, commiter, modifier, commiter…&lt;/p&gt;

&lt;p&gt;Il donne la petite astuce du &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ENV DEBIAN_FRONTEND noninteractive&lt;/code&gt; afin d’éviter les questions pénibles lors d’un &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apt-get install&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Il énumère ensuite les choses importantes, pour lui, gérées par Docker :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Le réseau : avec le “service discovery” (cela évite d’utiliser d’utiliser &lt;a href=&quot;https://github.com/coreos/etcd&quot;&gt;etcd&lt;/a&gt; ou &lt;a href=&quot;https://github.com/doorkeeper-gem/doorkeeper&quot;&gt;doorkeeper&lt;/a&gt;) et les liens entre conteneurs (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--link&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Les volumes : comme nfs mais en bien mieux (ça permet, en autre, de créer des conteneurs juste pour stocker de la data) (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--volumes-from&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Le Docker Hub : la communauté est impressionante (plus de contributeurs en 1 an que vagrant en 4 ans) et les builds sont possibles à partir de repos github directement (même les privés moyennant finance)&lt;/li&gt;
  &lt;li&gt;Docker Remote API : beaucoup de client (php, ruby…)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il reste un point noir sur lequel les équipes de Docker travaillent : l’orchestration des conteneurs. Cela peut devenir vite très pénible. Le toolkit &lt;a href=&quot;https://github.com/docker/libswarm&quot;&gt;libswarm&lt;/a&gt; a été annoncé à la DockerCon 2014 pour gérer plus facilement cela.&lt;br /&gt;
En sachant qu’il existe quand même beaucoup d’outils tiers : fig, gaudi… pour pallier cette problématique.&lt;/p&gt;

&lt;p&gt;Les principales utilités : environnement de développement, intégration continue, parallélisation des tests automatisés, déploiement continu, solution de paas privé…&lt;/p&gt;

&lt;p&gt;Durant les questions, j’ai appris également que les gens sous MacOSX utilisent &lt;a href=&quot;http://doc.ubuntu-fr.org/sshfs&quot;&gt;sshfs&lt;/a&gt; pour partager du code source entre leur host et un conteneur.&lt;/p&gt;

&lt;h2 id=&quot;comment-grapher-et-visualiser-vos-datas&quot;&gt;Comment grapher et visualiser vos datas&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1059&quot;&gt;Résumé sur afup.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conférence donnée par &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#840&quot;&gt;Grégoire Pineau&lt;/a&gt;.&lt;br /&gt;
Slides disponibles &lt;a href=&quot;https://speakerdeck.com/lyrixx/comment-grapher-et-visualiser-vos-datas-at-phptourlyon-2014&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Grégoire commence par nous expliquer pourquoi grapher.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;pour tracer le comportement des utilisateurs&lt;/li&gt;
  &lt;li&gt;pour avoir de la visibilité sur l’utilisation des features&lt;/li&gt;
  &lt;li&gt;pour mesurer les performances de l’infrastructure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il recommande de tracer absolument tout et de trier ensuite.&lt;br /&gt;
Cela permet de répondre à des questions intéressantes comme :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;nouveaux utilisateurs par jour&lt;/li&gt;
  &lt;li&gt;commentaires ajoutés&lt;/li&gt;
  &lt;li&gt;commandes validées&lt;/li&gt;
  &lt;li&gt;erreurs 500&lt;/li&gt;
  &lt;li&gt;hits par contrôleur / route&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il tente ensuite de répondre à «Comment grapher ?»&lt;/p&gt;

&lt;p&gt;Il commence par mettre en avant &lt;a href=&quot;https://graphite.readthedocs.org/en/latest/&quot;&gt;Graphite&lt;/a&gt;. C’est un outil, écrit en Python et utilisant Django, qui permet de stocker des time-series et de rendre des graphiques. Très utile mais très moche !&lt;/p&gt;

&lt;p&gt;Graphite s’appuie sur &lt;a href=&quot;http://graphite.readthedocs.org/en/latest/carbon-daemons.html&quot;&gt;Carbon&lt;/a&gt;. C’est un démon qui reçoit les métriques et les injecte dans &lt;a href=&quot;https://github.com/graphite-project/whisper&quot;&gt;Whisper&lt;/a&gt;, un outil bas niveau de stockage.&lt;/p&gt;

&lt;p&gt;Ce qui donne :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Le client (nous) (php, ruby…) envoie des données à Carbon (via tcp ou udp)&lt;/li&gt;
  &lt;li&gt;Carbon stocke les données dans Whisper&lt;/li&gt;
  &lt;li&gt;Graphite affiche des graphiques à partir des données dans Whisper&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whisper est une time series database. Très proche d’un RRD (round-robin-database). Il génère et utilise des fichiers &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wsp&lt;/code&gt; de même taille afin d’accéder le plus rapidemment aux données.&lt;/p&gt;

&lt;p&gt;Graphite va permettre de faire des comparaisons dans le temps très facilement.&lt;/p&gt;

&lt;p&gt;Grégoire nous explique qu’il faut faire attention car Graphite ne garde que la dernière valeur sur l’intervalle de temps donné. Toutefois, une solution de contournement existe : &lt;a href=&quot;https://github.com/etsy/statsd/&quot;&gt;StatsD&lt;/a&gt; (démon Node.js écrit par Etsy). Du coup, notre client communiquera directement avec StatsD, qui communiquera avec Graphite.&lt;/p&gt;

&lt;p&gt;Graphite met également à disposition une API assez complète.&lt;/p&gt;

&lt;p&gt;En Symfony2, il est possible d’écrire un MetricBundle (qui utilise le client &lt;a href=&quot;https://github.com/beberlei/metrics&quot;&gt;metrics&lt;/a&gt; ou &lt;a href=&quot;https://github.com/M6Web/Statsd&quot;&gt;StatsD&lt;/a&gt;) qui va nous permettre de :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;se brancher sur tous les listeners possibles (kernel.terminate)
    &lt;ul&gt;
      &lt;li&gt;pour grapher les temps de réponse&lt;/li&gt;
      &lt;li&gt;la mémoire&lt;/li&gt;
      &lt;li&gt;les status code&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;tracer le nombre et le type de requêtes sql / page via Doctrine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Attention au nommage des métriques. C’est très important de les choisir correctement dès le départ car on peut «glober» avec Graphite.&lt;br /&gt;
Par exemple, pour les compteurs, on peut suffixer par un verbe au passé (project.created, violation.comment.created…)&lt;/p&gt;

&lt;p&gt;Dernière recommandation : il faut absolument installer StatsD sur un SSD. Il effectue des accès au disque très importants.&lt;/p&gt;

&lt;p&gt;Pour visualiser les données, il est possible de construire des dashboards ou en utiliser des existants : &lt;a href=&quot;https://github.com/kenhub/giraffe&quot;&gt;Giraffe&lt;/a&gt;, &lt;a href=&quot;https://square.github.io/cubism/&quot;&gt;Cubism&lt;/a&gt;, &lt;a href=&quot;http://grafana.org/&quot;&gt;Grafana&lt;/a&gt;…&lt;/p&gt;

&lt;h2 id=&quot;utiliser-postgresql-en-2014&quot;&gt;Utiliser PostgreSQL en 2014&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1007&quot;&gt;Résumé sur afup.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conférence donnée par &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#800&quot;&gt;Dimitri Fontaine&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Un SGBD respectable se doit d’être &lt;a href=&quot;http://en.wikipedia.org/wiki/ACID&quot;&gt;ACID&lt;/a&gt; (atomicité, cohérence, isolation et durabilité).&lt;br /&gt;
Un SGBD n’est pas ACID si il a un mauvais système de transactions.&lt;br /&gt;
En tant qu’utilisateur, on doit pouvoir réaliser ce genre de requête :&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INDEX&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;…&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;EXPLAIN&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;ANALYSE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;…&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;ROLLBACK&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;PostgreSQL permet de faire des backups cohérents à chaud.&lt;/p&gt;

&lt;p&gt;Il assure également une réelle cohérence des données avec des typage de données assez complexe :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;tsrange : intervalle de temps&lt;/li&gt;
  &lt;li&gt;circle&lt;/li&gt;
  &lt;li&gt;iprange&lt;/li&gt;
  &lt;li&gt;point (earth distance)&lt;/li&gt;
  &lt;li&gt;array&lt;/li&gt;
  &lt;li&gt;xml&lt;/li&gt;
  &lt;li&gt;json&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PostgreSQL permet de faire des requêtes sur des ranges d’adresse ip.&lt;br /&gt;
Il permet d’utiliser l’opérateur &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;with&lt;/code&gt; qui est dans la norme sql depuis très longtemps.
Il implémente un opérateur de distance &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;-&amp;gt;&lt;/code&gt; qui peut fonctionner avec les ips, les points, les strings…&lt;br /&gt;
Il est également possible d’utiliser xpath pour faire une recherche dans des données xml et ce type de requête peut être indexé.&lt;/p&gt;

&lt;h2 id=&quot;transition-agile-4-real--meetic&quot;&gt;Transition agile 4 real @ meetic&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1119&quot;&gt;Résumé sur afup.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conférence donnée par &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#840&quot;&gt;Nicolas Kalmanovitz&lt;/a&gt; et &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#890&quot;&gt;Thomas Diavet&lt;/a&gt;.&lt;br /&gt;
Slides disponibles &lt;a href=&quot;http://fr.slideshare.net/tdiavet/transition-agile-4-real-meetic&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Les équipes de Meetic étaient organisées sur des cycles en V. Ils sont ensuite passés à SCRUM.&lt;/p&gt;

&lt;p&gt;En 2011, Meetic est un gros paquebot lent dans un milieu où tout va vite.&lt;/p&gt;

&lt;p&gt;La méthodo Scrum, facile à apprendre, allait leur permettre une approche structurée, simple et efficace des méthodes agiles.&lt;/p&gt;

&lt;p&gt;Avant de passer sous Scrum, ils sont passés sous Kanban afin de séduire la direction. Ils ont appris que c’est compliqué de mettre du Kanban directement et ça a été un échec dans leurs équipes.&lt;br /&gt;
La transition de Scrum vers Kanban est, par contre, beaucoup plus facile.&lt;/p&gt;

&lt;p&gt;Ils ont joué à &lt;a href=&quot;http://getkanban.com/&quot;&gt;GetKanban&lt;/a&gt; avec la direction pour les convaincre.&lt;/p&gt;

&lt;p&gt;Ils ont également appris que les boards physiques sont très importants. Ils permettent d’identifier rapidement les points de blocage.&lt;/p&gt;

&lt;p&gt;À l’époque, leur équipe était dispersée. Le Scrum Master, les développeurs, les intégrateurs et les testeurs ne travaillent pas ensemble physiquement. Ils ont décidé de les rapprocher et ça a vraiment tout changé chez eux.&lt;/p&gt;

&lt;p&gt;Ils ont plusieurs équipes sous SCRUM mais chaque équipe fait maximum 8 membres.  Ils sont sous des sprints de 15 jours.&lt;br /&gt;
Ils font des releases toutes les 2 semaines.&lt;br /&gt;
Ils travaillent sous git avec un vrai travail sur les branches.&lt;/p&gt;

&lt;p&gt;Ils obtiennent plus d’autonomie, plus de communication, une meilleure priorisation et une amélioration de la qualité assez rapidement.&lt;/p&gt;

&lt;p&gt;Ce qu’ils ont appris :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;il faut de l’accompagnement : sinon démonstration ratée, sprint raté…&lt;/li&gt;
  &lt;li&gt;il ne faut pas plusieurs PO : sinon chevauchement des responsabilités&lt;/li&gt;
  &lt;li&gt;il fallait qu’il retravaillent leur time to market : problématique des releases toutes les 2 semaines alors que la feature était finalisé pendant le sprint&lt;/li&gt;
  &lt;li&gt;l’outillage est très important&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Afin de réduire le time-to-market, ils ont travaillé sur :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;le Quality Driven Development&lt;/li&gt;
  &lt;li&gt;de l’intégration continue (puppet, capistrano)&lt;/li&gt;
  &lt;li&gt;de l’industrialisation&lt;/li&gt;
  &lt;li&gt;de la refonte&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ils ont fait appel à un consultant pour appuyer leur choix d’agilité, faire de la formation et de la conduite de changement. Ça leur a été très bénéfique.&lt;/p&gt;

&lt;h2 id=&quot;take-a-walk-on-the-ops-side&quot;&gt;Take a walk on the OPS side&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1036&quot;&gt;Résumé sur afup.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conférence donnée par &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#822&quot;&gt;Baptiste Dupain&lt;/a&gt;.&lt;br /&gt;
Slides disponibles &lt;a href=&quot;http://fr.slideshare.net/bdu_p/take-a-walk-on-the-ops-side-php-tour-2014&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Baptiste nous explique tout d’abord comment debugger php sans php avec &lt;a href=&quot;http://www.sysdig.org/&quot;&gt;sysdig&lt;/a&gt;. Cela permet, par exemple, de faire remonter des instructions &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt; sans timeout (60s par defaut, c’est énorme !) qui peuvent faire tomber un site.&lt;/p&gt;

&lt;p&gt;On peut également faire ressortir toutes les requêtes sql grâce à :&lt;/p&gt;
&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sysdig &lt;span class=&quot;nt&quot;&gt;-w&lt;/span&gt; php.scap proc.name&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;php
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sysdig &lt;span class=&quot;nt&quot;&gt;-A&lt;/span&gt; proc.name&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;php5-fpm and evt.buffer contains SELECT
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Il nous explique ensuite comment surveiller et mesurer des données grâce aux outils comme :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;collectd : données systèmes CPU, Ram, I/O, Net&lt;/li&gt;
  &lt;li&gt;sensu : monitoring distribué (basé sur RabbitMQ) -&amp;gt; hipchat, http, logstash&lt;/li&gt;
  &lt;li&gt;seyren : alerting basé sur des seuils Graphite (send to hipchat)&lt;/li&gt;
  &lt;li&gt;mayday : (mieux que seyren) contextualise l’alerte&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il tente ensuite de nous expliquer comment donner du sens à ses logs :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;logs http : roadster&lt;/li&gt;
  &lt;li&gt;logs php : script python&lt;/li&gt;
  &lt;li&gt;logs mysql : anemometer&lt;/li&gt;
  &lt;li&gt;logs firewall / syslog : rsyslog central&lt;/li&gt;
  &lt;li&gt;logs dev : ELK&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chez M6Web, les logs représentent entre 450 et 700 millions de lignes par jour.&lt;/p&gt;

&lt;p&gt;Ils en utilisent à peine 50% via :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;elasticsearch, logstash, kibana&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/bleskes/sense&quot;&gt;Sense&lt;/a&gt; et &lt;a href=&quot;https://github.com/lmenezes/elasticsearch-kopf&quot;&gt;Kopf&lt;/a&gt; permettent de rendre plus facile les devs sur elasticsearch. Il existe &lt;a href=&quot;grokdebug.herokuapp.com&quot;&gt;grokdebug.herokuapp.com&lt;/a&gt; pour tester des configurations pour logstash.&lt;/p&gt;

&lt;p&gt;Il présente ensuite le projet &lt;a href=&quot;http://www.r-project.org/&quot;&gt;R&lt;/a&gt;, le Excel du hipster. C’est un outil simple pour les stats et du machine learning.&lt;/p&gt;

&lt;p&gt;Il nous explique ensuite pourquoi bencher son applicatif est important :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;test de charge
    &lt;ul&gt;
      &lt;li&gt;capable de tenir 50K users ?&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;test de stress
    &lt;ul&gt;
      &lt;li&gt;jusqu’où on peut tenir ?&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;test de perf
    &lt;ul&gt;
      &lt;li&gt;xp utilisateur&lt;/li&gt;
      &lt;li&gt;qu’est-ce qui est acceptable ?&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Et il nous donne des outils pour faire cela :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://jmeter.apache.org/&quot;&gt;jmeter&lt;/a&gt; &amp;amp; &lt;a href=&quot;http://gatling-tool.org/&quot;&gt;gatling&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.joedog.org/siege-home/&quot;&gt;siege&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/wg/wrk&quot;&gt;wrk&lt;/a&gt; : plus simple que siege&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://tsung.erlang-projects.org/&quot;&gt;tsung&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/buger/gor&quot;&gt;gor&lt;/a&gt; : réplique le traffic en temps réel&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quelques saas :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;blitz.io&quot;&gt;blitz.io&lt;/a&gt; : bourrin, gratuit&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blazemeter.com/&quot;&gt;blazemeter&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.neotys.fr/&quot;&gt;neotys&lt;/a&gt; : les meilleurs du test de charge&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;comment-migrer-un-projet-majeur-sous-symfony2-&quot;&gt;Comment migrer un projet majeur sous Symfony2 ?&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://afup.org/pages/phptourlyon2014/sessions.php#1101&quot;&gt;Résumé sur afup.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conférence donnée par &lt;a href=&quot;http://afup.org/pages/phptourlyon2014/conferenciers.php#873&quot;&gt;Thomas Rabaix&lt;/a&gt; de l’équipe &lt;a href=&quot;http://www.ekino.com/&quot;&gt;Ekino&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Avant de commencer à coder, il ont mis en place un Wiki sur lequel ils ont partagé toute la connaissance acquise sur le métier.&lt;/p&gt;

&lt;p&gt;Ils ont ensuite réalisé un audit interne :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;650K loc&lt;/li&gt;
  &lt;li&gt;Zend1, toupti1, toupti2, framework interne&lt;/li&gt;
  &lt;li&gt;moteur de template smarty&lt;/li&gt;
  &lt;li&gt;250 méthodes REST&lt;/li&gt;
  &lt;li&gt;beaucoup de code dupliqué&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;L’architecture était très complexe.&lt;/p&gt;

&lt;p&gt;Ils ont effectué une migration en plusieurs étapes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ÉTAPE 0 : Réfléchir&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Création d’un outil interne pour comprendre l’architecture en place par l’analyse du code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Étape 1 : Industrialiser&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Le but est de ne pas perdre du temps sur ce qui n’est pas important et répétitif.&lt;br /&gt;
Il s’agit pour lui du point le plus important.&lt;/p&gt;

&lt;p&gt;Ils ont utilisé :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;vagrant et puppet pour les envs de dev&lt;/li&gt;
  &lt;li&gt;github et jira pour le code support&lt;/li&gt;
  &lt;li&gt;un mirroring packagist&lt;/li&gt;
  &lt;li&gt;jenkins pour piloter le tout&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Étape 2 : Refonte&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ils ont entamé la refonte du modèle de données sous Doctrine. Ils ont écrit un data mapper pour lire de l’atom (ORM/Atom). Et ils ont mis en place un Symfony2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Étape 3 : Migration du code legacy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ils ont porté le code legacy dans un répertoire spécifique de la nouvelle application. Ils ont utilisé le mode multi-kernel pour sf2.&lt;/p&gt;

&lt;p&gt;Ils ont créé un bundle crade (DigipostLegacy) pour permettre la transition et l’encapsulation de l’ancien code legacy. Exemple d’utilisation :&lt;/p&gt;

&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Cature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mon&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legacy&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;php&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Avant la refonte, ils ont mis en place des tests pour s’assurer que rien ne cassait. Ils ont appelé l’outil «Maniac», assez fun :-)&lt;br /&gt;
Ils ont activé le code coverage via phpunit afin de détecter du code mort, et des parties non couvertes.&lt;/p&gt;</content><author><name>Julien Fusco</name></author><summary type="html">Le PHP Tour est une conférence organisée par l’AFUP. Elle se déroule sur deux jours et réunit des experts PHP ainsi que des conférenciers spécialistes dans leur domaine.</summary></entry><entry><title type="html">Dnsmasq pour ton environnement de développement</title><link href="https://imjufu.github.io/dnsmasq-pour-ton-environnement-de-developpement" rel="alternate" type="text/html" title="Dnsmasq pour ton environnement de développement" /><published>2014-05-20T00:00:00+00:00</published><updated>2014-05-20T00:00:00+00:00</updated><id>https://imjufu.github.io/dnsmasq-pour-ton-environnement-de-developpement</id><content type="html" xml:base="https://imjufu.github.io/dnsmasq-pour-ton-environnement-de-developpement">&lt;p&gt;C’est pas le tout de monter un bel environnement de développement à grand coup de Vagrant, Docker, et VirtualBox, mais encore faut-il pouvoir y accéder.&lt;/p&gt;

&lt;p&gt;Pour cela, il existe la solution classique de modification du fichier &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/hosts&lt;/code&gt;. Toutefois, cela est assez pénible car il faut le modifier à chaque fois qu’on créé un nouveau projet et cela nécessite obligatoirement les droits root sur la machine. Pas cool !&lt;/p&gt;

&lt;p&gt;Une autre approche (plus belle et plus pratique !) consiste à utiliser un serveur DNS en local. Contrairement à ce que l’on peut penser, cette approche n’est pas très compliqué et offre une plus grande souplesse de configuration.&lt;/p&gt;

&lt;p&gt;Dans cet article, je vais utiliser &lt;a href=&quot;http://www.thekelleys.org.uk/dnsmasq/doc.html&quot;&gt;Dnsmasq&lt;/a&gt; sous un environnement Mac OSX (10.9.2) disposant de &lt;a href=&quot;http://brew.sh/&quot;&gt;Homebrew&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Pourquoi Dnsmasq ? Tout simplement car :&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Dnsmasq est un serveur léger pour fournir les services DNS, DHCP, Bootstrap Protocol et TFTP pour un petit réseau, voire pour un poste de travail. &lt;strong&gt;&lt;a href=&quot;http://fr.wikipedia.org/wiki/Dnsmasq&quot;&gt;Wikipédia&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tout d’abord, installons le serveur.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;brew &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;dnsmasq
&lt;span class=&quot;o&quot;&gt;==&amp;gt;&lt;/span&gt; Downloading https://downloads.sf.net/project/machomebrew/Bottles/dnsmasq-2.71.mavericks.bottle.tar.gz
&lt;span class=&quot;c&quot;&gt;######################################################################## 100,0%&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;==&amp;gt;&lt;/span&gt; Pouring dnsmasq-2.71.mavericks.bottle.tar.gz
&lt;span class=&quot;o&quot;&gt;==&amp;gt;&lt;/span&gt; Caveats
To configure dnsmasq, copy the example configuration to /usr/local/etc/dnsmasq.conf
and edit to taste.

  &lt;span class=&quot;nb&quot;&gt;cp&lt;/span&gt; /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

To have launchd start dnsmasq at startup:
    &lt;span class=&quot;nb&quot;&gt;sudo cp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-fv&lt;/span&gt; /usr/local/opt/dnsmasq/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;.plist /Library/LaunchDaemons
Then to load dnsmasq now:
    &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
&lt;span class=&quot;o&quot;&gt;==&amp;gt;&lt;/span&gt; Summary
   /usr/local/Cellar/dnsmasq/2.71: 7 files, 488K
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Et là, Homebrew est sympa car il nous explique comment configurer notre serveur.&lt;/p&gt;

&lt;p&gt;On commence donc par mettre en place la configuration locale.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cp&lt;/span&gt; /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On fait en sorte que Dnsmasq se lance automatiquement au démarrage de la session.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo cp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-fv&lt;/span&gt; /usr/local/opt/dnsmasq/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;.plist /Library/LaunchDaemons
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Et enfin, on démarre le serveur.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Passons maintenant au plus intéressant : la configuration.&lt;/p&gt;

&lt;p&gt;Prenons un exemple concret.&lt;br /&gt;
Nous souhaitons que toutes les requêtes, qui se terminent par &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.lxc&lt;/code&gt;, retournent &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Comme nous l’avons vu plus haut, le fichier par défaut de configuration se trouve dans &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/local/etc/dnsmasq.conf&lt;/code&gt;. Nous allons donc l’éditer pour ajouter la ligne suivante à la fin.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;address&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/lxc/127.0.0.1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nous devons recharger le serveur pour prendre en compte cette nouvelle configuration.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;launchctl stop homebrew.mxcl.dnsmasq
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;launchctl start homebrew.mxcl.dnsmasq
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Faisons un test en utilisant notre résolveur.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;dig foobar.lxc @127.0.0.1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Normalement, vous devriez obtenir la réponse suivante.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;;;&lt;/span&gt; ANSWER SECTION:
foobar.lxc.     0   IN  A   127.0.0.1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Tout cela est très bien mais pour l’instant notre résolveur DNS n’est pas reconnu par notre système.&lt;br /&gt;
Pas de panique, c’est super simple grâce aux fichiers &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resolvers&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;On commence par préparer le système si ce n’est pas déjà fait.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; /etc/resolver
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Il suffit ensuite de créer un fichier pour chaque résolveur que nous souhaitons ajouter à notre système.&lt;br /&gt;
&lt;strong&gt;Attention&lt;/strong&gt;, le fichier doit porter le même nom que le domaine principal.&lt;/p&gt;

&lt;p&gt;Dans notre exemple, nous cherchons à rediriger les requêtes se terminant par &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.lxc&lt;/code&gt; à notre serveur DNS local. Nous créons donc le fichier &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/resolver/lxc&lt;/code&gt; contenant l’instruction suivante.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;nameserver 127.0.0.1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Regardons si nous n’avons rien cassé.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ping &lt;span class=&quot;nt&quot;&gt;-c1&lt;/span&gt; www.google.com
PING www.google.com &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;173.194.40.177&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;: 56 data bytes
64 bytes from 173.194.40.177: &lt;span class=&quot;nv&quot;&gt;icmp_seq&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;nv&quot;&gt;ttl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;54 &lt;span class=&quot;nb&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;39.117 ms

&lt;span class=&quot;nt&quot;&gt;---&lt;/span&gt; www.google.com ping statistics &lt;span class=&quot;nt&quot;&gt;---&lt;/span&gt;
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 39.117/39.117/39.117/0.000 ms
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Et enfin, regardons si notre requête à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foobar.lxc&lt;/code&gt; répond favorablement.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ping &lt;span class=&quot;nt&quot;&gt;-c1&lt;/span&gt; foobar.lxc
PING foobar.lxc &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;127.0.0.1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;: 56 data bytes
64 bytes from 127.0.0.1: &lt;span class=&quot;nv&quot;&gt;icmp_seq&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;nv&quot;&gt;ttl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;64 &lt;span class=&quot;nb&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0.034 ms

&lt;span class=&quot;nt&quot;&gt;---&lt;/span&gt; foobar.lxc ping statistics &lt;span class=&quot;nt&quot;&gt;---&lt;/span&gt;
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 0.034/0.034/0.034/0.000 ms
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Julien Fusco</name></author><summary type="html">C’est pas le tout de monter un bel environnement de développement à grand coup de Vagrant, Docker, et VirtualBox, mais encore faut-il pouvoir y accéder.</summary></entry><entry><title type="html">Ruby style guide</title><link href="https://imjufu.github.io/ruby-style-guide" rel="alternate" type="text/html" title="Ruby style guide" /><published>2014-05-15T00:00:00+00:00</published><updated>2014-05-15T00:00:00+00:00</updated><id>https://imjufu.github.io/ruby-style-guide</id><content type="html" xml:base="https://imjufu.github.io/ruby-style-guide">&lt;p&gt;Voici maintenant quelques mois que je code en Ruby et je n’ai jamais pris le temps de centraliser les bonnes pratiques. Il est donc temps de m’y mettre !&lt;br /&gt;
Je me suis grandement inspiré de l’excellent &lt;a href=&quot;https://github.com/bbatsov/ruby-style-guide&quot;&gt;The Ruby Style Guide&lt;/a&gt;.&lt;br /&gt;
Surtout, ne lisez pas la traduction française, elle n’est pas à jour, incomplète et parfois fausse !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/ruby-style-guide/ruby.png&quot; alt=&quot;Ruby&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Il existe plusieurs outils en ligne de commande pour vérifier le bon respect de ce guide mais, personnellement, j’utilise &lt;a href=&quot;https://github.com/bbatsov/rubocop&quot;&gt;Rubocop&lt;/a&gt;.&lt;br /&gt;
Sachez aussi que vous pouvez écrire du code ruby plus “safe” grace à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ruby -w&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;encodage-des-fichiers&quot;&gt;Encodage des fichiers&lt;/h2&gt;

&lt;p&gt;UTF-8 par défaut.&lt;/p&gt;

&lt;p&gt;Les différentes versions de Ruby n’ont pas toujours utilisé le même encodage par défaut :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ruby &amp;lt;= 1.8 n’avait pas de notion d’encodage. Les chaînes étaient plus ou moins des tableaux d’octets&lt;/li&gt;
  &lt;li&gt;ruby 1.9 utilisait l’US_ASCII comme encodage par défaut. Il était possible de définir l’encodage en UTF-8 en ajoutant en haut de fichier : &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;# encoding: utf-8&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;ruby &amp;gt;= 2.0 utilise l’UTF-8 par défaut&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;espacement--saut-de-ligne&quot;&gt;Espacement &amp;amp; Saut de ligne&lt;/h2&gt;

&lt;p&gt;Utilisez des espaces autour des opérateurs, après les &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;;&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;,&lt;/code&gt;, autour de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{&lt;/code&gt; et devant &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;}&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Hi'&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;some&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;other&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;L’opérateur d’exposant est la seule exception.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Pas d’espace après &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[&lt;/code&gt; ou devant &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;]&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;)&lt;/code&gt;.&lt;br /&gt;
Pas d’espace entre le nom d’une méthode et la parenthèse d’ouverture.&lt;br /&gt;
Pas d’espace après &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;some&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;other&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;length&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;something&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez des espaces autour de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt; lors de l’assignement des valeurs par défaut aux paramètres de méthode.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;some_method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arg1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# do something...&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Sautez des lignes entre les &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;def&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;some_method&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;some_method&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Pensez à entourer le code interpolé d’un espace. Cela permet de mieux distinguer le code de la chaîne de caractères.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;last_name&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;first_name&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;identation--alignement&quot;&gt;Identation &amp;amp; Alignement&lt;/h2&gt;

&lt;p&gt;Utilisez deux espaces par niveau d’indentation.  Pas de tabulation.&lt;/p&gt;

&lt;p&gt;Indentez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;when&lt;/code&gt; au même niveau que &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;case&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;song&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Misty'&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Not again!'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;song&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;duration&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;120&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Too long!'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;hour&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;21&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;It's too late&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;song&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;play&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;kind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;year&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1850&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1889&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Blues'&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1890&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1909&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Ragtime'&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1910&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1929&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'New Orleans Jazz'&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1930&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1939&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Swing'&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1940&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1950&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Bebop'&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Jazz'&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Alignez les paramètres de l’appel de méthode s’ils s’étalent sur plus d’une ligne.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;send_mail&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;Mailer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;deliver&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;to: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'bob@example.com'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                 &lt;span class=&quot;ss&quot;&gt;from: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'us@example.com'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                 &lt;span class=&quot;ss&quot;&gt;subject: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Important message'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                 &lt;span class=&quot;ss&quot;&gt;body: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;lisibilité&quot;&gt;Lisibilité&lt;/h2&gt;

&lt;p&gt;Utilisez RDoc et ses conventions pour la documentation d’API.&lt;br /&gt;
Limiter les lignes à 80 caractères.&lt;br /&gt;
Utiliser des fins de ligne de type Unix.&lt;br /&gt;
Ne laisser pas des espaces en fin de ligne.&lt;/p&gt;

&lt;p&gt;Ajoutez des tirets bas aux grands expressions numériques.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;num&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000_000&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Évitez les prolongements de ligne &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\&lt;/code&gt;. Sauf dans le cas de prolongement de chaine.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;long_string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'First part of the long string'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;
              &lt;span class=&quot;s1&quot;&gt;' and second part of the long string'&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;N’utilisez pas de parenthèses autour des conditions d’un &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unless&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;while&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;until&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;||=&lt;/code&gt; pour initialiser des variables uniquement si elles ne le sont pas déjà.&lt;br /&gt;
Ne l’utilisez pas pour des variables booléennes.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Bozhidar'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;enabled&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&amp;amp;=&lt;/code&gt; pour changer la valeur d’une variable qui existe déjà. Cela supprime l’intérêt de tester son existance avec &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;something&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;something&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;downcase&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Préfixez par &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_&lt;/code&gt; les paramètres de bloc et les variables locales inutilisés.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;something&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;used_var&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;something_else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# ...&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[*var]&lt;/code&gt; ou &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array()&lt;/code&gt;, au lieu de d’une vérification explicite, lorsque vous voulez traiter une variable comme un &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; mais vous n’êtes pas sûr que c’est un &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez les plages ou &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Comparable#between?&lt;/code&gt; au lieu d’une comparaison logique complexe.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;include?&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;between?&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Préférez les méthodes dédiées aux comparaisons explicites avec &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;. Sauf pour les numériques.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;even?&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;odd?&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zero?&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ne faites pas de vérification non-&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nil&lt;/code&gt; sauf sur les valeurs booléennes.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;something&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;value_set?&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;vi&quot;&gt;@some_boolean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Préférez :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;collect&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;find&lt;/code&gt; à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;detect&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;select&lt;/code&gt; à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;find_all&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reduce&lt;/code&gt; à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inject&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;size&lt;/code&gt; à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count&lt;/code&gt; ou &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lenght&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Privilégiez la notation littérale pour créer des tableaux ou des hashs (sauf si vous devez passer des paramètres à leurs constructeurs).&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;arr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Privilégiez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%w&lt;/code&gt; à la syntaxe littérale de création de tableau quand vous avez besoin d’un tableau de chaines de caractères.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;STATES&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%w(draft open closed)&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Privilégiez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%i&lt;/code&gt; à la syntaxe littérale de création de tableau quand vous avez besoin d’un tableau de symboles.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;STATES&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%i(draft open closed)&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;bonnes-pratiques&quot;&gt;Bonnes pratiques&lt;/h2&gt;

&lt;p&gt;Quand vous concevez des hiérarchies de classes, assurez-vous qu’elles sont conformes au &lt;a href=&quot;http://fr.wikipedia.org/wiki/Principe_de_substitution_de_Liskov&quot;&gt;Principe de substitution de Liskov&lt;/a&gt; et essayez de les rendre aussi &lt;a href=&quot;http://en.wikipedia.org/wiki/SOLID_\(object-oriented_design\)&quot;&gt;SOLIDES&lt;/a&gt; que possible.&lt;/p&gt;

&lt;p&gt;Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;::&lt;/code&gt;seulement pour référencer des constantes (de classes ou de modules) et des constructeurs (comme &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array()&lt;/code&gt; ou &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Nokogiri::HTML()&lt;/code&gt;). Jamais pour invoquer des méthodes.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;SomeClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;some_method&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;some_object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;some_method&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;SomeModule&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;SomeClass&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;SOME_CONST&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;SomeModule&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;SomeClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Tirez parti du fait que &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;case&lt;/code&gt; sont des expressions qui renvoient un résultat.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;condition&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;N’utilisez jamais &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;and&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;or&lt;/code&gt;. Ils sont bannis.&lt;br /&gt;
Utilisez toujours &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&amp;amp;&lt;/code&gt; et &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;||&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;N’utilisez jamais &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for&lt;/code&gt;. Utiliser &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;each&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Evitez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self&lt;/code&gt; quand il n’est pas nécessaire. Il est nécessaire uniquement pour appeller un accesseur d’écriture local.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ready?&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last_reviewed_at&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last_updated_at&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;worker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:in_progress&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:verified&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$stdout/$stderr/$stdin&lt;/code&gt; au lieu de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;STDOUT/STDERR/STDIN&lt;/code&gt;.&lt;br /&gt;
Ce sont des constantes, vous pouvez les ré-assigner et vous aurez un avertissement de la part de l’interpréteur.&lt;/p&gt;

&lt;p&gt;Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;warn&lt;/code&gt; au lieu de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$stderr.puts&lt;/code&gt;.&lt;br /&gt;
Plus clair, plus concis. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;warn&lt;/code&gt; vous permet également de supprimer les avertissements au besoin (en définissant le niveau d’avertissement à 0 via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-W0&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Préférez les modules aux classes qui comportent uniquement des méthodes. Les classes doivent être utilisé uniquement si il y a un intérêt de créer une instance de ces-dernières.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;# bad&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SomeClass&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;some_method&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# body omitted&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;some_other_method&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# good&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;SomeClass&lt;/span&gt;
  &lt;span class=&quot;kp&quot;&gt;module_function&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;some_method&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# body omitted&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;some_other_method&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Fournissez toujours une méthode &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;to_s&lt;/code&gt; qui représente vos objets.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Person&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;attr_reader&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:first_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:last_name&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@first_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first_name&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@last_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last_name&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;to_s&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;vi&quot;&gt;@first_name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;vi&quot;&gt;@last_name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Privilégiez le &lt;a href=&quot;http://fr.wikipedia.org/wiki/Duck_typing&quot;&gt;duck-typing&lt;/a&gt; plutôt que l’héritage.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;# bad&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Animal&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# abstract method&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;speak&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# extend superclass&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Duck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Animal&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;speak&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Quack! Quack'&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# extend superclass&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Dog&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Animal&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;speak&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Bau! Bau!'&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# good&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Duck&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;speak&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Quack! Quack'&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Dog&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;speak&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Bau! Bau!'&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;def self.method&lt;/code&gt; pour définir les méthodes statiques.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TestClass&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;some_other_method&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# body omitted&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;# Also possible and convenient when you&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# have to define many singleton methods.&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;first_method&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# body omitted&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;second_method_etc&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# body omitted&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Set&lt;/code&gt; au lieu de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; quand vous travaillez sur des éléments uniques.&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Set&lt;/code&gt; implémente une collection de valeurs uniques désordonnées. C’est un mélange entre les fonctionnalités pratiques et intuitives d’un &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; et l’accès rapide dans un &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hash&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Préférez les symboles aux chaines pour les clés dans un &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hash&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nb&quot;&gt;hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;one: &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;two: &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;three: &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hash#fetch&lt;/code&gt; quand vous souhaitez récupérer une clé présente dans un &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hash&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;heroes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;batman: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Bruce Wayne'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;superman: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Clark Kent'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# bad - if we make a mistake we might not spot it right away&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;heroes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:batman&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; &quot;Bruce Wayne&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;heroes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:supermann&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; nil&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# good - fetch raises a KeyError making the problem obvious&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;heroes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:supermann&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Jouez avec &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hash#fetch&lt;/code&gt; pour définir une valeur par défaut lorsque la clé n’existe pas dans un &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hash&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;batman&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;name: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Bruce Wayne'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;is_evil: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# bad - if we just use || operator with falsy value we won't get the expected result&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;batman&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:is_evil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; true&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# good - fetch work correctly with falsy values&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;batman&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:is_evil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; false&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Si vous avez besoin de transiter par une méthode pour récupérer la valeur par défaut, utilisez un block. La méthode sera appelée uniquement si besoin.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;batman&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:powers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_batman_powers&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Evitez d’utiliser &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String#+&lt;/code&gt; pour assembler de longues chaînes de caractères.&lt;br /&gt;
Utilisez plutôt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String#&amp;lt;&amp;lt;&lt;/code&gt; qui transforme la chaîne sur place et s’avère toujours plus rapide que &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String#+&lt;/code&gt;, qui crée beaucoup de nouveaux objets.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;''&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&amp;lt;h1&amp;gt;Page title&amp;lt;/h1&amp;gt;'&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;paragraphs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;paragraph&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;paragraph&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;lt;/p&amp;gt;&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;nommage&quot;&gt;Nommage&lt;/h2&gt;

&lt;p&gt;Utilisez le &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;snake_case&lt;/code&gt; pour :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;les symboles, les méthodes et les variables&lt;/li&gt;
  &lt;li&gt;les noms de fichier (ex: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hello_world.rb&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;les noms de répertoire (ex: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lib/hello_world/hello_world.rb&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;ss&quot;&gt;:some_symbol&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;some_var&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;some_method&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez le &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CamelCase&lt;/code&gt; pour les classes et les modules.&lt;br /&gt;
Conservez les acronymes comme HTTP, RFC, XML en &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uppercase&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SomeClass&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SomeXML&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Essayez d’avoir une classe ou un module par fichier. Nommez ce fichier avec le nom de la classe ou du module, en remplacant le &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CamelCase&lt;/code&gt; par du &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;snake_case&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Utilisez le &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SCREAMING_SNAKE_CASE&lt;/code&gt; pour les constantes.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;SOME_CONST&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Seulement les méthodes qui retournent une valeur booléenne doivent se finir par &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;bar&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;empty?&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Les méthodes dangereuses (qui modifient &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self&lt;/code&gt; ou les arguments, …) doivent se finir par &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt;. Une version plus sûr de la méthode dangereuse doit toujours exister.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Person&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;update!&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;commentaires&quot;&gt;Commentaires&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Un code de qualité constitue sa propre documentation. Quand vous êtes sur le point d’ajouter un commentaire, demandez-vous, “Comment puis-je améliorer le code pour que ce commentaire ne soit pas nécessaire ?” Améliorez le code et documentez le ensuite pour le rendre encore plus limpide. &lt;em&gt;Steve McConnell&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Utilisez :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TODO&lt;/code&gt; pour marquer les fonctionnalités manquantes ou qui devraient être ajoutées ultérieurement&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FIXME&lt;/code&gt; pour signaler un code erroné qui doit être corrigé&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OPTIMIZE&lt;/code&gt; pour signaler un code lent ou inefficace pouvant poser des problèmes de performance&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HACK&lt;/code&gt; pour signaler un code qui semble être issu de pratiques d’écriture douteuses qui devrait être refactorisé&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REVIEW&lt;/code&gt; pour signaler toute chose devant être vérifiée pour confirmer qu’elle fonctionne comme prévu. Par exemple: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REVIEW: Are we sure this is how the client does X currently?&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;d’autres mots clés d’annotation personnalisés si vous considérez que c’est approprié, mais assurez-vous de les documenter dans le README de votre projet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;exceptions&quot;&gt;Exceptions&lt;/h2&gt;

&lt;p&gt;Signalez les exceptions en utilisant la méthode &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fail&lt;/code&gt;.&lt;br /&gt;
Utilisez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;raise&lt;/code&gt; uniquement lorsque vous capturez une exception et la levez à nouveau (parcequ’il ne s’agit pas d’un échec mais d’une levée d’exception explicite et intentionnelle).&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;fail&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Oops'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Oops'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;N’utilisez jamais &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return&lt;/code&gt; dans un bloc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ensure&lt;/code&gt;. Cela donnerait la priorité au retour sur une éventuelle levée d’exception, et la méthode retournerait un résultat comme si aucune exception n’avait été levée. En fait, l’exception serait ignorée silencieusement.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;fail&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'very bad idea'&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Utilisez des blocs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;begin&lt;/code&gt; implicites autant que possible.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# main logic goes here&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# failure handling goes here&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Limitez la prolifération des blocs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;begin&lt;/code&gt; en utilisant les méthodes de contingence (un terme inventé par Avdi Grimm.)&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;with_io_error_handling&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;yield&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;IOError&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# handle IOError&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;with_io_error_handling&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;something_that_might_fail&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;with_io_error_handling&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;something_else_that_might_fail&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Evitez &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rescue Exception&lt;/code&gt;.&lt;br /&gt;
Cela aurait pour effet d’intercepter les signaux et appels à &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exit&lt;/code&gt;, et nécesiterait de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;kill -9&lt;/code&gt; le processus.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;# bad&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# calls to exit and kill signals will be caught (except kill -9)&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Exception&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;you didn't really want to exit, right?&quot;&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# exception handling&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# good&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# a blind rescue rescues from StandardError, not Exception as many&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# programmers assume.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# exception handling&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# also good&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# an exception occurs here&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;StandardError&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# exception handling&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Libérez les ressources externes ouvertes par votre programme dans un bloc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ensure&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'testfile'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# .. process&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# .. handle error&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Privilégiez l’utilisation d’exceptions standards plutôt que d’introduire de nouvelles classes d’exception.&lt;/p&gt;</content><author><name>Julien Fusco</name></author><summary type="html">Voici maintenant quelques mois que je code en Ruby et je n’ai jamais pris le temps de centraliser les bonnes pratiques. Il est donc temps de m’y mettre ! Je me suis grandement inspiré de l’excellent The Ruby Style Guide. Surtout, ne lisez pas la traduction française, elle n’est pas à jour, incomplète et parfois fausse !</summary></entry></feed>