<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mahmoud Abdelwahab</title>
    <description>The latest articles on Forem by Mahmoud Abdelwahab (@thisismahmoud).</description>
    <link>https://forem.com/thisismahmoud</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F151238%2Fea74eb83-e8d8-4543-91e3-f0c8311eb1c3.jpg</url>
      <title>Forem: Mahmoud Abdelwahab</title>
      <link>https://forem.com/thisismahmoud</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/thisismahmoud"/>
    <language>en</language>
    <item>
      <title>Set up a free PostgreSQL database on Supabase to use with Prisma</title>
      <dc:creator>Mahmoud Abdelwahab</dc:creator>
      <pubDate>Fri, 11 Jun 2021 20:13:04 +0000</pubDate>
      <link>https://forem.com/prisma/set-up-a-free-postgresql-database-on-supabase-to-use-with-prisma-3pk6</link>
      <guid>https://forem.com/prisma/set-up-a-free-postgresql-database-on-supabase-to-use-with-prisma-3pk6</guid>
      <description>&lt;p&gt;&lt;a href="https://supabase.com" rel="noopener noreferrer"&gt;Supabase&lt;/a&gt; is a backend-as-a-service built on top of open source technologies. It gives you a database, authentication, a REST API, real-time subscriptions, and storage.&lt;/p&gt;

&lt;p&gt;It offers a free plan which includes a hosted PostgreSQL database. This can be useful if you're getting started with a new project.&lt;/p&gt;

&lt;p&gt;This guide explains how to quickly connect the Postgres database provided by Supabase to a Prisma project. There are other services out there that provide hosted PostgreSQL databases like &lt;a href="https://dev.to/prisma/how-to-setup-a-free-postgresql-database-on-heroku-1dc1"&gt;Heroku&lt;/a&gt; or &lt;a href="https://www.digitalocean.com/products/managed-databases/" rel="noopener noreferrer"&gt;Digital Ocean&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://prisma.io" rel="noopener noreferrer"&gt;Prisma&lt;/a&gt; is an &lt;a href="https://github.com/prisma/prisma" rel="noopener noreferrer"&gt;open source&lt;/a&gt; next-generation ORM. It consists of the following parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prisma Client&lt;/strong&gt;: Auto-generated and type-safe query builder for Node.js &amp;amp; TypeScript.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prisma Migrate&lt;/strong&gt;: Migration system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prisma Studio&lt;/strong&gt;: GUI to view and edit data in your database.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Log into Supabase
&lt;/h2&gt;

&lt;p&gt;Navigate your browser to &lt;a href="https://app.supabase.com/api/login" rel="noopener noreferrer"&gt;https://app.supabase.com&lt;/a&gt; and log in with GitHub.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4esri9nkyvz7odpug78l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4esri9nkyvz7odpug78l.png" alt="Login screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create a new project
&lt;/h2&gt;

&lt;p&gt;You'll find that an organization has been created for you under the same GitHub username you used when logging in.&lt;/p&gt;

&lt;p&gt;Go ahead and create a new project by clicking on &lt;strong&gt;"New project"&lt;/strong&gt; and then pick the organization.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdtatpc6j848sjlqva7i8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdtatpc6j848sjlqva7i8.png" alt="Create a new project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You'll then need to provide a name and set a password for your database (we'll need it later). Finally, click on &lt;strong&gt;"create new project"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F950bp5xw267ncu9oc6jy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F950bp5xw267ncu9oc6jy.png" alt="Set project name and database password"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating the project, you'll need to wait for ~2 minutes for Supabase to finish creating the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Get the connection string from the project settings
&lt;/h2&gt;

&lt;p&gt;Go to the settings page from the sidebar and navigate to the &lt;strong&gt;Database&lt;/strong&gt; tab. You'll find the database's connection string with a placeholder for the password you provided when creating the project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzntcsh3ic91gf1gy8j73.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzntcsh3ic91gf1gy8j73.png" alt="Getting the connection string"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Testing the connection
&lt;/h2&gt;

&lt;p&gt;To make sure that everything works correctly, let's try the connection string in a Prisma project.&lt;/p&gt;

&lt;p&gt;If you already have one, all you need to do is set the &lt;code&gt;DATABASE_URL&lt;/code&gt; to the connection string (including the password) in your &lt;code&gt;.env&lt;/code&gt; file, and you're good to go. &lt;/p&gt;

&lt;p&gt;In case you don't have a Prisma project or this is your first time working with Prisma, you're going to use with the repo from the &lt;a href="https://www.prisma.io/docs/getting-started/quickstart" rel="noopener noreferrer"&gt;quickstart&lt;/a&gt; guide.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cloning the starter project
&lt;/h3&gt;

&lt;p&gt;Navigate into a directory of your choice and run the following command in your terminal if you're on a Windows machine:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

curl https://pris.ly/quickstart &lt;span class="nt"&gt;-L&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; quickstart-master.tar.gz &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-zxvf&lt;/span&gt; quickstart-master.tar.gz quickstart-master/typescript/starter &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; move quickstart-master&lt;span class="se"&gt;\t&lt;/span&gt;ypescript&lt;span class="se"&gt;\s&lt;/span&gt;tarter starter &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;rmdir&lt;/span&gt; /S /Q quickstart-master &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; del /Q quickstart-master.tar.gz


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And if you're using Mac OS or Linux, run the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://pris.ly/quickstart | &lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-xz&lt;/span&gt; &lt;span class="nt"&gt;--strip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2 quickstart-master/typescript/starter


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can now navigate into the directory and install the project's dependencies:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nb"&gt;cd &lt;/span&gt;starter &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm &lt;span class="nb"&gt;install&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  A look at the project's structure
&lt;/h3&gt;

&lt;p&gt;This project comes with TypeScript configured and has the following structure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;prisma&lt;/code&gt; directory which contains:

&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;dev.db&lt;/code&gt; file: This is a SQLite database.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;schema.prisma&lt;/code&gt; file: Where we define the different database models and relations between them.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;.env&lt;/code&gt; file: Contains the &lt;code&gt;DATABASE_URL&lt;/code&gt; variable, which Prisma will use.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;script.ts&lt;/code&gt; file: where we will run some queries using Prisma Client.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This starter also comes with the following packages installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/prisma" rel="noopener noreferrer"&gt;&lt;code&gt;@prisma/client&lt;/code&gt;&lt;/a&gt;: An auto-generated and type-safe query builder that's &lt;em&gt;tailored&lt;/em&gt; to your data. &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/@prisma/client" rel="noopener noreferrer"&gt;&lt;code&gt;prisma&lt;/code&gt;&lt;/a&gt;: Prisma's command-line interface (CLI). It allows you to initialize new project assets, generate Prisma Client, and analyze existing database structures through introspection to automatically create your application models.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Prisma works with both JavaScript and TypeScript. However, to get the best possible development experience, using TypeScript is highly recommended.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Configuring the project to use PostgreSQL
&lt;/h3&gt;

&lt;p&gt;Go ahead and delete the &lt;code&gt;prisma/dev.db&lt;/code&gt; file because we will be switching to PostgreSQL.&lt;/p&gt;

&lt;p&gt;Next, inside the &lt;code&gt;prisma/.env&lt;/code&gt; file, update the value of the &lt;code&gt;DATABASE_URL&lt;/code&gt; variable to the connection string you got in &lt;strong&gt;step 3&lt;/strong&gt;. The URL might look as follows:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# prisma/.env

postgres://postgres:[YOUR-PASSWORD]@db.vdbnhqozmlzdsaejdxwr.supabase.co:5432/postgres



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Finally, inside your &lt;code&gt;schema.prisma&lt;/code&gt; file, change the &lt;code&gt;provider&lt;/code&gt; from "sqlite" to &lt;code&gt;"postgresql"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is what your &lt;code&gt;schema.prisma&lt;/code&gt; file should look like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="n"&gt;datasource&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"postgresql"&lt;/span&gt;
  &lt;span class="n"&gt;url&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"DATABASE_URL"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;generator&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"prisma-client-js"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;Post&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;        &lt;span class="n"&gt;Int&lt;/span&gt;     &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;autoincrement&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="n"&gt;title&lt;/span&gt;     &lt;span class="n"&gt;String&lt;/span&gt;
  &lt;span class="n"&gt;content&lt;/span&gt;   &lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;
  &lt;span class="n"&gt;published&lt;/span&gt; &lt;span class="n"&gt;Boolean&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;author&lt;/span&gt;    &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;   &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="n"&gt;relation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;references&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="n"&gt;authorId&lt;/span&gt;  &lt;span class="n"&gt;Int&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;    &lt;span class="n"&gt;Int&lt;/span&gt;     &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;autoincrement&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt;  &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="n"&gt;unique&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt;  &lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;
  &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="n"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To test that everything works correctly, run the following command to create a migration:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

prisma migrate dev &lt;span class="nt"&gt;--name&lt;/span&gt; init


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can optionally give your migration a name, depending on the changes you made. Since this is the project's first migration, you're setting the &lt;code&gt;--name&lt;/code&gt; flag to "init".&lt;/p&gt;

&lt;p&gt;If everything works correctly, you should get the following message in your terminal:&lt;/p&gt;

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

Your database is now in sync with your schema.

✔ Generated Prisma Client (2.x.x) to ./node_modules/@prisma/client in 111ms


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will create a &lt;code&gt;prisma/migrations&lt;/code&gt; folder inside your &lt;code&gt;prisma&lt;/code&gt; directory and synchronize your Prisma schema with your database schema.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: if you want to skip the process of creating a migration history, you can use the &lt;a href="https://www.prisma.io/docs/concepts/components/prisma-migrate/db-push" rel="noopener noreferrer"&gt;&lt;code&gt;db push&lt;/code&gt;&lt;/a&gt; command instead of &lt;code&gt;migrate dev&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you go to your Supabase project, in the table editor, you should see that two tables have been created, a &lt;code&gt;Post&lt;/code&gt; and a &lt;code&gt;User&lt;/code&gt; table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7y4qq4wwvfrheti6r09u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7y4qq4wwvfrheti6r09u.png" alt="tables created in the UI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! You have now successfully connected a Prisma project to a PostgreSQL database hosted on Supabase and ran your first migration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connection pooling with Supabase
&lt;/h2&gt;

&lt;p&gt;If you're working in a serverless environment (for example Node.js functions hosted on AWS Lambda, Vercel or Netlify Functions), you need to set up &lt;a href="https://www.prisma.io/docs/guides/performance-and-optimization/connection-management#serverless-environments-faas" rel="noopener noreferrer"&gt;connection pooling&lt;/a&gt; using a tool like &lt;a href="https://www.pgbouncer.org/" rel="noopener noreferrer"&gt;PgBouncer&lt;/a&gt;. That's because every function invocation may result in a &lt;a href="https://www.prisma.io/docs/guides/performance-and-optimization/connection-management#the-serverless-challenge" rel="noopener noreferrer"&gt;new connection to the database&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Fortunately, Supabase projects &lt;a href="https://supabase.com/blog/supabase-pgbouncer#what-is-connection-pooling" rel="noopener noreferrer"&gt;support connection management using PgBouncer&lt;/a&gt; and are enabled by default.&lt;/p&gt;

&lt;p&gt;Go to the &lt;strong&gt;Database&lt;/strong&gt; page from the sidebar and navigate to &lt;strong&gt;connection pool&lt;/strong&gt; settings&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw0oowg8vq435ob5c3gf0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw0oowg8vq435ob5c3gf0.png" alt="Connection pool settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When running migrations you need to use the non pooled connection URL (like the one we used in &lt;strong&gt;step 4&lt;/strong&gt;). However,  when deploying your app, you'll use the pooled connection URL.  and add the &lt;code&gt;?pgbouncer=true&lt;/code&gt; flag to the PostgreSQL connection URL. The URL might look as follows:&lt;/p&gt;

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

# prisma/.env

postgres://postgres:[YOUR-PASSWORD]@db.vdbnhqozmlzdsaejdxwr.supabase.co:6543/postgres?pgbouncer=true



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Prisma Migrate uses database transactions to check out the current state of the database and the migrations table. However, the Migration Engine is designed to use a single connection to the database, and does not support connection pooling with PgBouncer. If you attempt to run Prisma Migrate commands in any environment that uses PgBouncer for connection pooling, you might see the following error:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

Error: undefined: Database error
Error querying the database: db error: ERROR: prepared statement &lt;span class="s2"&gt;"s0"&lt;/span&gt; already exists


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is a known issue and it is being worked on, you can follow the progress on this &lt;a href="https://github.com/prisma/prisma/issues/6485" rel="noopener noreferrer"&gt;GitHub issue&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want to learn more about Supabase, check out the &lt;a href="https://supabase.com/docs" rel="noopener noreferrer"&gt;docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want to learn more about Prisma, check out the &lt;a href="https://www.prisma.io/docs" rel="noopener noreferrer"&gt;docs&lt;/a&gt;. Also in case you have any questions or run into any issue, feel free to start a discussion in the repo's &lt;a href="https://github.com/prisma/prisma/discussions" rel="noopener noreferrer"&gt;discussions section&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>supabase</category>
      <category>prisma</category>
      <category>postgres</category>
      <category>database</category>
    </item>
    <item>
      <title>A Letter You Can Send to Your Manager to Adopt Prisma at Work</title>
      <dc:creator>Mahmoud Abdelwahab</dc:creator>
      <pubDate>Tue, 09 Feb 2021 13:07:32 +0000</pubDate>
      <link>https://forem.com/prisma/a-letter-you-can-send-to-your-manager-to-adopt-prisma-at-work-4k94</link>
      <guid>https://forem.com/prisma/a-letter-you-can-send-to-your-manager-to-adopt-prisma-at-work-4k94</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Want to use Prisma at work? We've made it easier for you to ask your manager to adopt Prisma for your projects! Here's a letter you can copy/paste&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Dear Manager,&lt;/p&gt;

&lt;p&gt;The team has been working hard on improving our product and shipping new features, however, we'd like to increase our productivity even more while maintaining &lt;em&gt;great&lt;/em&gt; code quality.&lt;/p&gt;

&lt;p&gt;The current state of our tooling is &lt;em&gt;okay&lt;/em&gt;, but we would like to take it to the next level. One way to do that is to adopt &lt;a href="https://prisma.io"&gt;Prisma&lt;/a&gt;. It is a next-generation ORM that offers an amazing development experience.&lt;/p&gt;

&lt;p&gt;Prisma will make our code easier to reason about since it has an intuitive API with features like CRUD, pagination, and filtering built-in.&lt;/p&gt;

&lt;p&gt;It also offers great auto-completion so we'll be making fewer errors while building new features, and we can ship with confidence.&lt;/p&gt;

&lt;p&gt;The great thing about Prisma is that it solves one problem and it solves it really well: providing a simple data access layer for our database inside a Node.js or TypeScript environment. &lt;/p&gt;

&lt;p&gt;Prisma is also framework and API agnostic, so we can easily integrate it within our stack and inside any architecture.&lt;/p&gt;

&lt;p&gt;Here's what some of the biggest companies are saying about Prisma:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;"Next.js and Prisma is the ultimate combo if you need a database in React apps! Depending on your needs, you can query your database with Prisma in Next.js API routes, in getServerSideProps or in getStaticProps for full rendering flexibility and top performance 🚀 "&lt;/em&gt; - &lt;a href="https://twitter.com/rauchg"&gt;Guillermo Rauch&lt;/a&gt; - CEO &amp;amp; Founder of &lt;a href="https://vercel.com"&gt;Vercel&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;"So happy we chose Prisma Client and Migrate for &lt;a href="https://redwoodjs.com/"&gt;Redwood.js&lt;/a&gt;. Finally we have something akin to Rails' ActiveRecord but for JavaScript &amp;amp; the future of JAMstack apps!"&lt;/em&gt; - &lt;a href="https://twitter.com/mojombo"&gt;Tom Preston-Werner&lt;/a&gt; - GitHub Co-Founder&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;"Prisma provides an excellent modeling language for defining your database, as well as a powerful ORM for working with SQL in JavaScript &amp;amp; TypeScript. It’s the perfect match to Apollo Server and makes building GraphQL APIs with a database feel delightful."&lt;/em&gt; - &lt;a href="https://twitter.com/theworstdev"&gt;Kurt Kemple&lt;/a&gt; -  DevRel Manager of &lt;a href="https://apollographql.com/"&gt;Apollo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Prisma also has a dedicated team for providing support on GitHub and a huge &lt;a href="https://slack.prisma.io"&gt;Slack&lt;/a&gt; community of 40,000+ developers where we can ask questions. &lt;/p&gt;

&lt;p&gt;It currently supports PostgreSQL, MySQL, SQL Server, and SQLite, so we can incrementally adopt it in our backend.&lt;/p&gt;

&lt;p&gt;In case you have any questions, please let us know, we'd love to discuss it. To get things started, check out &lt;a href="https://www.prisma.io/docs/concepts/overview/what-is-prisma"&gt;what is Prisma&lt;/a&gt;, to gain a better understanding of how it works and why it would be an upgrade for us. We can also incrementally adopt it in our &lt;a href="https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project-typescript-postgres"&gt;project&lt;/a&gt; and the &lt;a href="https://www.prisma.io/docs/concepts/more/comparisons/prisma-and-typeorm"&gt;migration&lt;/a&gt; is low-risk so it is definitely worth trying. For more information, check out the &lt;a href="https://www.prisma.io/docs/concepts/overview/should-you-use-prisma"&gt;should you use Prisma&lt;/a&gt; page&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;

&lt;p&gt;– The team&lt;/p&gt;

</description>
      <category>prisma</category>
    </item>
    <item>
      <title>How I Failed The 100 Days Of Code Challenge</title>
      <dc:creator>Mahmoud Abdelwahab</dc:creator>
      <pubDate>Mon, 07 Dec 2020 22:26:37 +0000</pubDate>
      <link>https://forem.com/thisismahmoud/how-i-failed-the-100-days-of-code-challenge-3lo2</link>
      <guid>https://forem.com/thisismahmoud/how-i-failed-the-100-days-of-code-challenge-3lo2</guid>
      <description>&lt;h1&gt;
  
  
  Consistency Is Hard
&lt;/h1&gt;

&lt;p&gt;I heard about the 100 days of code challenge around two years ago when I got into web development. It's a challenge where you're supposed to code at least 1 hour a day for 100 days straight.&lt;/p&gt;

&lt;p&gt;I failed at it. &lt;em&gt;HARD&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I just couldn't manage to stay consistent.&lt;/p&gt;

&lt;p&gt;Some days I coded, others I didn't.&lt;/p&gt;

&lt;p&gt;Some days I felt inspired and motivated, other days I felt like crap and I couldn't get anything done. &lt;/p&gt;

&lt;p&gt;Some days I was just, well, busy. Life got in the way.&lt;/p&gt;

&lt;p&gt;Coding 1 hour a day for 100 days, sounds easy, but it's not. The consistency aspect is super hard. At least for me.&lt;/p&gt;

&lt;p&gt;So after multiple tries, I've accepted defeat.&lt;/p&gt;

&lt;h1&gt;
  
  
  Going with the flow
&lt;/h1&gt;

&lt;p&gt;I decided to go with the flow. Code depending on how I felt.&lt;/p&gt;

&lt;p&gt;So some days I'd code for 5-7 hours, and on these days everything would just magically work ✨ &lt;/p&gt;

&lt;p&gt;That code snippet I copied from stack overflow? Runs the first time.&lt;/p&gt;

&lt;p&gt;I Encounter a bug? The answer was the first one on Google.&lt;/p&gt;

&lt;p&gt;On other days though, things were &lt;em&gt;slow.&lt;/em&gt; Nothing seemed to work, I felt stuck, and I wasn't focused at all. Sometimes it feels like the only productive thing I've done during the day was running &lt;code&gt;npm install&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What's also weird was I had no in-between. It was binary. &lt;/p&gt;

&lt;p&gt;Either I'm super productive, or a potato.&lt;/p&gt;

&lt;p&gt;With time though, I managed to accept it. &lt;/p&gt;

&lt;p&gt;Getting used to this cycle made me happier since I didn't feel guilty all the time.&lt;/p&gt;

&lt;p&gt;For all beginner developers out there, I want to let you know that It's okay not to be productive every day. It's okay to stumble, struggle, and be stuck. In fact, it's part of the journey.&lt;/p&gt;

&lt;p&gt;If you're productive and in the zone, enjoy it while it lasts.&lt;/p&gt;

&lt;p&gt;If you're stuck, ask for help or take the day off. It's fine. You can always try again tomorrow. &lt;/p&gt;

&lt;p&gt;Now some of you might find a hard time believing what I'm saying. You might be worried that missing a couple of days will greatly impact your progress as a developer.&lt;/p&gt;

&lt;p&gt;I'm here to tell you it won't. &lt;/p&gt;

&lt;h1&gt;
  
  
  What truly matters: doing your best
&lt;/h1&gt;

&lt;p&gt;In reality, what matters is the &lt;em&gt;total&lt;/em&gt; hours spent.&lt;/p&gt;

&lt;p&gt;Two people can end up coding the same amount even if they follow different schedules. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yjcfo7lm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6wkpqcgg0wu31o7hzi4h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yjcfo7lm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6wkpqcgg0wu31o7hzi4h.png" alt="Comparison between two developers, 1 coding for 1 hour daily and one that goes with the flow"&gt;&lt;/a&gt;&lt;br&gt;
Here you can see that in the weekly progress chart, the person coding 1 hour a day codes for 7 hours per week, while the other person codes the same amount but for fewer days.&lt;/p&gt;

&lt;p&gt;And for the total number of hours spent coding during the year, the person that went with the flow spent on average the same number of hours as someone that coded 1 hour every day.&lt;/p&gt;

&lt;p&gt;I'm the second type, and luckily, I track how much time I spend on my text editor.&lt;/p&gt;

&lt;p&gt;I use &lt;a href="https://wakatime.com"&gt;Wakatime&lt;/a&gt;, which is a VSCode extension that tracks the amount of time you spend coding. I installed it on December 24th, 2018. Since then, I've coded for a total of 1218 hours. &lt;/p&gt;

&lt;p&gt;This is what my chart looks like&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LqYOVikc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ai5rsgttne3aczehttjd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LqYOVikc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ai5rsgttne3aczehttjd.png" alt="WakaTime Chart"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I have times where I coded consistently, others I had &lt;em&gt;zero&lt;/em&gt; activity.&lt;/p&gt;

&lt;p&gt;The moral of the story, do what works best for you. &lt;br&gt;
Don't feel like you have to follow a specific schedule religiously to get better. Just make sure you're always trying to get better. Eventually, you will.&lt;/p&gt;

&lt;p&gt;The funny thing is, 1218 hours in two years is around 1.7 hours per day. So I guess I did complete the challenge after all.&lt;/p&gt;

&lt;h1&gt;
  
  
  Track how much you work, but don't obsess over it
&lt;/h1&gt;

&lt;p&gt;Tracking the number of hours is not the best metric, the quality of the time matters too. You should strive to achieve both quality &lt;em&gt;and&lt;/em&gt; quantity.&lt;/p&gt;

&lt;p&gt;These numbers also do not show the full picture. They don't include the time I spent reading other people's code (which taught me &lt;em&gt;a lot&lt;/em&gt;), watching talks, reading blog posts, and meeting new people.&lt;/p&gt;

&lt;p&gt;However, I think tracking helps in keeping you accountable and it can also act as motivation.&lt;/p&gt;

&lt;p&gt;Do your best, trust the process, and remember: you're only competing with yourself.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Building An Open Source Project | Developer Vlog</title>
      <dc:creator>Mahmoud Abdelwahab</dc:creator>
      <pubDate>Thu, 13 Aug 2020 18:01:23 +0000</pubDate>
      <link>https://forem.com/thisismahmoud/building-an-open-source-project-developer-vlog-4ne6</link>
      <guid>https://forem.com/thisismahmoud/building-an-open-source-project-developer-vlog-4ne6</guid>
      <description>&lt;p&gt;New Video is LIVE! 🚀 I document my progress building an open-source project - Tailwind Snippets. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/S_4PZW1v0dQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>tailwindcss</category>
      <category>typescript</category>
    </item>
    <item>
      <title>The Ultimate Screencast Recording Process </title>
      <dc:creator>Mahmoud Abdelwahab</dc:creator>
      <pubDate>Wed, 12 Aug 2020 01:27:23 +0000</pubDate>
      <link>https://forem.com/thisismahmoud/the-ultimate-screencast-recording-process-29nd</link>
      <guid>https://forem.com/thisismahmoud/the-ultimate-screencast-recording-process-29nd</guid>
      <description>&lt;p&gt;Knowing how to screencast is a valuable skill, You may have already tried doing it and you found that it takes a ton of work. &lt;/p&gt;

&lt;p&gt;Generally, there are two approaches when it comes to creating screencasts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Record your screen and then do a voice over&lt;/li&gt;
&lt;li&gt;Record both simultaneously, but doing one step at a time while taking pauses between each step.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each process has it's own pros and cons&lt;/p&gt;

&lt;h2&gt;
  
  
  Record your screen and then do a voice over
&lt;/h2&gt;

&lt;p&gt;Recording audio and the screen separately sounds really good in theory. You'll read a script and your life will be easy.&lt;/p&gt;

&lt;p&gt;However, the problem with voiceovers is that it's so hard to match the pace of the screen recording. Sometimes you're coding too fast, other times you're going too slow.&lt;/p&gt;

&lt;p&gt;So the only fix is to keep adjusting the video speed and try doing multiple takes when you're recording the audio. &lt;/p&gt;

&lt;p&gt;This is a ton of work and it can be really frustrating. So I personally don't use this approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Record both simultaneously, but doing one step at a time while taking pauses between each step.
&lt;/h2&gt;

&lt;p&gt;This is a nicer approach because after recording you don't need a lot of editing. You can remove the pauses by looking at the audio track.&lt;br&gt;
Also, if you know you messed up, you can just do a loud clap, so that you can find the bad takes a lot faster.&lt;/p&gt;

&lt;p&gt;On the other hand, I find this approach very hard for me. I can't do two things at the same time (code + voiceover).&lt;/p&gt;

&lt;p&gt;So for me to get a good take, I need to redo the same step multiple times. &lt;/p&gt;



&lt;p&gt;So from my point of view, both approaches are hard. &lt;br&gt;
One is hard in the production phase, and the other in post-production.&lt;/p&gt;

&lt;p&gt;But it doesn't have to be this way. Here's how I do it:&lt;/p&gt;
&lt;h2&gt;
  
  
  Code. Pause. Narrate
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;I record my screen&lt;/li&gt;
&lt;li&gt;pause&lt;/li&gt;
&lt;li&gt;read the explanation from a script.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When editing, all I need to do is grab the voiceover and decide where I want it to start&lt;/p&gt;

&lt;p&gt;I don't mess up or forget what I want to say, and I'm not doing two things at once&lt;/p&gt;

&lt;p&gt;This is a combination of the 2 approaches and works perfectly for me.&lt;/p&gt;

&lt;p&gt;Here's a video where I show how I do it:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/VNoraIXOo8Q"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>video</category>
      <category>tutorial</category>
      <category>screencasts</category>
    </item>
    <item>
      <title>Landing Page Redesign| Design For Developers </title>
      <dc:creator>Mahmoud Abdelwahab</dc:creator>
      <pubDate>Sat, 25 Jul 2020 03:39:10 +0000</pubDate>
      <link>https://forem.com/thisismahmoud/landing-page-redesign-design-for-developers-22ob</link>
      <guid>https://forem.com/thisismahmoud/landing-page-redesign-design-for-developers-22ob</guid>
      <description>&lt;p&gt;If you're a developer and you find yourself struggling with making things look good then this video is for you! &lt;/p&gt;

&lt;p&gt;I go over how I changed the landing page from this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqnayp2nx3o8silwrw143.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqnayp2nx3o8silwrw143.png" alt="Landing Page before the redesign"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;to this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff81anj41ita1hb7pdh94.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff81anj41ita1hb7pdh94.png" alt="Landing page after the redesign"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👉🏻 &lt;strong&gt;&lt;a href="https://www.youtube.com/watch?v=eovEWBXSWIg" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=eovEWBXSWIg&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the landing page for &lt;a href="https://learninpublic.org" rel="noopener noreferrer"&gt;The coding Career Handbook&lt;/a&gt;. You'll find my redesign live at &lt;a href="https://coding-career-handbook.netlify.app" rel="noopener noreferrer"&gt;https://coding-career-handbook.netlify.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's built using Gatsby and TailwindCSS, two of my favorite technologies at the moment. It's open-source as well at &lt;a href="https://github.com/m-abdelwahab/coding-career-handbook" rel="noopener noreferrer"&gt;https://github.com/m-abdelwahab/coding-career-handbook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you prefer reading, I wrote a summary of the changes I made + key takeaways ⬇️&lt;/p&gt;

&lt;h1&gt;
  
  
  The Hero Section
&lt;/h1&gt;

&lt;p&gt;By far the most important section of any landing page. This is where users build the first impression and should be able to understand what the whole website is about.&lt;/p&gt;

&lt;p&gt;So make sure that:&lt;/p&gt;

&lt;p&gt;→ Use an attention-grabbing headline that focuses on the product's value&lt;br&gt;
→ Make sure that there are clear call-to-actions&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fen5j84gpkw8r4xm1mw48.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fen5j84gpkw8r4xm1mw48.png" alt="Hero section summary before and after"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Table Of Contents Section
&lt;/h1&gt;

&lt;p&gt;Having a table of contents that users can read is important.&lt;/p&gt;

&lt;p&gt;People want to know exactly what they're paying for.&lt;/p&gt;

&lt;p&gt;However, having it on the main page will result in a lot of scrolling.&lt;/p&gt;

&lt;p&gt;A good approach is to have it on a separate page&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffptol5rcp7ld61q5p434.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffptol5rcp7ld61q5p434.png" alt="Table of contents before and after"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  About The Author Section
&lt;/h1&gt;

&lt;p&gt;When designing things, sometimes "less is more"&lt;/p&gt;

&lt;p&gt;You don't need a unique color combination&lt;/p&gt;

&lt;p&gt;You don't need fancy layouts.&lt;/p&gt;

&lt;p&gt;Keeping things simple works more often than you think&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fex42wbiw22llbzhztosh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fex42wbiw22llbzhztosh.png" alt="About the author section before and after"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Pricing Section
&lt;/h1&gt;

&lt;p&gt;If you offer different packages/ pricings a common pattern is to have a comparison table. This way your future customers can easily understand the differences and which package is best for them&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk3dkftjplcpt43dyb7ro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk3dkftjplcpt43dyb7ro.png" alt="pricing section before and after"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enjoyed this you'll find that the video covers one more section (the book reviews)&lt;/p&gt;

&lt;p&gt;Check it out here: 👉🏻 &lt;strong&gt;&lt;a href="https://www.youtube.com/watch?v=eovEWBXSWIg" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=eovEWBXSWIg&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>design</category>
      <category>ux</category>
    </item>
    <item>
      <title>What's the best approach for form validation in React?</title>
      <dc:creator>Mahmoud Abdelwahab</dc:creator>
      <pubDate>Tue, 28 Apr 2020 09:34:58 +0000</pubDate>
      <link>https://forem.com/thisismahmoud/what-s-the-best-approach-for-form-validation-in-react-3jl9</link>
      <guid>https://forem.com/thisismahmoud/what-s-the-best-approach-for-form-validation-in-react-3jl9</guid>
      <description>&lt;p&gt;I had a task where I needed to validate a sign-up form in React.&lt;br&gt;
There was a name, email, password, confirm password, and a checkbox. All fields were required and the password had a couple of rules.&lt;br&gt;
I got it to work using Formik + Yup, was that overkill for this use-case? &lt;/p&gt;

&lt;p&gt;I found that there are a ton of form validation libraries, which one should I work with? What makes one better than the other?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>AWS The Good Parts: My Personal Notes</title>
      <dc:creator>Mahmoud Abdelwahab</dc:creator>
      <pubDate>Wed, 15 Apr 2020 14:47:50 +0000</pubDate>
      <link>https://forem.com/thisismahmoud/aws-the-good-parts-my-personal-notes-37db</link>
      <guid>https://forem.com/thisismahmoud/aws-the-good-parts-my-personal-notes-37db</guid>
      <description>&lt;p&gt;Hi! My name is Mahmoud Abdelwahab and I'm a  front-end engineer based in Egypt. I successfully landed my first ever paid gig this year (🎉), where I was responsible for styling a Web app. The project was using React on the front-end and the backend was powered by AWS Amplify and DynamoDB.&lt;br&gt;
While I was working on the project, the backend developer made me very interested in learning AWS. So after I finished the job, I did some research about the best resources to learn AWS and I found &lt;a href="https://gumroad.com/l/aws-good-parts/corona"&gt;The Good Parts Of AWS&lt;/a&gt; by &lt;a href="https://twitter.com/dvassallo"&gt;Daniel Vassallo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This will be a series of blog posts where I share my understanding of the things I learn from the book. You should definitely check it out.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Default Heuristic
&lt;/h2&gt;

&lt;p&gt;As a Software engineer, you have to make a lot of choices, from deciding which language(s) to use, frameworks, libraries, architectures, etc. So for you to make these decisions, you have to first understand what are the available options.&lt;br&gt;
This part requires research so that you're able to determine what are the right tools for your specific use case.&lt;br&gt;
And with the fast pace of the tech industry, new tools are constantly being invented.&lt;br&gt;
The problem is that, while doing your research, sometimes one might fall in the trap of chasing the &lt;em&gt;best&lt;/em&gt; tool.&lt;/p&gt;

&lt;p&gt;So with each tool you encounter, you try to understand how it works, the different trade-offs you'll make when using it, who's using it and maybe try building something with it to test it.&lt;/p&gt;

&lt;p&gt;This approach takes a lot of time and effort and it becomes really inefficient when you have a lot of options.&lt;/p&gt;

&lt;p&gt;Okay, so how can you avoid this trap? Daniel Vassallo recommends using a technique called the "Default Heuristic".&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The premise of this heuristic is that when the cost of acquiring new information is high and the consequence of deviating from a default choice is low, sticking with the default will likely be the optimal choice."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So an important question pops up: "what should be my default choice"?&lt;/p&gt;

&lt;p&gt;You should go with something that you already understand, you're confident that it works and you've tested it before.&lt;br&gt;
The default choice doesn't have to be the best, it just needs to be &lt;strong&gt;reliable&lt;/strong&gt; so that it gets you closer to your goals.&lt;/p&gt;

&lt;p&gt;When you follow this strategy, you end up being more efficient, because you're making the majority of your decisions based on your experience. When the defaults you have don't fit a certain case, that's when you should do your research and try to find the right tool.&lt;/p&gt;

&lt;p&gt;I'm a front-end engineer and I recently faced a situation where I had to make a choice about which tool to use concerning the styling of the UI.&lt;/p&gt;

&lt;p&gt;Should I go with an existing component library or write my own CSS from scratch? Okay, if I'm going to write my own CSS from scratch should I use CSS-in-JS? SCSS? Or maybe I should try tailwind-CSS, I heard it makes you really efficient when building layouts and UIs.&lt;/p&gt;

&lt;p&gt;So as you can see, there are a lot of possible decisions for one aspect of the project. There are also different conventions, philosophies, libraries, frameworks, linting-tools, build-tools, CI/CD, etc.&lt;br&gt;
So if I would research and try all the possible tools that there is, I just wouldn't get anything done.&lt;/p&gt;

&lt;p&gt;The point of this book is to share "the default choices" of Daniel Vassallo. He explains each one of them and why it became a default choice when working with AWS.&lt;/p&gt;

&lt;p&gt;I will share my learnings from this book here, but definitely I recommend that you buy the book yourself and go through it.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>beginners</category>
      <category>books</category>
    </item>
    <item>
      <title>Composition Over Inheritance</title>
      <dc:creator>Mahmoud Abdelwahab</dc:creator>
      <pubDate>Sun, 12 May 2019 21:20:11 +0000</pubDate>
      <link>https://forem.com/thisismahmoud/composition-over-inheritance-4fn9</link>
      <guid>https://forem.com/thisismahmoud/composition-over-inheritance-4fn9</guid>
      <description>&lt;h1&gt;
  
  
  Composition Over Inheritance
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Object-Oriented Programming (OOP)&lt;/em&gt; is one of the most popular paradigms when it comes to building software, however, the more I learned about JavaScript, I got introduced to &lt;em&gt;Functional Programming (FP)&lt;/em&gt;, a completely different way of thinking. In this article, I'll share with you what I've learned and I'll explain to you using my own examples.&lt;/p&gt;

&lt;p&gt;Example: You want to build a game, where the main character is a student in Hogwarts and he's learning witchcraft from his teacher.&lt;br&gt;
So you create a &lt;em&gt;Student&lt;/em&gt; Class where your student object will be able to take tests, and you have another class called &lt;em&gt;Teacher&lt;/em&gt;, where the teacher object will be able to grade Tests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Student&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nx"&gt;Teacher&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;gradeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Assuming you want to add some features like eating, sleeping and walking, you'll end up with something that looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Student&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;eat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nx"&gt;Teacher&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;gradeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;eat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The problem is that the code above doesn't follow the DRY principle, which stands for ( Don't Repeat Yourself), so the solution is to create a &lt;em&gt;parent&lt;/em&gt; class where we put the sleep, eat and walk features. So we end up with something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Human&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;eat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nx"&gt;Student&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nx"&gt;Teacher&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Yaaay problem solved! everyone's happy. However, a few months later, to make your game even more exciting, you decide to add another character to your game, let's say you want to add a dragon. This is what you end up with:&lt;br&gt;
SO you end up with something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;EvilDragon&lt;/span&gt;
 &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;breathFire&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fly&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nx"&gt;Human&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;eat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nx"&gt;Student&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nx"&gt;Teacher&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While this is great, you're not satisfied, so you decide to make the game more realistic by giving your dragon abilities like humans, you want your dragon to be able to sleep and eat, so you end up with something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;GameObject&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;eat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nx"&gt;EvilDragon&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;breathFire&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fly&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nx"&gt;Human&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="nx"&gt;Student&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="nx"&gt;Teacher&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeTest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, this is working completely fine, but assuming that in your game, the teacher, after careful study of witchcraft, was able to create a cape that allowed him to fly.&lt;br&gt;
Now comes the problem: &lt;em&gt;how&lt;/em&gt; do you structure your project? you can't add the flying ability to the humans class because not all humans can fly, and you can't make the teacher inherit from the EvilDragon Class, because the teacher can't breathe fire.&lt;br&gt;
There is a solution it's to add features that will never be used by the teacher object to make him able to fly, like breathing fire. However, this is like asking for a banana and receiving a gorilla holding a banana.&lt;br&gt;
So now, you've hit a wall, you can't turn your game idea into a reality.&lt;br&gt;
Of course, you can repeat yourself, but since you're an excellent developer who cares about every line of code he writes you won't do that.&lt;br&gt;
Don't worry though, there is a solution: &lt;strong&gt;Composition&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With inheritance, you structure your classes around &lt;strong&gt;what they are.&lt;/strong&gt; With functional programming, you structure your classes on &lt;strong&gt;what they do&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;By favoring composition over inheritance and thinking in terms of what things &lt;em&gt;do&lt;/em&gt; rather than what things &lt;em&gt;are&lt;/em&gt;, you free yourself of fragile and tightly coupled inheritance structures.&lt;/p&gt;

&lt;p&gt;Here's a snippet of what our code might look like in our game when we think in terms of objects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Teacher&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Damn, that was a great nap&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;teacher&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Teacher&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Dumbledore&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;teacher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;//outputs 'Damn, that was a great nap' after 8 seconds&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When we write our project using a functional approach we end up with a collection of stand-alone functions, each one of them serving a single purpose, which facilitates maintainability and makes debugging easier since we can predict the outcome of a function. When creating an object, we simply import all the functions that we need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//same code rewritten using factory functions&lt;/span&gt;
&lt;span class="c1"&gt;//factory functions are functions that create objects&lt;/span&gt;
&lt;span class="c1"&gt;//we will use&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sleep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Damn, that was a great nap&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;assign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Which one wins? well normally you would use inheritance when there is a &lt;em&gt;relation&lt;/em&gt; between objects, like me, Mahmoud, I'm a human, so I will inherit all of the things that a human has. On the other hand, you would use composition for example when an object &lt;em&gt;has&lt;/em&gt; a certain feature, like for example a car will have an engine component.&lt;/p&gt;

&lt;p&gt;However, this is not completely true because, for example, a car is a vehicle and me Mahmoud, I have arms and I can lift things. So, in reality, you can follow any of these patterns.&lt;br&gt;
Buuuut, composition is easier to debug, maintain, everything is encapsulated and in a project, you can easily add features.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>oop</category>
      <category>functional</category>
    </item>
  </channel>
</rss>
