<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ryan Thelin</title>
    <description>The latest articles on DEV Community by Ryan Thelin (@ryanthelin).</description>
    <link>https://dev.to/ryanthelin</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%2F432071%2F61d2269e-ac47-4610-9d7f-8c44d2ea0104.jpeg</url>
      <title>DEV Community: Ryan Thelin</title>
      <link>https://dev.to/ryanthelin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ryanthelin"/>
    <language>en</language>
    <item>
      <title>TensorFlow.js tutorial: Get started with the ML library</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Fri, 30 Jul 2021 19:15:13 +0000</pubDate>
      <link>https://dev.to/educative/tensorflow-js-tutorial-get-started-with-the-ml-library-45j8</link>
      <guid>https://dev.to/educative/tensorflow-js-tutorial-get-started-with-the-ml-library-45j8</guid>
      <description>&lt;p&gt;TensorFlow is one of the most popular tools for machine learning and deep learning. It's used by many big tech companies such as Twitter, Uber, and Google. TensorFlow.js is a JavaScript library used for training and deploying machine learning models in the browser. TensorFlow.js was designed to provide the same features and functionalities as traditional TensorFlow, but for the JavaScript ecosystem. &lt;/p&gt;

&lt;p&gt;Today, we're going to dive deeper into TensorFlow and discuss its benefits, features, models, and more. We'll finish the article with a walkthrough of the Layers API, which is one of the two ways to create a machine learning model with TensorFlow.js. Let's get started!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We’ll cover&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What is TensorFlow?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What is TensorFlow.js?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Installing TensorFlow.js&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating a ML model with the Layers API&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wrapping up and next steps&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;b&gt;&lt;h4&gt;Get hands-on with machine learning&lt;/h4&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;This learning path will help you master important ML skills and techniques.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/path/become-a-machine-learning-engineer" rel="noopener noreferrer"&gt;Become a Machine Learning Engineer&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is TensorFlow?
&lt;/h2&gt;

&lt;p&gt;TensorFlow is an open-source &lt;a href="https://www.educative.io/blog/deep-vs-machine-learning" rel="noopener noreferrer"&gt;&lt;strong&gt;machine learning&lt;/strong&gt;&lt;/a&gt; platform. It was created in 2015 by the &lt;a href="https://www.educative.io/blog/deep-learning-beginner-tutorial" rel="noopener noreferrer"&gt;deep learning&lt;/a&gt; artificial intelligence research team at Google. TensorFlow has an extensive environment that includes many different tools, libraries, and user resources. &lt;/p&gt;

&lt;p&gt;TensorFlow uses machine learning and deep learning algorithms. It uses Python for an accessible front-end API for building apps within the framework and then executes those apps in &lt;a href="https://www.educative.io/blog/top-cpp-coding-interview-questions" rel="noopener noreferrer"&gt;C++&lt;/a&gt;. With TensorFlow, we can train and run &lt;strong&gt;deep neural networks&lt;/strong&gt; for many different purposes, such as image classification, &lt;a href="https://www.educative.io/blog/what-is-natural-language-processing" rel="noopener noreferrer"&gt;natural language processing&lt;/a&gt;, and more. &lt;/p&gt;

&lt;p&gt;TensorFlow is known to have an intuitive and easy-to-learn set of &lt;a href="https://www.educative.io/blog/what-is-an-api" rel="noopener noreferrer"&gt;APIs&lt;/a&gt;. Their goal is to make it easy for you to learn and implement machine learning, deep learning, and scientific computing. In 2019, they released TensorFlow 2.0, which enhanced the platform and made it easier to work with and more efficient. One of their big changes was using the &lt;strong&gt;Keras API&lt;/strong&gt; for model training.&lt;/p&gt;

&lt;p&gt;With TensorFlow, we can create dataflow graphs. Each node we see in the graph represents a mathematical operation, and each edge between the nodes is called a &lt;strong&gt;tensor&lt;/strong&gt;. A tensor is a multi-dimensional array.&lt;/p&gt;

&lt;p&gt;TensorFlow has many benefits, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Portability&lt;/strong&gt;: TensorFlow allows us to train and deploy our models easily, no matter what language or platform we use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Powerful&lt;/strong&gt;: With TensorFlow, we can create complex topologies using features like the Keras Functional API and the Model Subclassing API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt;: We can use eager execution for quick and intuitive debugging.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Community&lt;/strong&gt;: TensorFlow has a large and active community.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Abstraction&lt;/strong&gt;: TensorFlow has multiple levels of abstraction so we can pick the right one for our needs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is TensorFlow.js?
&lt;/h2&gt;

&lt;p&gt;TensorFlow.js (TFJS) is an open-source &lt;strong&gt;machine learning library&lt;/strong&gt; that we can run anywhere that we run JavaScript. It supports WebGL, which is the browser interface to OpenGL. OpenGL is an API used for rendering 2D and 3D vector graphics. The goal of TensorFlow.js was to recreate the experience of traditional TensorFlow, but for the JavaScript ecosystem. &lt;/p&gt;

&lt;p&gt;TFJS allows JavaScript code to be executed on a GPU. It allows us to build deep neural networks that we can easily integrate into new or existing web applications and is heavily based on the Keras API. &lt;/p&gt;

&lt;p&gt;We can use TensorFlow.js in the following platforms: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Client-side in the web browser using JavaScript&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server-side and with IoT tools using &lt;a href="https://www.educative.io/blog/what-is-nodejs" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Desktop and web apps using Electron&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Native mobile apps using &lt;a href="https://www.educative.io/blog/top-react-native-interview-questions" rel="noopener noreferrer"&gt;React Native&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;h3&gt;
  
  
  TensorFlow.js models
&lt;/h3&gt;

&lt;p&gt;TensorFlow.js provides &lt;strong&gt;pre-trained, out-of-the-box machine learning models&lt;/strong&gt; that we can use in our projects. Some of these trained models and use cases include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Image classification&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Object detection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Body segmentation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Speech command recognition&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simple face detection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Transfer learning&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And much more&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With these models, JavaScript developers have built a lot of really cool demos, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;LipSync by YouTube&lt;/strong&gt;: This demo uses the Facemesh model to score your lip-syncing accuracy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Emoji Scavenger Hunt&lt;/strong&gt;: In this demo, you use your phone's camera to find emojis in the real world. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Webcam Controller&lt;/strong&gt;: In this demo, you play Pac-Man using images trained in your browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to check out the code for any of these existing models, you can visit the &lt;code&gt;tensorflow/tfjs-models&lt;/code&gt; GitHub repository to dive deeper! To check out the code for the demos, you can visit &lt;code&gt;tensorflow/tfjs-examples&lt;/code&gt; on GitHub.&lt;/p&gt;


&lt;h4&gt;
  
  
  Keep the learning going.
&lt;/h4&gt;

&lt;p&gt;Learn fundamental machine learning techniques without scrubbing through videos or documentation. Educative’s text-based learning paths are easy to skim and feature live coding environments, making learning quick and efficient.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/path/become-a-machine-learning-engineer" rel="noopener noreferrer"&gt;Become a Machine Learning Engineer&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing TensorFlow.js
&lt;/h2&gt;

&lt;p&gt;The two most common ways to install TensorFlow.js in your browser include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Installation with npm&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Installation with script tags&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we want to install using npm, we can use npm cli or yarn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;npm cli installation&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;tensorflow&lt;/span&gt;&lt;span class="sr"&gt;/tfj&lt;/span&gt;&lt;span class="err"&gt;s
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;yarn installation&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;yarn&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;tensorflow&lt;/span&gt;&lt;span class="sr"&gt;/tfj&lt;/span&gt;&lt;span class="err"&gt;s
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to install using script tags, we can add the following tag to our main HTML file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a ML model with the Layers API
&lt;/h2&gt;

&lt;p&gt;In TensorFlow.js, there are &lt;strong&gt;two ways&lt;/strong&gt; to create a machine learning model. We can either use the higher-level Layers API to build a model using layers, or we can use the Core API with lower-level operations. Today, we're going to take a closer look at the Layers API.&lt;/p&gt;

&lt;p&gt;With the Layers API, we can either create a sequential model or a functional model. The sequential model is the most common type of model. We can create one by passing a list of layers to the &lt;code&gt;sequential()&lt;/code&gt; function using &lt;code&gt;const&lt;/code&gt;. Let's take a look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sequential&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;

&lt;span class="nx"&gt;indent&lt;/span&gt; &lt;span class="na"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;

&lt;span class="nx"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;indent&lt;/span&gt; &lt;span class="nx"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dense&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;inputShape&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;692&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="na"&gt;units&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;activation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;relu&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}),&lt;/span&gt;

&lt;span class="nx"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;indent&lt;/span&gt; &lt;span class="nx"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dense&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;units&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;activation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;softmax&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}),&lt;/span&gt;

&lt;span class="nx"&gt;indent&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;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: When providing the &lt;code&gt;inputShape&lt;/code&gt;, leave out the batch size. As an example, let's say we plan to give our model tensors of shape &lt;code&gt;[X, 692]&lt;/code&gt;, where &lt;code&gt;X&lt;/code&gt; is any batch size. We would specify our &lt;code&gt;inputShape&lt;/code&gt; as &lt;code&gt;[692]&lt;/code&gt; when making our model.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up and next steps
&lt;/h2&gt;

&lt;p&gt;Congrats on taking your first steps with TensorFlow.js! It's a great tool to add to your machine learning workflow. With TensorFlow, it's easy to train and deploy machine learning and [deep learning models in the browser. Machine learning is a vast field, and there's still so much more to learn. Some recommended concepts to cover next include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Image processing with datasets&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Building advanced data pipelines with TensorFlow&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Analyzing and manipulating data in &lt;a href="https://www.educative.io/blog/python-pandas-tutorial" rel="noopener noreferrer"&gt;Pandas&lt;/a&gt; and Numpy&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To get started learning these concepts and much more, check out Educative's learning path &lt;a href="https://www.educative.io/path/become-a-machine-learning-engineer" rel="noopener noreferrer"&gt;&lt;strong&gt;Become a Machine Learning Engineer&lt;/strong&gt;&lt;/a&gt;. In this hands-on path, you'll learn the essential ML techniques to stand out from the competition. By the end, you'll have job-ready skills in data pipeline creation, model deployment, and interference. The path even has a chapter dedicated to deep learning with TensorFlow.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy learning!&lt;/em&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  Continue reading about machine learning
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/top-10-ml-algorithms-for-data-science-in-5-minutes" rel="noopener noreferrer"&gt;The top 10 ML algorithms for data science in 5 minutes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/cracking-machine-learning-interview-system-design" rel="noopener noreferrer"&gt;Cracking the machine learning interview: System design approaches&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/top-machine-learning-interview-questions" rel="noopener noreferrer"&gt;Crack the top 40 machine learning interview questions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is cloud native? What to know for your interview</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Thu, 29 Jul 2021 23:02:33 +0000</pubDate>
      <link>https://dev.to/educative/what-is-cloud-native-what-to-know-for-your-interview-1g4i</link>
      <guid>https://dev.to/educative/what-is-cloud-native-what-to-know-for-your-interview-1g4i</guid>
      <description>&lt;p&gt;Cloud-native technologies have become an important part of modern software development. The cloud-native architecture allows us to handle sudden surges in demand in an organized and efficient way through the use of containers, microservices, DevOps, and APIs. With cloud jobs in such high demand, you can help set yourself apart from the competition by developing strong cloud skills. &lt;/p&gt;

&lt;p&gt;In this article, we’ll explore the term cloud-native and discuss the benefits of cloud-native architecture, how to build a cloud-native application, and what to know for your cloud interviews. &lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We'll cover&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is cloud native?&lt;/li&gt;
&lt;li&gt;Cloud-native vs. traditional applications&lt;/li&gt;
&lt;li&gt;How to build a cloud-native application&lt;/li&gt;
&lt;li&gt;What to know for a cloud-native interview&lt;/li&gt;
&lt;li&gt;Wrapping up and next steps&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;b&gt;&lt;h4&gt;Get hands-on with cloud native app development&lt;/h4&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;This interactive course will help you walk you through the journey to creating your first cloud-native web application.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/cloud-native-development" rel="noopener noreferrer"&gt;Cloud Native Development with Tailwind, Google Cloud, and Firebase&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  What is cloud native?
&lt;/h2&gt;

&lt;p&gt;Cloud-native is an &lt;strong&gt;approach to application development&lt;/strong&gt; that uses the cloud computing delivery model. Cloud-native development was designed to enhance modern application development by employing the scalability, resiliency, and flexibility that the cloud provides.&lt;/p&gt;

&lt;p&gt;As defined by the Cloud Native Computing Foundation (CNCF), “cloud-native technologies empower organizations to build and run scalable applications in modern, dynamic environments such as public, private, and hybrid clouds.” &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The CNCF was created by the Linux Foundation in 2015. It’s an open-source software foundation that promotes cloud-native technologies. Companies like Microsoft, Oracle, and Intel are members of the foundation. They support open-source projects such as Kubernetes, Envoy, and many more.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Cloud-native app development leverages things like containerization, service meshes, declarative APIs, and &lt;a href="https://www.educative.io/blog/microservices-architecture-tutorial-all-you-need-to-get-started" rel="noopener noreferrer"&gt;microservices&lt;/a&gt; to allow you to build, deploy, and manage &lt;strong&gt;high-impact&lt;/strong&gt; cloud-native applications. Cloud-native services use technologies such as &lt;a href="https://www.educative.io/blog/beginners-guide-to-docker" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;, &lt;a href="https://www.educative.io/blog/beginner-kafka-tutorial" rel="noopener noreferrer"&gt;Kafka&lt;/a&gt;, &lt;a href="https://www.educative.io/blog/kubernetes-tutorial" rel="noopener noreferrer"&gt;Kubernetes&lt;/a&gt;, and serverless functions to help you efficiently build and run scalable applications in private and public cloud environments.&lt;/p&gt;



&lt;h3&gt;
  
  
  Cloud-native architecture
&lt;/h3&gt;

&lt;p&gt;Cloud-native architecture focuses on designing apps or services that were made to exist in the cloud rather than on-premises infrastructure. The cloud-native architecture enables us to create and deploy applications that are easy to maintain and have &lt;strong&gt;flexibility&lt;/strong&gt; without relying on physical servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Microservices&lt;/strong&gt; and serverless functions are very important in cloud-native architectures. Microservices are one of the main parts of cloud-native app architecture. Many companies use them because they support DevOps, improve scalability, reduce costs, and enable flexibility. &lt;/p&gt;

&lt;p&gt;Microservices and containerization support cloud-native apps by enabling us to switch between cloud providers, deploy services independently, and deploy services in different languages or frameworks without issues. There are many benefits to implementing a cloud-native architecture into your application development process. Let’s take a look at some of the benefits and challenges:&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Continuous integration&lt;/strong&gt;: Microservices help us with continuous integration and continuous delivery efforts because the development lifecycle is reduced and more processes are automated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Container orchestration&lt;/strong&gt;: Container orchestrators can schedule and allocate resources based on user needs. Open-source container orchestration platforms help us identify bugs in specific containers so we can find the root of the problem instead of affecting the entire application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portability&lt;/strong&gt;: Containerized microservices are very portable, which means we don’t need to rely too much on one specific cloud provider.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduced downtime&lt;/strong&gt;: Container orchestrators help us deploy software updates with less downtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast development time&lt;/strong&gt;: Cloud native architecture helps us speed up the app development process for organizations that have compute resources spread across different environments. This also allows us to get more value from the hybrid cloud.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;Challenges&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lack of DevOps&lt;/strong&gt;: If your organization doesn’t establish a DevOps pipeline, it may be difficult to manage the distributed workflows and microservices within your application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Microservices&lt;/strong&gt;: Certain microservices are dependent on specific types of operating systems, so make sure to consider that before moving forward.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependencies&lt;/strong&gt;: If you transition from a traditional application to a cloud-native application, dependencies and interdependencies may arise.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;a href="https://media2.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%2Femc2sshj0h2t1yoi36gf.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Femc2sshj0h2t1yoi36gf.PNG" alt="Alt Text" width="613" height="400"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloud-native vs traditional applications
&lt;/h2&gt;

&lt;p&gt;Traditional apps are basic apps that run on a mainframe environment or that have a client/server environment. Cloud-native apps implement the cloud computing delivery model to improve the app development process.&lt;/p&gt;

&lt;p&gt;Let’s take a look at some of the main differences between cloud-native apps and traditional apps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cloud native&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Predictable&lt;/strong&gt;: Cloud-native apps follow a framework that helps optimize resiliency through predictable actions. Cloud platforms use an automated, container-driven infrastructure that drives the way we write our software. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaborative&lt;/strong&gt;: Since cloud-native architecture uses DevOps, the app development process is more streamlined. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practical capacity&lt;/strong&gt;: Cloud-native app development automates infrastructure provisioning, which helps allocate the appropriate resources at the time of deployment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Independent&lt;/strong&gt;: The microservices architecture breaks apps into smaller services. This makes it easier to perform updates and scale the services without affecting other aspects of the application. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Continuous delivery&lt;/strong&gt;: Individual updates can be released as soon as they’re ready.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operating system abstraction&lt;/strong&gt;: The cloud-native architecture allows us to break away from underlying infrastructure dependencies and focus on the software.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Traditional&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Not predictable&lt;/strong&gt;: Traditional apps are developed in specific ways, and they don’t use the benefits of the cloud computing delivery model. This means that traditional apps may take longer to build, and they may have more infrequent releases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Isolated&lt;/strong&gt;: Traditional app development doesn’t use DevOps, so there’s typically less collaboration between different teams. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large capacity&lt;/strong&gt;: Custom infrastructure solutions may delay app deployment due to their oversized capacity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependent&lt;/strong&gt;: The monolithic architectures bundle services into single packages, which causes dependencies between services. This can affect updates and scaling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delayed delivery&lt;/strong&gt;: Updates may be delayed, which affects the performance of the application. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operating system dependency&lt;/strong&gt;: Traditional app development typically involves dependencies between the application itself and its underlying operating system.&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  Keep the learning going.
&lt;/h4&gt;

&lt;p&gt;Learn about cloud native app development without scrubbing through videos or documentation. Educative’s text-based courses are easy to skim and feature live coding environments, making learning quick and efficient.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/cloud-native-development" rel="noopener noreferrer"&gt;Cloud Native Development with Tailwind, Google Cloud, and Firebase&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;





&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to build a cloud-native application
&lt;/h2&gt;

&lt;p&gt;There are many different tools and practices we can use when building and operating cloud-native applications. Let’s take a look at some of the fundamentals:&lt;/p&gt;



&lt;h3&gt;
  
  
  DevOps
&lt;/h3&gt;

&lt;p&gt;DevOps is a combination of philosophies, practices, and tools that increases an organization’s ability to deliver apps and services quickly and efficiently. DevOps allows us to &lt;strong&gt;fully use the native cloud capabilities&lt;/strong&gt; and ensures that dev and operations teams work together with regular communication and common goals. With DevOps, our software development processes and more consistent and efficient. &lt;/p&gt;



&lt;h3&gt;
  
  
  Microservices
&lt;/h3&gt;

&lt;p&gt;Microservices architecture involves developing applications as collections of smaller services. Each microservice can be manipulated independently of other services within the same application. This enables a more &lt;strong&gt;streamlined&lt;/strong&gt; application development lifecycle without negatively impacting users.&lt;/p&gt;



&lt;h3&gt;
  
  
  Continuous delivery
&lt;/h3&gt;

&lt;p&gt;Continuous delivery is made possible by Agile development practices. It means that we constantly make phased software changes through automation. It’s a very &lt;strong&gt;reliable&lt;/strong&gt; way to release and deliver software more frequently and safely.&lt;/p&gt;



&lt;h3&gt;
  
  
  APIs
&lt;/h3&gt;

&lt;p&gt;Since cloud-native applications rely heavily on microservices, we need a well-defined way for these separate services to communicate with each other. This is where APIs come in. &lt;a href="https://www.educative.io/blog/what-is-an-api" rel="noopener noreferrer"&gt;Application programming interfaces (APIs)&lt;/a&gt; connect products and services and allow them to &lt;strong&gt;easily communicate&lt;/strong&gt; so we can maximize the development process.&lt;/p&gt;



&lt;h3&gt;
  
  
  Containerization
&lt;/h3&gt;

&lt;p&gt;Using containers gives us more &lt;strong&gt;efficiency and speed&lt;/strong&gt; compared to traditional virtual machines. With containerization, a single operating system instance is divided across one or more containers, which allows us to create and deploy individual microservices. &lt;/p&gt;



&lt;p&gt;&lt;a href="https://media2.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%2Fjrmb28hpscxwa26pnasm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjrmb28hpscxwa26pnasm.PNG" alt="Alt Text" width="721" height="502"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What to know for a cloud-native interview
&lt;/h2&gt;

&lt;p&gt;If you want to work in the cloud space, it’s important to know about cloud-native application development. Let’s discuss some fundamental information you should know and useful things you can do before your cloud-related interview:&lt;/p&gt;



&lt;h3&gt;
  
  
  Cloud computing
&lt;/h3&gt;

&lt;p&gt;Your expected skills and knowledge will depend a lot on the position you’re interviewing for. Overall, you still need to have a solid understanding of the fundamentals of cloud computing. Make sure you have the knowledge to answer basic questions about the cloud.&lt;/p&gt;

&lt;p&gt;Your preparation and study topics will depend on the position you’re applying for. Make sure to brush up on the &lt;strong&gt;relevant ideas and technologies&lt;/strong&gt; that pertain to the job you want. It’s also important that you demonstrate that you have some &lt;strong&gt;hands-on experience&lt;/strong&gt; with cloud computing. If you don’t have experience, you should have a solid understanding of the concepts and be able to explain them at a higher level. &lt;/p&gt;



&lt;h3&gt;
  
  
  Cloud certification
&lt;/h3&gt;

&lt;p&gt;A cloud certification shows potential employers that you have a solid understanding of the fundamentals of cloud computing. Over 80% of hiring managers say that cloud certifications make applicants more &lt;strong&gt;desirable&lt;/strong&gt;. The most popular certifications on the market now are for AWS, Azure, and &lt;a href="https://www.educative.io/blog/crack-gcp-certification-exam" rel="noopener noreferrer"&gt;GCP&lt;/a&gt;. Regardless of the certification you choose, multi-cloud skills are in high demand, so you’ll have room to move around.&lt;/p&gt;



&lt;h3&gt;
  
  
  DevOps
&lt;/h3&gt;

&lt;p&gt;DevOps is a strategy to help speed up application development by allowing operation feedback to come right to the developers. This means that cloud engineers follow their app throughout its entire lifecycle. For interviews, prepare to answer questions about things like disaster control, feedback, and automated data management.&lt;/p&gt;



&lt;h3&gt;
  
  
  Soft skills
&lt;/h3&gt;

&lt;p&gt;Don’t forget the &lt;a href="https://www.educative.io/blog/top-post-pandemic-skills" rel="noopener noreferrer"&gt;&lt;strong&gt;soft skills&lt;/strong&gt;&lt;/a&gt;! Now more than ever, tech companies are looking for well-rounded candidates with technical skills and soft skills. Make sure to highlight experiences that demonstrate your flexibility, adaptability, communication skills, and your customer service mentality. &lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up and next steps
&lt;/h2&gt;

&lt;p&gt;Congrats on taking your first step with cloud-native applications! Cloud-native development is growing in popularity, so it’s an important thing to know for a career in software development. There’s still so much more to learn about cloud-native app development, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setting up a continuous deployment pipeline&lt;/li&gt;
&lt;li&gt;Feature toggles&lt;/li&gt;
&lt;li&gt;Monorepo&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Getting hands-on experience with cloud-native applications is a great way to demonstrate to potential employers that you have the relevant skills and experience with the cloud. To start learning about the listed concepts and a lot more, check out Educative’s course &lt;a href="https://www.educative.io/courses/cloud-native-development" rel="noopener noreferrer"&gt;&lt;strong&gt;CloudNative Development with Tailwind, Google Cloud, and Firebase&lt;/strong&gt;&lt;/a&gt;. In this curated course, you’ll get hands-on experience in developing, testing, and managing a complete cloud-native application. &lt;/p&gt;

&lt;p&gt;By the end of the course, you’ll have the foundational knowledge you need to develop cloud-native applications on your own or with your team. You’ll also have great experience to talk about in your next interview!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy learning!&lt;/em&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  Continue reading about the cloud
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/roadmap-to-cloud-engineer-jobs" rel="noopener noreferrer"&gt;Roadmap to cloud jobs: how and why to become a cloud engineer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/microservices-in-azure" rel="noopener noreferrer"&gt;Microservices in Azure: an introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/amazon-aws-best-services" rel="noopener noreferrer"&gt;A quick AWS tutorial: the services you should definitely use&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cloudnative</category>
      <category>cloud</category>
      <category>career</category>
      <category>development</category>
    </item>
    <item>
      <title>Learn Python 3: Python basics in 7 coding challenges</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Tue, 06 Jul 2021 20:08:37 +0000</pubDate>
      <link>https://dev.to/educative/learn-python-3-python-basics-in-7-coding-challenges-13dg</link>
      <guid>https://dev.to/educative/learn-python-3-python-basics-in-7-coding-challenges-13dg</guid>
      <description>&lt;p&gt;Python 3 is the latest version of Python, a popular programming language used mainly for web development, data science, and machine learning. Python has quickly become one of the most popular programming languages for new developers because of the wide range of uses in software development and some of the great improvements added since Python 2.&lt;/p&gt;

&lt;p&gt;Today, we'll walk you through a hands-on, challenge-based tutorial to get you started with Python quickly!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s what we’ll cover today:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why challenge-based learning?&lt;/li&gt;
&lt;li&gt;1. Hello World&lt;/li&gt;
&lt;li&gt;2. String concatenation&lt;/li&gt;
&lt;li&gt;3. List&lt;/li&gt;
&lt;li&gt;4. Slicing&lt;/li&gt;
&lt;li&gt;5. Branching&lt;/li&gt;
&lt;li&gt;6. For loop&lt;/li&gt;
&lt;li&gt;7. Functions&lt;/li&gt;
&lt;li&gt;What to learn next&lt;/li&gt;
&lt;/ul&gt;



&lt;h4&gt;&lt;b&gt; Learn Python 3 in half the time with hands-on practice&lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;Our new 50 challenge Python course lets you skip the book work and get right to hands-on learning, with challenges ranging from beginner to expert difficulties. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/intro-python-3" rel="noopener noreferrer"&gt;An Intro to Python 3&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why challenge-based learning?
&lt;/h2&gt;

&lt;p&gt;Not everyone learns new programming languages the same way. For many aspiring Python programmers, book learning is inefficient and doesn't lead to lasting learning. The main flaws of book learning are that it doesn't invite the reader to directly engage and it encourages memorization instead of the natural exploration of programming concepts. &lt;/p&gt;

&lt;p&gt;To avoid the downsides of book learning, many would rather learn by exploring Python code through hands-on, challenge-based crash courses. This method is great for hands-on learners because it allows absolute beginners to learn both the theory and pragmatic use case for every basic concept or algorithm.  &lt;/p&gt;

&lt;p&gt;The challenges encourage you to explore the problems naturally and learn to use Python syntax through investigation rather than lecturing.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Hello World
&lt;/h2&gt;

&lt;p&gt;Let’s start with a basic puzzle that uses the &lt;code&gt;print()&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;hello world&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;print()&lt;/code&gt; function allows you to connect your program to the outside world. This function, as the name indicates, prints a value to the standard output.&lt;/p&gt;

&lt;p&gt;You can think of the standard output as the environment in which your Python program lives. Your standard output is the air around you. Let’s say you shout “Ouch!” Every person in your environment can read from your standard output that you just experienced pain.&lt;br&gt;
The data that is printed to the standard output is of the string data type.&lt;/p&gt;

&lt;p&gt;A string is a sequence of characters.&lt;/p&gt;

&lt;p&gt;You can define a string in Python in any of the following ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single quotes (&lt;code&gt;'hello world'&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Double quotes (&lt;code&gt;"hello world"&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Triple quote (&lt;code&gt;'''hello world'''&lt;/code&gt; and &lt;code&gt;"""hello world"""&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the puzzle, we use single quotes to define our string.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Challenge 1: Hello World&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is the output of the above code?&lt;/p&gt;

&lt;p&gt;A) &lt;code&gt;hello world&lt;/code&gt;&lt;br&gt;
B) &lt;code&gt;'hello world'&lt;/code&gt;&lt;br&gt;
C) &lt;code&gt;Hello World&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct answer is &lt;code&gt;hello world&lt;/code&gt; because the quotes are used to denote the string but are not parts of the string.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Variables
&lt;/h2&gt;

&lt;p&gt;Now we'll introduce the concepts of variables and float division.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;55&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The puzzle has two goals.&lt;br&gt;
First, it introduces the concept of variables. Python evaluates the result of the expression on the right side of the equation and stores it in the variable &lt;code&gt;x&lt;/code&gt;. After defining the variable, you can access it at any point in the program code.&lt;/p&gt;

&lt;p&gt;Second, it forces you to read code carefully due to a twist:&lt;br&gt;
Division operations always return a floating-point number. Thus, variable &lt;code&gt;x&lt;/code&gt; stores the float value &lt;code&gt;5.0&lt;/code&gt;. The print function outputs the result as a float and not as an integer value &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is the source of most errors in the code. People focus too much on what they mean (semantics) and too little on how they say it (syntax). &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;: Programs always execute instructions according to syntax, which may be different from what you intended. The key is to get used to thinking like a computer.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;&lt;strong&gt;Challenge 2: Variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is the output of the above code?&lt;/p&gt;

&lt;p&gt;A) &lt;code&gt;5&lt;/code&gt;&lt;br&gt;
B) &lt;code&gt;05&lt;/code&gt;&lt;br&gt;
C) &lt;code&gt;5.0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The solution is &lt;code&gt;5.0&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Division always returns a floating-point number, meaning it always includes a decimal point value. Here, the decimal point value was zero but must still be included to be a floating point number.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3. List
&lt;/h2&gt;

&lt;p&gt;This puzzle introduces lists, our first data structure in Python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;squares&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;squares&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The data type is “abstract” because you can use lists independently of the list elements’ concrete data types. Most complex algorithms that you'll learn later will use lists as a building block. Many famous algorithms such as quicksort are based only on a single list as their core data structure.&lt;/p&gt;

&lt;p&gt;The pythonic way of handling lists and list access is simple and clean. You can create a list by writing comma-separated values between the opening and closing square brackets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;lst&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You access the &lt;code&gt;i&lt;/code&gt;-th element in a list lst with the intuitive bracket notation &lt;code&gt;lst[i]&lt;/code&gt;. This notation is consistent for all compound data types, such as strings and arrays.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Challenge 3: Lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is the output of the above code?&lt;/p&gt;

&lt;p&gt;A) &lt;code&gt;1&lt;/code&gt;&lt;br&gt;
B) &lt;code&gt;4&lt;/code&gt;&lt;br&gt;
C) &lt;code&gt;9&lt;/code&gt;&lt;br&gt;
D) &lt;code&gt;16&lt;/code&gt;&lt;br&gt;
E) &lt;code&gt;25&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct answer is &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The index passed to a list indicates the position of the desired element. Indices are numbered starting with 0. Therefore, calling the &lt;code&gt;0&lt;/code&gt;th element of the list prints the first number, &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;



&lt;blockquote&gt;
&lt;h4&gt;
  
  
  Keep building your Python programming experience.
&lt;/h4&gt;

&lt;p&gt;Learn Python concepts from data structures to decorators, all with step-by-step challenges. Educative's hands-on courses let you learn the languages and tools you need quickly, with real-world examples and in-browser code environments.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/intro-python-3" rel="noopener noreferrer"&gt;An Intro to Python 3&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;





&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Slicing
&lt;/h2&gt;

&lt;p&gt;Now, we'll explore how to use slicing and some more advanced variable manipulation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slicing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Slicing is a Python-specific concept for accessing a range of values in sequence types, such as lists or strings. It is one of the most popular Python features. Understanding slicing is one of the key requirements for understanding most existing Python codebases.&lt;/p&gt;

&lt;p&gt;The idea behind slicing is simple. Use the bracket notation to access a sequence of elements instead of only a single element. You do this via the colon notation of &lt;code&gt;[start: end]&lt;/code&gt;. This notation defines the start index (included) and the end index (excluded).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;: A very common source of bugs is forgetting that the end index is always excluded in sequence operators.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For the sake of completeness, quickly look into the advanced slicing notation &lt;code&gt;[start:end:step]&lt;/code&gt;. The only difference to the previous notation is that it allows you to specify the step size. For example, the command &lt;code&gt;'python'[:5:2]&lt;/code&gt; returns every second character up to the fourth character, i.e., the string &lt;code&gt;pto&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;len()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;len()&lt;/code&gt; function is a handy tool to get the length of built-in Python data types, such as strings, lists, dictionaries, or tuples.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Challenge 4: Slicing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is the output of the above code?&lt;/p&gt;

&lt;p&gt;A) &lt;code&gt;galaxy&lt;/code&gt;&lt;br&gt;
B) &lt;code&gt;alaxy&lt;/code&gt;&lt;br&gt;
C) &lt;code&gt;5&lt;/code&gt;&lt;br&gt;
D) &lt;code&gt;6&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The code outputs the number &lt;code&gt;5&lt;/code&gt; because &lt;code&gt;len()&lt;/code&gt; checks the length of &lt;code&gt;galaxy&lt;/code&gt; starting after the first element. The selected portion, &lt;code&gt;alaxy&lt;/code&gt;, has 5 letters. Therefore, the program prints &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  5. Branching
&lt;/h2&gt;

&lt;p&gt;Now we're moving into some harder challenges. In this challenge, we'll introduce branching and conditional statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;if_confusion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
      &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;B&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
      &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;E&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

  &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="n"&gt;x_old&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;
      &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;
      &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;x_old&lt;/span&gt;

      &lt;span class="nf"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;C&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;D&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;F&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;if_confusion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like any other programming language, Python also has Conditional Statements also known as Branching Statements. To create branches, you can use the keywords if, else, or &lt;code&gt;elif&lt;/code&gt;. These statements return Booleans, &lt;code&gt;true&lt;/code&gt; if the condition is met and &lt;code&gt;false&lt;/code&gt; if it is not.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;: The computer does not execute the code strictly from top to bottom, and you shouldn’t either.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead, start where the program execution starts, which is at the bottom with the function call &lt;code&gt;if_confusion(3, 7)&lt;/code&gt;.&lt;br&gt;
Now you know that &lt;code&gt;x=3&lt;/code&gt; and &lt;code&gt;y=7&lt;/code&gt;. Then, you proceed to do what the interpreter does.&lt;/p&gt;

&lt;p&gt;As &lt;code&gt;x&amp;gt;y&lt;/code&gt; is false, you can skip the whole upper part of the function. Similarly, you can skip the if branch for &lt;code&gt;x-2&amp;gt;y-4&lt;/code&gt;.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Challenge 5: Branching&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is the output of the above code?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;A&lt;/code&gt;&lt;br&gt;
&lt;code&gt;B&lt;/code&gt;&lt;br&gt;
&lt;code&gt;C&lt;/code&gt;&lt;br&gt;
&lt;code&gt;D&lt;/code&gt;&lt;br&gt;
&lt;code&gt;E&lt;/code&gt;&lt;br&gt;
&lt;code&gt;F&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The key is to notice the indentation. The first &lt;code&gt;if&lt;/code&gt; statement asks if &lt;code&gt;x&lt;/code&gt; is greater than &lt;code&gt;y&lt;/code&gt;. This is false for our entered input of &lt;code&gt;(3,7)&lt;/code&gt; so we do not enter that &lt;code&gt;if&lt;/code&gt; block. Instead, we enter the corresponding &lt;code&gt;else&lt;/code&gt; statement on line 15. Both of the &lt;code&gt;if&lt;/code&gt; statements are not true and so we return &lt;code&gt;F&lt;/code&gt; at the bottom of the &lt;code&gt;else&lt;/code&gt; block.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  6. For loop
&lt;/h2&gt;

&lt;p&gt;Now that we've seen a &lt;code&gt;while&lt;/code&gt; loop, we'll learn about &lt;code&gt;for&lt;/code&gt; loops.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;cat&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;mouse&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Repeated code is redundant and hard to read, debug, and maintain. As programmers, we should avoid redundant code at all costs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The Python for loop statement is a way out of redundant code. With a &lt;code&gt;for&lt;/code&gt; loop, you write code once and put it into different contexts.&lt;/p&gt;

&lt;p&gt;Among the ingredients that make a programming language powerful are control flow statements. The Python for loop is one such control flow statement. It repeats the execution of the code body for all sequence elements, iterating over all elements in the order of the sequence. It's similar to a &lt;code&gt;forEach&lt;/code&gt; loop found in Java or JavaScript. &lt;/p&gt;

&lt;p&gt;In the puzzle, the variable word takes first the value cat and second the value mouse. We then print out the length of each word.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Challenge 6: For Loops&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is the output of the above code?&lt;/p&gt;

&lt;p&gt;A) &lt;code&gt;cat mouse&lt;/code&gt;&lt;br&gt;
B) &lt;code&gt;3 5&lt;/code&gt;&lt;br&gt;
C) &lt;code&gt;cat&lt;/code&gt;&lt;br&gt;
D) &lt;code&gt;3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
The answer is &lt;code&gt;3 5&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;for&lt;/code&gt; loop repeats the code body for every &lt;code&gt;word&lt;/code&gt; in the &lt;code&gt;words&lt;/code&gt; list. The code body prints the length of the current selected word. The length of the first &lt;code&gt;word&lt;/code&gt; is &lt;code&gt;3&lt;/code&gt; and the length of the second word is &lt;code&gt;5&lt;/code&gt;. &lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  7. Functions
&lt;/h2&gt;

&lt;p&gt;For our final challenge, we'll take a look at a fundamental programming concept: functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;


&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;func&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A function encapsulates a sequence of program instructions. The ideal function solves a single high-level goal.&lt;/p&gt;

&lt;p&gt;For example, you can encapsulate the task of searching the web for specific keywords into a named function. This allows you to call for a search later using just a single statement. &lt;/p&gt;

&lt;p&gt;Functions allow you to write code once and reuse it later or in other programs. Reusing code is more efficient than writing the same code each time. Suppose you want to calculate the square root of 145. You could either calculate it for the specific value 145 or define a function that calculates the square root for any value &lt;code&gt;x&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defining a function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can define a function with the keyword &lt;code&gt;def&lt;/code&gt;, followed by a name and the function’s arguments. The Python interpreter maintains a symbol table that stores all function definitions, i.e., mappings from function names to function objects.&lt;/p&gt;

&lt;p&gt;This allows the interpreter to relate each occurrence of the function name to the defined function object. A single function object can have zero, one, or even many names.&lt;/p&gt;

&lt;p&gt;In the puzzle, we assign the function object to the name &lt;code&gt;func&lt;/code&gt; and then reassign it to the new name &lt;code&gt;f&lt;/code&gt;. We can then use both the names to refer to the same code.&lt;/p&gt;

&lt;p&gt;Upon the function call, the Python interpreter will find the function in the symbol table and execute it. This can make your code more readable when calling the same function in different contexts.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Challenge 7: Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is the output of the above code?&lt;/p&gt;

&lt;p&gt;A) &lt;code&gt;6&lt;/code&gt;&lt;br&gt;
B) &lt;code&gt;3&lt;/code&gt;&lt;br&gt;
C) &lt;code&gt;3+3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The solution is &lt;code&gt;6&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;We first set up the function &lt;code&gt;func&lt;/code&gt; to return &lt;code&gt;x+1&lt;/code&gt;. We then add &lt;code&gt;f&lt;/code&gt; as another valid name for the function. This allows us to call either &lt;code&gt;func&lt;/code&gt; or &lt;code&gt;f&lt;/code&gt; and execute the same code block. As a result, the final function all translates to &lt;code&gt;(2+1) + (2+1)&lt;/code&gt;.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What to learn next
&lt;/h2&gt;

&lt;p&gt;Now that you've completed these 7 challenges, you have programming experience with the major building blocks of most Python 3 programs. Transitioning to a new language can be tough, but know that you're making a great investment in your education. Python is the best general-purpose language in use today and there has never been a better time to start learning Python! &lt;/p&gt;

&lt;p&gt;As you continue your journey to become a python programmer, look for Python projects on concepts like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.educative.io/blog/how-to-use-oop-in-python" rel="noopener noreferrer"&gt;Object Oriented Programming (OOP)&lt;/a&gt; with Python class inheritance&lt;/li&gt;
&lt;li&gt;Python Standard Library&lt;/li&gt;
&lt;li&gt;Implementation with popular outside technologies like &lt;a href="https://www.educative.io/blog/what-is-django-python" rel="noopener noreferrer"&gt;Django&lt;/a&gt; or &lt;a href="https://www.educative.io/blog/python-pandas-tutorial" rel="noopener noreferrer"&gt;Pandas&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Advanced Python 3 syntax like &lt;a href="https://www.educative.io/blog/python-lambda-functions-tutorial" rel="noopener noreferrer"&gt;Lambda&lt;/a&gt; and Continue statements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To help you get to that point, Educative has launched our new Python course &lt;a href="https://www.educative.io/courses/intro-python-3" rel="noopener noreferrer"&gt;&lt;strong&gt;An Intro to Python 3&lt;/strong&gt;&lt;/a&gt;. This course features 50 challenges that provide hands-on experience with all the skills you'll need to jump into building Python projects. The course's challenge-based learning approach is perfect for developers looking to transition to Python because it draws on your existing coding intuition to learn in half the time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy learning!&lt;/em&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  Continue reading about Python Projects
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/web-development-in-python" rel="noopener noreferrer"&gt;A Complete Guide to Web Development in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/best-python-ides-ce-2021" rel="noopener noreferrer"&gt;10 Best Python IDEs and Code Editors to use in 2021&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/python-quirks-tricks" rel="noopener noreferrer"&gt;10 Python quirks you should know about in your code&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Celebrating Pride: How to write gender-neutral coding tutorials</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Wed, 09 Jun 2021 21:08:09 +0000</pubDate>
      <link>https://dev.to/educative/celebrating-pride-how-to-write-gender-neutral-coding-tutorials-m1</link>
      <guid>https://dev.to/educative/celebrating-pride-how-to-write-gender-neutral-coding-tutorials-m1</guid>
      <description>&lt;p&gt;&lt;strong&gt;Pride Month&lt;/strong&gt; is an annual celebration for the month of June that is dedicated to celebrating Lesbian, Gay, Bisexual, Transexual, and Queer people and culture. It is also a time to reaffirm support for the LGBTQ+ community's continued struggle for equal rights and treatment in society.&lt;/p&gt;

&lt;p&gt;The first Pride celebration was in New York in 1970 to remember the 1969 Stonewall Uprising, a demonstration oppose to the hate-fueled police raids on the Stonewall Gay club. Many historians view this and the following Pride celebration as a &lt;strong&gt;tipping point&lt;/strong&gt; in the United States Gay Liberation Movement.&lt;/p&gt;

&lt;p&gt;Educative is committed to building a better, more inclusive future for LGBTQ+ people, both in the developer community and the world at large. One way we can all do this is to think critically about &lt;strong&gt;how we write coding tutorials&lt;/strong&gt; and examples. &lt;/p&gt;

&lt;p&gt;Today, we'll explore how you can make your educational content more approachable for Queer and Non-Male identifying readers and increase the performance of your content at the same time!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s what we’ll cover today:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How gendered language hurts content&lt;/li&gt;
&lt;li&gt;Simple changes to make tutorials more inclusive&lt;/li&gt;
&lt;li&gt;Wrapping up&lt;/li&gt;
&lt;/ul&gt;



&lt;h4&gt;&lt;b&gt; Never miss Educative content again &lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;Sign up for our free, bi-monthly newsletter to receive the latest in tech news and trends, right in your inbox.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; &lt;a href="https://www.educative.io/blog/blog-newsletter-annoucement" rel="noopener noreferrer"&gt;Learn more about our Newsletter&lt;/a&gt; &lt;/b&gt; &lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How gendered language hurts content
&lt;/h2&gt;

&lt;p&gt;Many online coding tutorials &lt;strong&gt;default to male pronouns&lt;/strong&gt;. The most common instances of this are when discussing functionalities or when providing a hypothetical example.  While the writers likely do not intend to offend, this gendered language can make Non-Male readers feel unwelcome in the developer space. &lt;/p&gt;

&lt;p&gt;For example, it's common to find articles that say something like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"A developer can use an array to store integers. This will allow &lt;em&gt;him&lt;/em&gt; to access these integers in the future." &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, we can see that the writer began with a gender-neutral term, "developer", but has then included a male pronoun, "him". The writer has therefore implied, perhaps unintentionally, &lt;strong&gt;that developers are inherently male&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Similarly, many writers will default to writing hypothetical examples using male pronouns exclusively. This is especially common for examples that discuss management or administrative positions. &lt;/p&gt;

&lt;p&gt;For example, a tutorial may include sections like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Imagine we have a Product Manager that wants to connect &lt;em&gt;his&lt;/em&gt; app to a database. &lt;em&gt;He&lt;/em&gt; knows the database uses a NoSQL schema." &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Like the first example, this hypothetical example implies that Product Managers are inherently male because it is an unspoken assumption.&lt;/p&gt;

&lt;p&gt;Most male readers may not notice this because it matches their experience; they are a male developer so the developer being referred to as male seems natural. However, this type of implication is very disheartening for Non-Male readers because it can make them feel like an outcast or an exception within the developer community. &lt;/p&gt;

&lt;p&gt;While a single instance of gendered language will not hurt the reader's sense of belonging in the community, these individual instances culminate over time to steady wear down the Non-Male developer's comfort as a member of the community.&lt;/p&gt;

&lt;p&gt;We should avoid this because it &lt;strong&gt;excludes groups of people from the community&lt;/strong&gt; and profession based on their natural-born characteristics.&lt;/p&gt;

&lt;p&gt;From a content writer's perspective, the success of your content relies on the reader's passion for the profession and comfort level within the community. Readers who do not feel welcome in the community or feel out of place as a developer are not going to read community-made coding tutorial content. These are valuable readers that have been lost but could be easily retained with just a few changes to how we write tutorials as a community.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fbfmvf77jfvb0lejkdngs.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fbfmvf77jfvb0lejkdngs.PNG" alt="Cartoon checklist" width="752" height="383"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Simple changes to make tutorials more inclusive
&lt;/h2&gt;

&lt;p&gt;We can easily avoid these problems by paying attention to the implications of gendered language and replacing it with a gender-neutral alternative. &lt;/p&gt;

&lt;p&gt;Writing in gendered language is a hard habit to break so &lt;strong&gt;don't worry if you have to write first then revise&lt;/strong&gt; when just starting out. Just making these small changes bit-by-bit will make a big difference to Non-Male readers.&lt;/p&gt;



&lt;h3&gt;
  
  
  Functionality explanations
&lt;/h3&gt;

&lt;p&gt;The functionality of a coding concept is the &lt;strong&gt;same regardless of the gender of the user&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Therefore, we don't have to specify gender when explaining the concept and can simply use impersonal, gender-neutral language like "the developer" or "a developer". We can also replace any pronouns with "they/their", which are gender-neutral and can be used as a single or plural pronoun.&lt;/p&gt;

&lt;p&gt;We can revise our previous example to instead be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"A developer can use an array to store integers. This will allow &lt;em&gt;them&lt;/em&gt; to access these integers in the future.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When discussing multiple people, use their titles in place of pronouns to avoid confusion:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The developer&lt;/em&gt; designed the app to learn from &lt;em&gt;the user's&lt;/em&gt; in-app behavior. &lt;em&gt;The user&lt;/em&gt; can limit the type of data tracked by the app.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, it's better to use "The user" instead of "they" because it makes it clearer which of the two established people we're referring to.&lt;/p&gt;

&lt;p&gt;Both examples leave the developer as a blank slate to explain the topic and allow readers of all kinds to interface with the topic. &lt;/p&gt;



&lt;h3&gt;
  
  
  Hypothetical examples
&lt;/h3&gt;

&lt;p&gt;Hypothetical examples are more specific and human-focused than explanations of abstract concepts. It's therefore even more important to use gender-neutral language to avoid making implicit claims. &lt;/p&gt;

&lt;p&gt;Let's look back at our original hypothetical example and make it better:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Imagine we have a Product Manager that wants to connect &lt;em&gt;their&lt;/em&gt; app to a database. &lt;em&gt;They&lt;/em&gt; know the database uses a NoSQL schema."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can replace all male pronouns with gender-neutral pronouns to avoid making assumptions about the gender of the product manager. Since there is no second person in this example, we have no risk of confusing the reader by using only pronouns.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fy1zeu4cl53d0uktbx3zu.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fy1zeu4cl53d0uktbx3zu.PNG" alt="X to checkmark" width="749" height="259"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  The problem with "he/she"
&lt;/h3&gt;

&lt;p&gt;Many tutorials will use "he/she" and "his/her" in place of pronouns to try to include all readers. &lt;/p&gt;

&lt;p&gt;For example, it's common to see a sentence like: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The developer can use Azure services to access cloud storage. &lt;em&gt;He/she&lt;/em&gt; will instantly gain access to many gigabytes of space and can access &lt;em&gt;his/her&lt;/em&gt; data anywhere with an internet connection."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While this comes from a good place, using these either/or pronouns unintentionally &lt;strong&gt;excludes Non-Binary readers&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Similar to "he", "he/she" implies that only people that identify within the traditional gender binary are welcome within the community. This format has a history of being used for transphobic and queer gatekeeping and can offend Non-Binary readers.&lt;/p&gt;

&lt;p&gt;Instead, &lt;strong&gt;it's better to use "they", "them", or just titles&lt;/strong&gt;. Doing so not only invites more demographics of readers to engage with your content but also reduces visual clutter by cutting the forward-slash from the sentence.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;While it can be difficult to break the habit of using gendered language, it makes a big difference to Non-Male members of your audience and keeps them engaged with your content. It can be tricky to get into the habit of writing with gender in mind but you don't have to make sweeping changes at once. &lt;/p&gt;

&lt;p&gt;In the end, what's important is that you're doing your best to welcome all kinds of developers to the community and improve your community engagement skills one article at a time.&lt;/p&gt;



&lt;h3&gt;
  
  
  Continue reading about social justice in tech
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/tech-innovators-black-history-month" rel="noopener noreferrer"&gt;8 Tech Innovators to Honor Black History Month&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/diversity-inclusion-tech-industry" rel="noopener noreferrer"&gt;Diversity and Inclusion in Tech: where do we go from here?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/racial-bias-machine-learning-algorithms" rel="noopener noreferrer"&gt;Understanding racial bias in machine learning algorithms&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>culture</category>
      <category>tutorial</category>
      <category>writing</category>
      <category>devpride</category>
    </item>
    <item>
      <title>Top 5 Distributed System Design Patterns</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Wed, 02 Jun 2021 22:23:04 +0000</pubDate>
      <link>https://dev.to/educative/top-5-distributed-system-design-patterns-4d21</link>
      <guid>https://dev.to/educative/top-5-distributed-system-design-patterns-4d21</guid>
      <description>&lt;p&gt;Distributed applications are a staple of the modern software development industry. They're pivotal to cloud storage services and allow web applications of massive scale to stay reactive. As programmers build these systems, they need fundamental building blocks they can use as a starting point and to communicate in a shared vocabulary.&lt;/p&gt;

&lt;p&gt;This is where distributed system design patterns become invaluable. While sometimes overused, design patterns are a key skill recruiters are looking for and are essential to stand out in advanced system design interviews.&lt;/p&gt;

&lt;p&gt;Today, we'll explore 5 of the top distributed system design patterns to help you learn their advantages, disadvantages, and when to use them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s what we’ll cover today:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is a distributed system design pattern?&lt;/li&gt;
&lt;li&gt;1. Command and Query Responsibility Segregation&lt;/li&gt;
&lt;li&gt;2. Two-Phase Commit&lt;/li&gt;
&lt;li&gt;3. Saga&lt;/li&gt;
&lt;li&gt;4. Replicated Load-Balanced Services&lt;/li&gt;
&lt;li&gt;5. Sharded Services&lt;/li&gt;
&lt;li&gt;What to learn next&lt;/li&gt;
&lt;/ul&gt;



&lt;h4&gt;&lt;b&gt; Ace advanced system design questions with ease &lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;Practice top distributed systems questions and design patterns to use in your next system design interview.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/grokking-adv-system-design-intvw" rel="noopener noreferrer"&gt;Grokking the Advanced System Design Interview&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a distributed system design pattern?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.educative.io/blog/the-7-most-important-software-design-patterns" rel="noopener noreferrer"&gt;Design patterns&lt;/a&gt; are tried and tested ways of building systems that each fit a particular use case. They're not implementations but rather are abstract ways of structuring a system. Most design patterns have been developed and updated over years by many different developers, meaning they're often very efficient starting points. &lt;/p&gt;

&lt;p&gt;Design patterns are building blocks that allow programmers to pull from existing knowledge rather than starting from scratch with every system. They also create a set of standard models for system design that help other developers see how their projects can interface with a given system.&lt;/p&gt;

&lt;p&gt;Creational design patterns provide a baseline when building new objects. Structural patterns define the overall structure of a solution. Behavioral patterns describe objects and how they communicate with each other.&lt;/p&gt;

&lt;p&gt;Distributed system design patterns are design patterns used when developing &lt;a href="https://www.educative.io/blog/distributed-systems-considerations-tradeoffs" rel="noopener noreferrer"&gt;distributed systems&lt;/a&gt;, which are essentially collections of computers and data centers that act as one computer for the end-user. These distributed design patterns outline a software architecture for how different nodes communicate with each other, which nodes handle each task, and the process flow for different tasks.&lt;/p&gt;

&lt;p&gt;These patterns are widely used when designing the distributed system architecture of large-scale &lt;a href="https://www.educative.io/blog/beginners-guide-cloud-computation" rel="noopener noreferrer"&gt;cloud computing&lt;/a&gt; and scalable &lt;a href="https://www.educative.io/blog/microservices-architecture-tutorial-all-you-need-to-get-started" rel="noopener noreferrer"&gt;microservice software systems&lt;/a&gt;.&lt;/p&gt;



&lt;h3&gt;
  
  
  Types of distributed design patterns
&lt;/h3&gt;

&lt;p&gt;Most distributed design patterns fall into one of three categories based on the functionality they work with.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Object communication&lt;/strong&gt;: Describes the messaging protocols and permissions for different components of the system to communicate. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security&lt;/strong&gt;: Handles confidentiality, integrity, and availability concerns to ensure the system is secure from unauthorized access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event-driven&lt;/strong&gt;: Patterns that describe the production, detection, consumption, and response to system events.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Command and Query Responsibility Segregation (CQRS)
&lt;/h2&gt;

&lt;p&gt;The CQRS pattern focuses on separating the read and write operations of a distributed system to increase scalability and security. This model uses commands to write data to persistent storage and queries to locate and fetch the data.&lt;/p&gt;

&lt;p&gt;These are handled by a command center, which receives requests from users. The command center then fetches the data and makes any necessary modifications, saves the data, and notifies the read service. The read service then updates the read model to show the change to the user. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduces system complexity by delegating tasks&lt;/li&gt;
&lt;li&gt;Enforces a clear separation between business logic and validation&lt;/li&gt;
&lt;li&gt;Helps categorize processes by their job&lt;/li&gt;
&lt;li&gt;Reduces the number of unexpected changes to shared data&lt;/li&gt;
&lt;li&gt;Reduces the number of entities that have modifying access to data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requires constant back-and-forth communication between command a read-models&lt;/li&gt;
&lt;li&gt;Can cause increased latency when sending high throughput queries&lt;/li&gt;
&lt;li&gt;No means to communicate between service processes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CQRS is best for data-intensive applications like SQL or noSQL database management systems. It's also helpful for data-heavy microservice architectures. It's great for handling stateful applications because the writer/reader distinction helps with immutable states.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Two-Phase Commit (2PC)
&lt;/h2&gt;

&lt;p&gt;2PC is similar to CQRS in its transactional approach and reliance on a central command, but partitions are processed by their type and what stage of completion they're on. The two phases are the &lt;strong&gt;Prepare&lt;/strong&gt; phase, in which the central control tells the services to prepare the data, and the &lt;strong&gt;Commit&lt;/strong&gt; phase, which signals the service to send the prepared data.&lt;/p&gt;

&lt;p&gt;All services in a 2PC system are locked by default, meaning they cannot send data. While locked, services complete the Prepare stage so they're ready to send once unlocked. The coordinator unlocks services one-by-one and requests its data. If the service is not ready to submit its data, the coordinator moves onto another service. Once all prepared data has been sent, all services unlock to await new tasks from the coordinator.&lt;/p&gt;

&lt;p&gt;2PC essentially ensures that only one service can operate at a time, which makes the process more resistant and consistent than CQRS. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consistent and resistant to errors due to lack of concurrent requests&lt;/li&gt;
&lt;li&gt;Scalable, can handle big data pools as easily as it can handle data from a single machine&lt;/li&gt;
&lt;li&gt;Allows for isolation and data sharing at the same time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not fault-tolerant, prone to bottlenecks and blocking due to its synchronous nature&lt;/li&gt;
&lt;li&gt;Requires more resources than other design patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;2PC is best for distributed systems that deal with high-stakes transaction operations that favor accuracy over resource efficiency. It is resistant to error and easy to track mistakes when they occur, even at scale.&lt;/p&gt;


&lt;h4&gt;
  
  
  Keep learning about distributed systems.
&lt;/h4&gt;

&lt;p&gt;Knowledge of distributed systems is a top priority for modern recruiters. Prepare for your next system design interview with hands-on practice and insider tips. Educative's text-based courses let you get the experience you need to land your next job on the first try.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/grokking-adv-system-design-intvw" rel="noopener noreferrer"&gt;Grokking the Advanced System Design Interview&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Saga
&lt;/h2&gt;

&lt;p&gt;Saga is an &lt;a href="https://www.educative.io/blog/javascript-promises-tutorial" rel="noopener noreferrer"&gt;asynchronous&lt;/a&gt; pattern that does not use a central controller and instead communicates entirely between services. This overcomes some of the disadvantages of the previously covered synchronous patterns. &lt;/p&gt;

&lt;p&gt;Saga uses Event Bus to allow services to communicate with each other in a microservice system. The bus sends and receives requests between services and each participating service creates a local transaction. The participating services then each emit an event for other services to receive. Other services all listen for events. The first service to receive the event will perform the required action. If that service fails to complete the action, it's sent to other services.&lt;/p&gt;

&lt;p&gt;This structure is similar to the 2PC design in that services are cycled if one cannot complete a task. However, Saga removes the central control element to better manage the flow and reduce the number of back-and-forth communication required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Individual services can handle much longer transactions&lt;/li&gt;
&lt;li&gt;Great for the distributed system due to decentralization&lt;/li&gt;
&lt;li&gt;Reduces bottlenecks thanks to peer-to-peer communication between services&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Asynchronous autonomy makes it difficult to track which services are doing individual tasks&lt;/li&gt;
&lt;li&gt;Difficult to debug due to complex orchestration&lt;/li&gt;
&lt;li&gt;Less service isolation than previous patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Saga's decentralized approach is great for scalable serverless functions that handle many parallel requests at once. AWS uses Saga-based designs in many functions like step and lambda functions.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Replicated Load-Balanced Services (RLBS)
&lt;/h2&gt;

&lt;p&gt;The RLBS pattern is the simplest and most commonly used design pattern. At the most basic level, it consists of multiple identical services that all report to a central load balancer. Each service is capable of handling tasks and can replicate if they fail. The load balancer receives requests from the end-user and distributes them to the services either using a round-robin fashion or sometimes a more complex routing algorithm. &lt;/p&gt;

&lt;p&gt;The duplicate services ensures the application maintains a high availability for user requests and can redistribute work if one instance of the service should fail.&lt;/p&gt;

&lt;p&gt;RLBS is often used with Azure Kubernetes, which is an open-source container orchestration technology made by Microsoft that offers automatic service scaling based on workflow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consistent performance from the view of the end-user&lt;/li&gt;
&lt;li&gt;Can quickly recover from failed services&lt;/li&gt;
&lt;li&gt;Highly scalable with more services&lt;/li&gt;
&lt;li&gt;Excellent for concurrency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inconsistent performance based on load balancer algorithm&lt;/li&gt;
&lt;li&gt;Resource intensive to manage services&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;RLBS is great for front-facing systems that have inconsistent workloads throughout the day but must maintain low latency, such as entertainment web apps like Netflix or Amazon Prime.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Sharded Services
&lt;/h2&gt;

&lt;p&gt;An alternative to replica-based designs is to create a selection of services that each only completes a certain kind of request. This is called "sharding" because you split the request flow into multiple unequal sections. For example, you may have one shard service that accepts all caching requests and another that only handles high-priority requests. The load balancer evaluates each request when it comes in and distributes it to the appropriate shard for completion.&lt;/p&gt;

&lt;p&gt;Sharded services are normally used for building stateful services because the size of the state is often too large for a single stateless container. Sharding lets you scale the individual shard to meet the size of the state.&lt;/p&gt;

&lt;p&gt;Sharded services also allow you to handle high-priority requests faster. Shards dedicated to high-priority requests are always available to handle such requests the moment they come in rather than being placed in the queue. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allows you to scale shards for common requests&lt;/li&gt;
&lt;li&gt;Easy to prioritize requests&lt;/li&gt;
&lt;li&gt;Simple to debug due to natural sorting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can be resource-intensive to maintain many shards&lt;/li&gt;
&lt;li&gt;Leads to loss in performance if shards are used disproportionately&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sharded services are best when your system receives a predictable imbalance in request types but some requests have priority. &lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What to learn next
&lt;/h2&gt;

&lt;p&gt;Distributed system design patterns are an essential part of any successful back-end system. However, these are just a few of the patterns used by professional software engineers. &lt;/p&gt;

&lt;p&gt;Some patterns for you to learn next are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sidecar Pattern&lt;/li&gt;
&lt;li&gt;Write-ahead Log&lt;/li&gt;
&lt;li&gt;Split-Brain Pattern&lt;/li&gt;
&lt;li&gt;Hinted Handoff&lt;/li&gt;
&lt;li&gt;Read Repair&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To help you master these advanced system design patterns, Educative has created the course &lt;a href="https://www.educative.io/courses/grokking-adv-system-design-intvw" rel="noopener noreferrer"&gt;&lt;strong&gt;Grokking the Advanced System Design Interview&lt;/strong&gt;&lt;/a&gt;. This course walks you through the top advanced SDI questions with in-depth explanations and hands-on practice. You'll learn about all the fundamental design patterns an advanced systems engineer needs. By the end, you'll have real-world experience with all the design patterns tested most by top industry recruiters.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy learning!&lt;/em&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  Continue learning about distributed systems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/distributed-systems-considerations-tradeoffs" rel="noopener noreferrer"&gt;What are Distributed Systems? A quick introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/scaling-in-python" rel="noopener noreferrer"&gt;An Introduction to Scaling Distributed Python Applications&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/microservices-architecture-tutorial-all-you-need-to-get-started" rel="noopener noreferrer"&gt;Microservices Architecture Tutorial: all you need to get started&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>distributedsystems</category>
      <category>systems</category>
      <category>design</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Bytesize: Quantum computing and the future of programming</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Wed, 02 Jun 2021 22:19:42 +0000</pubDate>
      <link>https://dev.to/educative/bytesize-quantum-computing-and-the-future-of-programming-1d5e</link>
      <guid>https://dev.to/educative/bytesize-quantum-computing-and-the-future-of-programming-1d5e</guid>
      <description>&lt;p&gt;Bytesize is our 5-minute infusion of developer history, speculation, or otherwise fun knowledge that you can enjoy during a work or study break.&lt;/p&gt;

&lt;p&gt;When you set off to become a developer, you probably dreamed of working on self-driving cars, artificial intelligence, world-changing apps, or any number of other amazing products. However, there’s a lot of learning and beginner developer work you need to do before you can get there. This can be draining and can make you lose sight of what got you excited to be a developer in the first place.&lt;/p&gt;

&lt;p&gt;When knee-deep in a tough concept or a product function that’s fighting back, Bytesize is here every week to give you 5-minutes to shake it off and let your imagination fly once more.&lt;/p&gt;



&lt;h4&gt;&lt;b&gt; Never miss Educative content again &lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;Sign up for our free, bi-monthly newsletter to receive the latest in tech news and trends, right in your inbox.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; &lt;a href="https://www.educative.io/blog/blog-newsletter-annoucement" rel="noopener noreferrer"&gt;Learn more about our Newsletter&lt;br&gt;
&lt;/a&gt; &lt;/b&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  What is Quantum Computing?
&lt;/h2&gt;

&lt;p&gt;Quantum Computing is a novel type of computer structure using quantum qubits instead of the traditional binary bit found in modern transistors. Qubits are unique because they can be set to &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt; as well as be suspended in a quantum superposition between &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt;. The qubit is necessarily at a halfway point, but rather it's unknown whether the particle is clear or set. &lt;/p&gt;

&lt;p&gt;The superposition state allows qubits to have 3 possible settings rather than the traditional &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt;. This changes the foundational structure of programs from a series of "yes" or "no" to one that offers an "I don't know" option. Qubits, therefore, allow computers to solve certain problems at a staggeringly fast rate compared to traditional computers, especially when dealing with analyzing large data sets or completing complex mathematical operations.&lt;/p&gt;

&lt;p&gt;While the quantum computer excels at certain tasks, it's not a strict upgrade over standard hardware. In fact, researchers have found that quantum computers are as fast or slower to complete many day-to-day tasks that we'd consider basic. Considering the high cost to build these machines and the energy required to keep a qubit in its superposition, it's unlikely we'll soon be walking around with Quantum iPhones or laptops for use on every task.&lt;/p&gt;

&lt;p&gt;Instead, the relationship between current computers and quantum computers will likely be similar to the relationship between GPU and CPU; each excels at specific tasks, and modern machines make use of when their ideal use case arises. &lt;/p&gt;

&lt;p&gt;The two current ideas to allow for everyday use of quantum computing are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Quantum Processing Unit (QPU)&lt;/strong&gt;: Like a CPU, the QPU would be a modularized piece of hardware that you could install in a desktop or laptop computer. The operating system would then relegate high volume analytical tasks to the QPU, ensuring it's always used for its intended use. This idea is a stretch dream until scientists can discover a superconductor that's effective enough to sustain sufficient energy for the qubit to be in superposition whenever needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quantum Cloud Systems&lt;/strong&gt;: A centralized, off-site quantum computer that other computers can use via the cloud. The system would theoretically work like current cloud storage systems where a third-party owns the computer and users pay based on the amount they use the system. Quantum Cloud systems seem to be a more feasible solution for the technology's current state and could start seeing use as early as the next 5 years.&lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;
  
  
  What fields will quantum computing affect most?
&lt;/h2&gt;

&lt;p&gt;So quantum computing is on the horizon, but how will it affect programmers when it becomes a reality?&lt;/p&gt;



&lt;h3&gt;
  
  
  Cybersecurity
&lt;/h3&gt;

&lt;p&gt;Cybersecurity will need to be heavily revamped to maintain effectiveness. Many modern encryption systems use RSA encryption, which relies on current computers being unable to find all the prime numbers in a 500+ digit number.&lt;/p&gt;

&lt;p&gt;While it would take several years for current computer systems to crack encryptions like this, quantum computers could do it in less than an hour. That means the cybersecurity community will need to come up with a new encryption algorithm that is uncrackable by both current and quantum computers.&lt;/p&gt;

&lt;p&gt;On the other hand, quantum computers allow for new cryptographic tools like quantum cryptography. This theoretical system stores an encryption key in a quantum particle that enters a quantum state and cannot be accessed for a period of 30-60 years when it returns to a normal state. Any attempt to view the key would change its state due to the wave function collapse property, which says that quantum particles in superposition must change state when observed.&lt;/p&gt;

&lt;p&gt;In short, while cybersecurity experts will lose a familiar tool, they will gain a new powerful form of cryptography that is theoretically impenetrable.&lt;/p&gt;



&lt;h3&gt;
  
  
  Machine learning and AI
&lt;/h3&gt;

&lt;p&gt;The other biggest change will be with big data analysis. Machine learning is being used in a myriad of fields from financial prediction to robotics to weather forecasting. Each of these fields uses machine learning algorithms to analyze data as it is made available and make predictions as close to real-time as possible.&lt;/p&gt;

&lt;p&gt;However, current hardware bottlenecks these technologies. Current computers are relatively slow at analyzing large sets of mixed data. There is therefore a floor for how close to live updates these systems can get.&lt;/p&gt;

&lt;p&gt;Quantum computing excels at handling high volumes of data with staggering efficiency, meaning it could open the door to near-instant data analysis. &lt;/p&gt;

&lt;p&gt;Financial predictions could more quickly react to changes and can process more variables in the market. AI and robots could immediately identify, evaluate, and respond to new stimuli such as changes in the environment. Weather forecasts could evaluate hundreds of live feeds of meteorological data and synthesize readings like air pressure, humidity, wind strength, and more to create more accurate and reactive predictions.&lt;/p&gt;

&lt;p&gt;Overall, quantum computing will affect anything that relies on big data analysis. &lt;/p&gt;



&lt;h3&gt;
  
  
  Continue reading about these fields
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/cyber-security-guide" rel="noopener noreferrer"&gt;Guide to Cyber Security: learn how to defend your systems
&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/what-is-big-data" rel="noopener noreferrer"&gt;What is Big Data? Characteristics, Types, and Technologies
&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/top-10-ml-algorithms-for-data-science-in-5-minutes" rel="noopener noreferrer"&gt;The top 10 ML algorithms for data science in 5 minutes
&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>hardware</category>
      <category>quantum</category>
      <category>news</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>Educative Raises $12 Million in Series A Funding</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Thu, 20 May 2021 22:05:17 +0000</pubDate>
      <link>https://dev.to/educative/educative-raises-12-million-in-series-a-funding-1i0g</link>
      <guid>https://dev.to/educative/educative-raises-12-million-in-series-a-funding-1i0g</guid>
      <description>&lt;p&gt;We founded Educative with the mission to make every developer more productive and successful. It was an inspirational rallying cry for the early few who helped us found the company. Along the way, we’ve been fortunate enough to work with millions of developers. We saw first-hand that developers need real hands-on training to succeed, and the market has responded with a resounding agreement.&lt;/p&gt;

&lt;p&gt;That’s why we’re excited to announce the completion of our Series A funding round. Matrix Partners led the round of $12 million with additional funding from new and returning investors, including Trilogy Equity Partners, Lookout founder Kevin Mahaffey, Mercury founder Immad Akhund, Segment founder Ilya Volodarsky, and several other angel investors. For additional information, we hope you’ll read the &lt;a href="http://www.prnewswire.com/news-releases/educative-secures-12-million-series-a-funding-to-accelerate-growth-and-expand-b2b-offerings-for-engineering-managers-and-leaders-301294762.html?tc=eml_cleartime" rel="noopener noreferrer"&gt;news release&lt;/a&gt; that we published this morning. &lt;/p&gt;

&lt;p&gt;The incredible support of the developers who rely on our courses to land new jobs and upskill themselves has humbled us. We are also thankful to our team and our investors for their continued support in expanding our mission.&lt;/p&gt;

&lt;p&gt;We founded Educative on the idea of making every developer more productive. We’d like to spend a few moments sharing our plan to use this investment to help developers. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We’re more than tripling our course offerings this year and building offerings for teams and enterprises that want to expand the skills of their employees.&lt;/li&gt;
&lt;li&gt;We recently launched our business-to-business offerings to target our enterprise customers and their needs. We have already seen traction and growth with paying customers of teams and organizations of all shapes and sizes, which validates our belief in the opportunity to grow in the enterprise space.&lt;/li&gt;
&lt;li&gt; We will continue to build the world-class courses you love -- hands-on, in-browser exercises that help you learn and develop your skills in key and emerging technologies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To facilitate this growth, we will be hiring more than 200 new employees in our Seattle headquarters and around the world.&lt;/p&gt;

&lt;p&gt;Ultimately, our promise to you is that we’ll continue to invest in ways that we think help you be more productive and more successful. That was our mission on our first day, and this round of investment will help us accelerate in that commitment.&lt;/p&gt;

&lt;p&gt;Thank you for your support, and as always…&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy learning!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Fahim and Naeem,&lt;br&gt;
Co-Founders @ Educative&lt;/p&gt;

</description>
      <category>news</category>
      <category>educative</category>
      <category>career</category>
      <category>startup</category>
    </item>
    <item>
      <title>JavaScript Tutorial: Build Tetris with modern JavaScript</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Fri, 14 May 2021 16:03:58 +0000</pubDate>
      <link>https://dev.to/educative/javascript-tutorial-build-tetris-with-modern-javascript-4dpd</link>
      <guid>https://dev.to/educative/javascript-tutorial-build-tetris-with-modern-javascript-4dpd</guid>
      <description>&lt;p&gt;Learning a new programming language is difficult and not everyone learns the same way. For many, hands-on exploration on a project or interactive tutorial is the key to lasting learning.&lt;/p&gt;

&lt;p&gt;Especially for intuitive languages like JavaScript, building projects helps to provide context for how and why to use fundamental concepts in different applications. It also helps build your resume because you can show recruiters a collection of awesome projects to demonstrate your drive and developer skills.&lt;/p&gt;

&lt;p&gt;Today, we'll help you get started on a JavaScript game development project to build Tetris. By the end of the article, you'll have all the foundational pieces you need to continue building on your own.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s what we’ll cover today:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is Tetris?&lt;/li&gt;
&lt;li&gt;Styling the game&lt;/li&gt;
&lt;li&gt;Designing the board&lt;/li&gt;
&lt;li&gt;Creating the canvas&lt;/li&gt;
&lt;li&gt;Next steps for your game&lt;/li&gt;
&lt;/ul&gt;



&lt;h4&gt;&lt;b&gt; Learn JavaScript your way, in half the time&lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;Pick up modern JavaScript skills while building a fun and fully featured project for your portfolio.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/game-development-js-tetris" rel="noopener noreferrer"&gt;Game Development with JavaScript: Creating Tetris&lt;/a&gt;&lt;/b&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Tetris?
&lt;/h2&gt;

&lt;p&gt;Tetris is a classic arcade game created in 1984 by Alexey Pajitnov. The game requires players to rotate and move falling Tetris pieces. Players clear lines by completing horizontal rows of blocks without empty cells. If the pieces reach the top, the game is over.&lt;/p&gt;

&lt;p&gt;Tetris is a popular project that lets aspiring game developers practice their skills in a simple environment. For example, you'll get hands-on practice with essential game design concepts, such as gameplay loop design, and implementing common game mechanics like user controls, score tracking, and collision detection. Unlike more complicated games, the behavior and visuals for Tetris are very simple. This lets you practice applying JavaScript basics for game development rather than figuring out animation or complex player behavior flowcharts.&lt;/p&gt;

&lt;p&gt;For this example, we'll start by using the simplest tools and build the complexity towards the end.&lt;/p&gt;

&lt;p&gt;To make Tetris, you'll need to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.educative.io/blog/html-beginners-tutorial-build-from-scratch" rel="noopener noreferrer"&gt;HTML&lt;/a&gt;/&lt;a href="https://www.educative.io/blog/beginner-guide-to-web-dev#basics" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; styling&lt;/li&gt;
&lt;li&gt;JavaScript classes, variables, and scope&lt;/li&gt;
&lt;li&gt;Arrow functions&lt;/li&gt;
&lt;li&gt;Template literals&lt;/li&gt;
&lt;li&gt;Spread vs Rest&lt;/li&gt;
&lt;li&gt;Destructuring&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Styling the game
&lt;/h2&gt;

&lt;p&gt;First, let's set up the basic UI elements: the play area, a start button, and readouts to track score, lines, and level. We'll use &lt;a href="https://www.educative.io/blog/css-flexbox" rel="noopener noreferrer"&gt;Flexbox&lt;/a&gt; and &lt;a href="https://www.educative.io/blog/complete-guide-css-positions" rel="noopener noreferrer"&gt;CSS Grid&lt;/a&gt; to position the elements correctly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- index.html --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"board"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"game-board"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"right-column"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;TETRIS&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Score: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"score"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Lines: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"lines"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Level: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"level"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"next"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"next"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"play()"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"play-button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Play&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;styles&lt;/span&gt;&lt;span class="nc"&gt;.css&lt;/span&gt;
&lt;span class="nc"&gt;.grid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;320px&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.right-column&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.game-board&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.play-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#4caf50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&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;A fundamental part of 80s games was the highly recognizable bitmap font. &lt;strong&gt;Press start 2P&lt;/strong&gt; is a free font from Google we can use to simulate the feeling. &lt;/p&gt;

&lt;p&gt;To add the font, we need to link to it in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; section of our HTML document and set it to our desired font in the CSS style sheet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt; &lt;span class="c"&gt;&amp;lt;!--index.html--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt;
  &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css?family=Press+Start+2P"&lt;/span&gt;
  &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;
&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;styles&lt;/span&gt;&lt;span class="nc"&gt;.css&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Press Start 2P'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;cursive&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;Finally, code the infrastructure of the game board using JavaScript.&lt;br&gt;
You'll need to add  &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; elements at the end of our HTML document to import our JavaScript. &lt;/p&gt;

&lt;p&gt;The bottom of your HTML document should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"constants.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"board.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"piece.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"main.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;constants.js&lt;/code&gt; will contain the code for our static play board. These values will never change regardless of player actions. The playboard will consist of 10 columns and 20 rows, with a block size of 30.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//constants.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;COLS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&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;ROWS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&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;BLOCK_SIZE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, in the &lt;code&gt;main.js&lt;/code&gt; file we'll include some code to manipulate the document &lt;code&gt;object&lt;/code&gt;, which provides a programmable interface for the HTML document. This type of document is called a &lt;strong&gt;Document Object Model (DOM)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We can use the DOM to call the &lt;code&gt;getElementByID&lt;/code&gt; to let us target specific elements and automatically scale our game to match the size of the user's browser window. This uses the &lt;code&gt;canvas&lt;/code&gt; element new with HTML5, which allows us to create and use 2D shapes with ease.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;main.js&lt;/code&gt; file should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//main.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;board&lt;/span&gt;&lt;span class="dl"&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;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Calculate size of canvas from constants.&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;COLS&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;BLOCK_SIZE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ROWS&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;BLOCK_SIZE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Scale blocks&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;BLOCK_SIZE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;BLOCK_SIZE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By the end, you'll have the following files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!--index.html--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt;
&lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css?family=Press+Start+2P"&lt;/span&gt;
&lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;
&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"board"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"game-board"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"right-column"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;TETRIS&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Score: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"score"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Lines: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"lines"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Level: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"level"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"next"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"next"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"play()"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"play-button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Play&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//main.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;board&lt;/span&gt;&lt;span class="dl"&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;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Calculate size of canvas from constants.&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;COLS&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;BLOCK_SIZE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ROWS&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;BLOCK_SIZE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Scale blocks&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;BLOCK_SIZE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;BLOCK_SIZE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//constants.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;COLS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&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;ROWS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&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;BLOCK_SIZE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;styles&lt;/span&gt;&lt;span class="nc"&gt;.css&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Press Start 2P'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;cursive&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.grid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;320px&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.right-column&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.game-board&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.play-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#4caf50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&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;&lt;a href="https://media2.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%2F28mwy40kn0u9sun64d30.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F28mwy40kn0u9sun64d30.PNG" alt="Alt Text" width="797" height="922"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h4&gt;
  
  
  Keep learning JS with hands-on projects.
&lt;/h4&gt;

&lt;p&gt;Learn in-demand JavaScript skills without the bookwork. Educative's text-based courses are easy to skim and feature hands-on project environments to help you learn your way, in half the time.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/game-development-js-tetris" rel="noopener noreferrer"&gt;Game Development with JavaScript: Creating Tetris&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Designing the board
&lt;/h2&gt;

&lt;p&gt;Now that we have created a container for our game, it’s time to start coding the logic. First, we need the board to be able to draw the falling pieces and keep track of the game state.&lt;/p&gt;

&lt;p&gt;The board and pieces are both good candidates for a class. We can create a new instance of &lt;code&gt;Board&lt;/code&gt; when starting a new game and a new instance of &lt;code&gt;Piece&lt;/code&gt; every time a new piece enters the game.&lt;/p&gt;

&lt;p&gt;For the &lt;code&gt;Board&lt;/code&gt; class, we'll make a new &lt;code&gt;board.js&lt;/code&gt; file. We want the board to reference the canvas every time the game starts so we'll include &lt;code&gt;ctx&lt;/code&gt; in the &lt;code&gt;Board&lt;/code&gt; constructor. We'll also include the &lt;code&gt;this&lt;/code&gt; keyword to let us set and access properties within &lt;code&gt;ctx&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//board.js&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Board&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&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;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ctx&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tetris boards consist of many individual cells that are either empty or occupied. We'll represent empty cells with &lt;code&gt;0&lt;/code&gt; and occupied cells with integers of &lt;code&gt;1-7&lt;/code&gt; to represent colors.&lt;/p&gt;

&lt;p&gt;To represent the rows and columns of the board, we'll use a 2D array (a matrix). We'll have arrays of integers to represent a row and an array of rows to represent the full board. &lt;/p&gt;

&lt;p&gt;Since all games start with an empty board, we'll need a method that returns an empty board. We can use the built-in &lt;code&gt;fill()&lt;/code&gt; array method to populate all elements of each row to &lt;code&gt;0&lt;/code&gt;. The constructor will call this method so all games start empty.&lt;/p&gt;

&lt;p&gt;Our &lt;code&gt;board.js&lt;/code&gt; file will now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//board.js&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Board&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&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;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ctx&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;grid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getEmptyBoard&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;getEmptyBoard&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ROWS&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;COLS&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we'll go back to &lt;code&gt;main.js&lt;/code&gt; to add this new game functionality to the play button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;play&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;board&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Board&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&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="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;board&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;grid&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;Now our game board is set up! You can use &lt;code&gt;console.table()&lt;/code&gt; to see the matrix that controls the board. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5tr94v1negl9x0va4st1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5tr94v1negl9x0va4st1.PNG" alt="Alt Text" width="800" height="512"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the canvas
&lt;/h2&gt;

&lt;p&gt;Now we'll make sure our &lt;code&gt;canvas&lt;/code&gt; element is ready to use. The canvas provides a blank canvas for our game to sit on. &lt;/p&gt;

&lt;p&gt;We can also add a 2D drawing context over the canvas for drawing shapes, text, images, and other objects. It works similarly to programs like MS Paint in that you can choose your brush type and color then draw using code. &lt;/p&gt;

&lt;p&gt;First, we want to make sure the canvas is the right size. It is 300x150 pixels by default but we want it to scale using the code we added above.&lt;/p&gt;

&lt;p&gt;To do so, we add a &lt;code&gt;canvas&lt;/code&gt; element to our &lt;code&gt;index.html&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"canvas"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add a reference to the HTML &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; element element in the DOM (Document Object Model) using the &lt;code&gt;getElementById&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;canvas&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we'll use the canvas context to render some pieces. &lt;/p&gt;

&lt;p&gt;We can use the &lt;code&gt;HTMLCanvasElement.getContext()&lt;/code&gt; method to get the canvas context where we render the graphics. This method needs an argument so we'll pass &lt;code&gt;'2d'&lt;/code&gt; to get the 2D render context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we can draw we have to choose a color using the &lt;code&gt;fillStyle()&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fillStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can then use the &lt;code&gt;fillRect()&lt;/code&gt; method from the context API to draw a simple rectangle filled with our chosen red color. &lt;code&gt;fillRect()&lt;/code&gt; takes 4 arguments: the x and y coordinates where the shape should start and the width/height of the rectangle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since all Tetris pieces are collections of squares, we can use this single draw method for all of our pieces!&lt;/p&gt;



&lt;h3&gt;
  
  
  Animations
&lt;/h3&gt;

&lt;p&gt;Now that we have the tools to draw our graphics, we have to be able to move them.&lt;/p&gt;

&lt;p&gt;Canvas uses &lt;strong&gt;immediate rendering&lt;/strong&gt;: Drawn shapes are immediately rendered on the screen, but are not stored as shape objects. Instead, canvas only recognizes the shape as filled pixels, meaning we cannot move the shape in one piece. &lt;/p&gt;

&lt;p&gt;To show a moving shape, we have to delete the old shape using &lt;code&gt;clearRect()&lt;/code&gt;  and redraw it in a new position using &lt;code&gt;fillRect()&lt;/code&gt;. Canvas animations are essentially like stop motion animation because they move a little bit in each frame. &lt;/p&gt;

&lt;p&gt;Take a look at this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&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;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fillStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clearRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we select blue as our color then fill a rectangle at point &lt;code&gt;0,0&lt;/code&gt;. Then we clear the whole canvas using &lt;code&gt;clearRect()&lt;/code&gt; and passing the width and height of the whole canvas. Finally, we draw a new rectangle of the same size and color at &lt;code&gt;1,1&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;From the user's perspective, the rectangle moved down and to the right on the screen.&lt;/p&gt;

&lt;p&gt;Now that you've got your canvas and drawing tools set up, you've got all the tools you need to start coding gameplay and a collection of game pieces!&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Next steps for your game
&lt;/h2&gt;

&lt;p&gt;This is a great start to your next portfolio project. Now that you've built the foundation of the game, your next step is to create objects that draw each unique Tetris game piece in its own color. &lt;/p&gt;

&lt;p&gt;Each piece type will be represented by a 3x3 matrix where the piece is the filled cells and the surrounding empty space helps to rotate around the central cell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2, 0, 0],  
[2, 2, 2],  
[0, 0, 0];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The best way to do this is with a &lt;code&gt;Piece&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;You'll also have to add keyboard support so the user can control the pieces. The best way to do this is to use keyboard event support built-in to modern browsers. You can set the program to listen for keyboard events like &lt;code&gt;keydown&lt;/code&gt;, &lt;code&gt;keyup&lt;/code&gt;, and so on at the document level using the &lt;code&gt;addEventListener()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;After these steps, you'll move onto adding more advanced features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add collision detection and piece randomizer&lt;/li&gt;
&lt;li&gt;Add line clearing if a row is filled&lt;/li&gt;
&lt;li&gt;Track score, level, and past high scores&lt;/li&gt;
&lt;li&gt;Increase responsiveness with asynchronous JavaScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To help complete this project and learn JavaScript with hands-on experience, Educative has created the course &lt;a href="https://www.educative.io/courses/game-development-js-tetris" rel="noopener noreferrer"&gt;&lt;strong&gt;Game Development with JavaScript: Creating Tetris&lt;/strong&gt;&lt;/a&gt;. This course helps you pick up foundational skills in JavaScript and game development at the same time by building a fun browser game. By the end of the course, you'll have a fully-featured Tetris web game and will have gained experience with JavaScript skills from beginner to advanced.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy learning!&lt;/em&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  Continue reading about JavaScript
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/javascript-snake-game-tutorial" rel="noopener noreferrer"&gt;JavaScript Snake Game Tutorial: build a simple, interactive game&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.educative.io/blog/level-up-javascript-coding-challenges" rel="noopener noreferrer"&gt;Level up your JavaScript skills with 10 coding challenges&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.educative.io/blog/javascript-es6-tutorial-a-complete-crash-course" rel="noopener noreferrer"&gt;JavaScript ES6 Tutorial: A complete crash course on modern JS&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>gamedev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Bytesize: 3 Future Uses of Blockchain</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Mon, 10 May 2021 22:35:40 +0000</pubDate>
      <link>https://dev.to/educative/bytesize-3-future-uses-of-blockchain-52a</link>
      <guid>https://dev.to/educative/bytesize-3-future-uses-of-blockchain-52a</guid>
      <description>&lt;p&gt;Bytesize is our 5-minute infusion of developer history, speculation, or otherwise fun knowledge that you can enjoy during a work or study break. &lt;/p&gt;

&lt;p&gt;When you set off to become a developer, you probably dreamed of working on self-driving cars, artificial intelligence, world-changing apps, or any number of other amazing products. However, there's a lot of learning and beginner developer work you need to do before you can get there. This can be draining and can make you lose sight of what got you excited to be a developer in the first place.&lt;/p&gt;

&lt;p&gt;When knee-deep in a tough concept or a product function that's fighting back, Bytesize is here every week to give you 5-minutes to shake it off and let your imagination fly once more.&lt;/p&gt;



&lt;h4&gt;&lt;b&gt; Never miss Educative content again &lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;Sign up for our free, bi-monthly newsletter to receive the latest in tech news and trends, right in your inbox.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; &lt;a href="https://www.educative.io/blog/blog-newsletter-annoucement" rel="noopener noreferrer"&gt;Learn more about our Newsletter&lt;br&gt;
&lt;/a&gt; &lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a href="https://media2.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%2Fb03rgs17r0c0o2zwt8dq.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fb03rgs17r0c0o2zwt8dq.PNG" alt="Alt Text" width="800" height="263"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  International Commerce:
&lt;/h2&gt;

&lt;p&gt;The most common use of Blockchain right now is cryptocurrencies like Bitcoin or Etherum. While most people know crypto's use in investing, it could also revolutionize international banking.&lt;/p&gt;

&lt;p&gt;Currency conversions now take a long time and come with huge fees, sometimes around 20% of the transfer. That's because currency conversion isn't direct. Your bank must contact a bank in the target country and work to set up a transaction. Both of these banks need to pay their workers for the time, the third party used to authenticate their connection, and charge extra to make the transaction worthwhile for the company. This sluggish and lengthy process inhibits international trade and your options as a consumer.&lt;/p&gt;

&lt;p&gt;Blockchain has economists excited because cryptocurrencies offer an intermediate and decentralized currency. &lt;/p&gt;

&lt;p&gt;For example, say I want to convert from American Dollar to Japanese Yen. On my end, I can just press a button. Behind the scenes, my Dollar is used to buy a portion of a Bitcoin equal to the value then immediately resold for Yen.&lt;/p&gt;

&lt;p&gt;Without the need for one or more middle parties, we can avoid high fees and the time it takes to connect to the decentralized server. The decentralized and secure ledger of cryptocurrencies could even allow companies to make large deals without the need for an authenticating bank. This concept has international business experts excited, with 90% of the European Payments Council they expect it to fundamentally change banking by 2025. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F1yj9etljerwxbdyzqw7r.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F1yj9etljerwxbdyzqw7r.PNG" alt="Alt Text" width="674" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Online Voting
&lt;/h2&gt;

&lt;p&gt;Democratic voting has been around for a long time, since the days of the Ancient Greeks. Unfortunately, the voting process hasn't seen much change since then. Much like the voting stones in Athens, most democratic nations still ask citizens to vote in person by placing their ballot in the box of their candidate. Ballot as a word reflects this stagnation as it developed from the Italian &lt;em&gt;balla&lt;/em&gt;, meaning a colored ball used as a voting token in the 1500s.&lt;/p&gt;

&lt;p&gt;The main problem of this system is that it assumes all voters can reach a ballot box and leads to long lines at voting locations. This centralized system makes it harder to vote, especially for those who can't take time off work to vote or cannot afford transportation.&lt;/p&gt;

&lt;p&gt;Right now the best alternative to in-person voting is vote-by-mail systems with various layers of authentication. These systems are very secure and do not cause voter fraud. The problem they have is that the authentication process is costly and sometimes invalidates valid votes that have slight errors in formatting or signature matching. While it's the best solution we have right now, it still creates a barrier between the voter and the voting system.&lt;/p&gt;

&lt;p&gt;That's why some experts are excited about Blockchain to enable online voting. The idea is to distribute a unique voting "coin" to all registered voters. Then, each voter adds their coin to an immutable blockchain associated with their preferred candidate. &lt;/p&gt;

&lt;p&gt;Blockchain's encrypted, decentralized nature makes these votes hard to hack and manipulate, which is the main obstacle against online voting. Since there is no central administrator that can access the full ledger, the identity of the voter is secure. Further, the unique coins allow the system to easily track every interaction and verify each coin as it's entered into the system. &lt;/p&gt;

&lt;p&gt;Blockchain does not require physical pickup by election officials and does not need to be authenticated by hand, which has been projected to lower the cost-per-vote to just $0.50.&lt;/p&gt;

&lt;p&gt;In short, the system can verify votes but no central power can link them back to voters.&lt;/p&gt;

&lt;p&gt;While still too early to implement at scale, Blockchain technology appears to be our current best option to enable online voting and further increase the availability of electoral engagement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F7rom9a65zd3b6mxtomua.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7rom9a65zd3b6mxtomua.PNG" alt="Alt Text" width="691" height="693"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Swarm Robotics
&lt;/h2&gt;

&lt;p&gt;Swarm Robotics is a form of AI that allows a group of robots to make decisions without a centralized director. Essentially, the swarm of robots uses a distributed peer-to-peer hive mind that allows the group itself to act as a decision-making device. This allows the group to make decisions, chart paths, and correct for obstacles faster than if it had to relay with an outside server. While long discussed in computer science academia, it's now being considered for application in drone-based delivery services.&lt;/p&gt;

&lt;p&gt;Blockchain is showing initial promise as a key to bringing this theory to life. It's naturally suited to peer-to-peer relationships and has proved the most reactive option to unexpected stimuli in recent MIT tests of the ARGoS Etherium-based system. Blockchain also includes built-in cryptographic security systems, which address the fear of hacking the hive-mind.&lt;/p&gt;

&lt;p&gt;This application of Blockchain is only just beginning to show promise, but its success will have staggering effects on our commercial transportation. &lt;/p&gt;

&lt;p&gt;The technology is currently under open-source development. You can contribute on Github under the name "ARGoS-Blockchain interface"!&lt;/p&gt;



&lt;h2&gt;
  
  
  Continue reading about these technologies
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/how-to-become-a-blockchain-developer-a-complete-guide" rel="noopener noreferrer"&gt;How to Become a Blockchain Developer: A Complete Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/distributed-systems-considerations-tradeoffs" rel="noopener noreferrer"&gt;What are Distributed Systems? A quick introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/kerberos-in-5-minutes" rel="noopener noreferrer"&gt;Kerberos in 5 Minutes: Introducing network authentication&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>blockchain</category>
      <category>watercooler</category>
      <category>todayilearned</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Advanced YAML Syntax Cheatsheet</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Thu, 06 May 2021 22:21:58 +0000</pubDate>
      <link>https://dev.to/educative/advanced-yaml-syntax-cheatsheet-59ij</link>
      <guid>https://dev.to/educative/advanced-yaml-syntax-cheatsheet-59ij</guid>
      <description>&lt;p&gt;YAML (YAML Ain’t Markup Language) is a data serialization language used to create key-value pair configuration files and app APIs. It's a superset of JSON and is formatted using line breaks and whitespace to improve readability. &lt;/p&gt;

&lt;p&gt;While not a daily use technology, it's an important foundation for many modern technologies like &lt;a href="https://www.educative.io/blog/ansible-for-beginners" rel="noopener noreferrer"&gt;Ansible&lt;/a&gt; and is, therefore, a prerequisite for higher-paying developer roles. &lt;/p&gt;

&lt;p&gt;Today, we'll help you perfect your YAML knowledge so you can impress your next interviewer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s what we’ll cover today:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validator and Parser&lt;/li&gt;
&lt;li&gt;Anchors and Alias&lt;/li&gt;
&lt;li&gt;Schemas&lt;/li&gt;
&lt;li&gt;Escape Sequences&lt;/li&gt;
&lt;li&gt;Separators and Directives&lt;/li&gt;
&lt;li&gt;Wrapping up&lt;/li&gt;
&lt;/ul&gt;



&lt;h4&gt;&lt;b&gt; Become a certified YAML professional &lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;Stand out from other applicants with a YAML certification that you can earn in less than an hour.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/introduction-to-yaml" rel="noopener noreferrer"&gt;Introduction to YAML&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  YAML Validator and Parser
&lt;/h2&gt;

&lt;p&gt;While YAML is more readable than XML, it's easy to miss mistakes in formattings like the number of spaces across a multi-line section or forgetting &lt;a href="https://www.educative.io/blog/yaml-tutorial" rel="noopener noreferrer"&gt;newline markers&lt;/a&gt;. These can cause sweeping errors for the YAML parser, which interprets YAML into more machine-readable actions.&lt;/p&gt;

&lt;p&gt;Parsing errors are hard to find by hand, so many developers choose to use a web validator or linter. These tools review your YAML document and highlight any potential errors to ensure you have valid YAML before putting it into use.&lt;/p&gt;

&lt;p&gt;The most popular validator is YAMLLint, a free &lt;a href="https://www.educative.io/blog/contribue-open-source-python-project" rel="noopener noreferrer"&gt;open-source&lt;/a&gt; tool available in your browser or on &lt;a href="https://www.educative.io/blog/git-github-tutorial-beginners" rel="noopener noreferrer"&gt;Github&lt;/a&gt;. YAMLLint is considered the most convenient linter because it provides error highlighting, autoformatting for copy/pasted YAML, and auto-correct options.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  YAML Anchors and Alias
&lt;/h2&gt;

&lt;p&gt;Anchors and Aliases are YAML constructions that allow you to reduce repeat syntax and extend existing data nodes. You can place Anchors (&lt;code&gt;&amp;amp;&lt;/code&gt;) on an entity to mark a multi-line section.  You can then use an Alias (&lt;code&gt;*&lt;/code&gt;) call that anchor later in the document to reference that section. Anchors and Aliases are very helpful for larger projects as they cut visual clutter caused by extra lines.&lt;/p&gt;

&lt;p&gt;The Alias essentially acts as a "see above'' command, which makes the program pause standard traversal, return to the anchor point, then resume standard traversal after the Anchored portion is finished. If you're familiar with Object-Oriented Programming designs, you'll feel right at home with Anchors.&lt;/p&gt;

&lt;p&gt;Below, the &lt;code&gt;build-test&lt;/code&gt; Anchor begins on &lt;strong&gt;line 3&lt;/strong&gt; and is called by Aliases on &lt;strong&gt;lines 13 and 15&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;definitions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;step&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nl"&gt;&amp;amp;build-test&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build and test&lt;/span&gt;
        &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;mvn package&lt;/span&gt;
        &lt;span class="na"&gt;artifacts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;target/**&lt;/span&gt;

&lt;span class="na"&gt;pipelines&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;develop&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;step&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;*build-test&lt;/span&gt;
    &lt;span class="na"&gt;master&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;step&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;*build-test&lt;/span&gt;

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

&lt;/div&gt;





&lt;h3&gt;
  
  
  Overrides and Extensions
&lt;/h3&gt;

&lt;p&gt;You can also tweak the Anchor when called by entering &lt;code&gt;&amp;lt;&amp;lt;:&lt;/code&gt; before the Alias. Below this, you can write any desired changes. Mappings are overridden if the new mapping has the same name or is added afterward if different.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;definitions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;step&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nl"&gt;&amp;amp;build-test&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build and test&lt;/span&gt;
        &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;mvn package&lt;/span&gt;
        &lt;span class="na"&gt;artifacts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;target/**&lt;/span&gt;


&lt;span class="na"&gt;pipelines&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;develop&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;step&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;*build-test&lt;/span&gt;
    &lt;span class="na"&gt;master&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;step&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
          &lt;span class="na"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;*build-test&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Testing on Master&lt;/span&gt; &lt;span class="c1"&gt;#override&lt;/span&gt;
          &lt;span class="na"&gt;ongoing&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;#extension&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  YAML Schemas
&lt;/h2&gt;

&lt;p&gt;Schemas are rulesets in YAML 1.2 that tell the loader/parser what each part of your YAML file converts to in actual commands. They're essentially a collection of if/then statements to process human-readable YAML tags into. For example, the YAML Core schema states that both &lt;code&gt;!!str my string&lt;/code&gt; and &lt;code&gt;my string&lt;/code&gt; are equivalent and should be parsed to the same action.&lt;/p&gt;

&lt;p&gt;There is a default schema for general-purpose YAML, and many special-use schemas that are each suited for certain niche scenarios. You can even create your own custom schemas or download other user's schemas on the JSON Schema Store.&lt;/p&gt;

&lt;p&gt;Custom schemas are helpful when configuration files include custom objects or if you want to create language-specific object serialization&lt;br&gt;
s.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="c1"&gt;# Ruby Psych&lt;/span&gt;
&lt;span class="na"&gt;dice&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!ruby/Object:Dice&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;3&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;6&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;

&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="c1"&gt;# perl YAML::XS, YAML.pm, YAML::Syck (Dump and Load)&lt;/span&gt;
&lt;span class="na"&gt;dice&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!!perl/array:Dice&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;3&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;6&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;

&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="c1"&gt;# perl YAML.pm, YAML::Syck (Load)&lt;/span&gt;
&lt;span class="na"&gt;dice&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!perl/array:Dice&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;3&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;6&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;

&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="c1"&gt;# Pyyaml&lt;/span&gt;
&lt;span class="na"&gt;dice&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!!python/object/new:__main__.Dice&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!!python/tuple&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;3&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;6&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are three default schemas for YAML are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Failsafe Schema&lt;/strong&gt;: A minimalist schema that only supports String (&lt;code&gt;!!str&lt;/code&gt;), Map (&lt;code&gt;!!map&lt;/code&gt;), and Sequence (&lt;code&gt;!!seq&lt;/code&gt;) tags. Failsafe is guaranteed to work with any YAML document due to its simplicity, but it does not support any complex tags.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JSON schema&lt;/strong&gt;: A foundational schema designed to reliably parse equivalent YAML and JSON files to the same end result. This is the most commonly used schema and is the starting point for most schemas. It supports all failsafe tags, as well as Boolean (&lt;code&gt;!!bool&lt;/code&gt;), null (&lt;code&gt;!!null&lt;/code&gt;), Integer (&lt;code&gt;!!int&lt;/code&gt;), and Float (&lt;code&gt;!!float&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Core Schema&lt;/strong&gt;: The default YAML schema that widens the matching criteria on the YAML side. It is essentially a less opinionated version of the JSON schema. For example, JSON accepts Booleans that achieve the criteria "Match: &lt;code&gt;true&lt;/code&gt; | &lt;code&gt;false&lt;/code&gt;". By comparison, here is Core's Boolean criteria: "&lt;code&gt;true&lt;/code&gt; | &lt;code&gt;True&lt;/code&gt; | &lt;code&gt;TRUE&lt;/code&gt; | &lt;code&gt;false&lt;/code&gt; | &lt;code&gt;False&lt;/code&gt; | &lt;code&gt;FALSE&lt;/code&gt;". &lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  Keep the learning going.
&lt;/h4&gt;

&lt;p&gt;Brush up on your expert YAML skills and earn a certificate at the same time. Educative's text-based courses are easy to skim and feature live coding environments, meaning you can better your skills in half the time. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/introduction-to-yaml" rel="noopener noreferrer"&gt;Introduction to YAML&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  YAML Escape Sequences
&lt;/h2&gt;

&lt;p&gt;YAML's readable syntax is only possible because it uses indents and whitespace over inline syntactic markers like square brackets or curly braces. However, this can get difficult when using special characters with quotation mark scalars.&lt;/p&gt;

&lt;p&gt;YAML offers Escape Sequences to allow you to indicate if the character should be interpreted as a special character or as part of the scalar. For example, you could escape a single space using &lt;code&gt;&amp;amp;#x20;&lt;/code&gt; to create a string with a value of &lt;code&gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Escape Sequences come in 3 types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Entity Escapes&lt;/strong&gt;, which allow you to use otherwise syntactically important characters by space (&lt;code&gt;&amp;amp;#x20;&lt;/code&gt;), colon (&lt;code&gt;&amp;amp;#58;&lt;/code&gt;), ampersand (&lt;code&gt;&amp;amp;amp;&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unicode Escapes&lt;/strong&gt;, which let you add a space (&lt;code&gt;\u0020&lt;/code&gt;), single quote (&lt;code&gt;\u0027&lt;/code&gt;), or double quote (&lt;code&gt;\u0022&lt;/code&gt;) by calling their unique key directly from the Unicode key-value pairs list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quoted Escapes&lt;/strong&gt;, which let you display quoted sentences using additional quotes. For example, double quotes can be shown within single quotes (‘ "quote" ’) or nested within another set of double quotes ("abc "quote" cba") and with nested single quotes (‘ ‘quote’ ’).&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; A full list of YAML Escape Sequences can be found in the official YAML Specification.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  YAML Separators and Directives
&lt;/h2&gt;

&lt;p&gt;You may have noticed that all YAML documents begin with &lt;code&gt;---&lt;/code&gt;. This notifies the parser that this data is a separate chunk but was sent as part of the same request for efficiency.&lt;/p&gt;

&lt;p&gt;Another more advanced separator is &lt;code&gt;...&lt;/code&gt;, which marks the end of a document. The end-of-document separator must be followed either by a beginning-of-document separator (&lt;code&gt;---&lt;/code&gt;) or a set of directives. Directives are defined settings marked by &lt;code&gt;%&lt;/code&gt; that comes before a document and are followed by &lt;code&gt;---&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This means &lt;code&gt;...&lt;/code&gt; and &lt;code&gt;---&lt;/code&gt; are needed to mark the boundaries of the directive space. The two current directives are &lt;code&gt;%YAML&lt;/code&gt;, which lets you set the YAML version for the coming document, and &lt;code&gt;%TAGS&lt;/code&gt;, which lets you create custom shorthands for tags you'll use in the document.&lt;/p&gt;

&lt;p&gt;Directives are only useful in niche circumstances, like using an old YAML document that's too large to update. Usually, you will not need directives or a document separator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;doc 1&lt;/span&gt; 
&lt;span class="nn"&gt;...&lt;/span&gt; 

&lt;span class="nt"&gt;%TAG&lt;/span&gt; &lt;span class="kt"&gt;!foo!&lt;/span&gt; &lt;span class="kt"&gt;!&lt;/span&gt;&lt;span class="err"&gt;foo-types/&lt;/span&gt; 

&lt;span class="nn"&gt;---&lt;/span&gt; 

&lt;span class="s"&gt;doc &lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  YAML Timestamp
&lt;/h2&gt;

&lt;p&gt;Timestamp is a helpful data type that lets you store times as a unit rather than as a collection of different numbers. It's marked by the &lt;code&gt;!!timestamp&lt;/code&gt; data tag and can hold various levels of specificity such as simple &lt;code&gt;yyyy/mm/dd&lt;/code&gt; or down to a fraction of a second &lt;code&gt;2001-12-15T2:59:43.10&lt;/code&gt;. &lt;br&gt;
You can also separate date and time using spaces to make the timestamp more readable, like &lt;code&gt;2001-12-15 2:59:43.10&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;All timestamps are recorded as Coordinated Universal Time (UTC) unless another timezone is specified at the end of the timestamps. You define the timezone by including how many hours it is ahead or behind UTC. &lt;/p&gt;

&lt;p&gt;For example, I could set a timestamp as Pacific Standard Time (PST) with a &lt;code&gt;-8&lt;/code&gt; at the end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2001-12-15 2:59:43.10 -8`. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is similar to DateTime used in popular programming languages like JavaScript or Python, except with how it handles timezone. DateTime records the time listed in the timezone of the host server by default. &lt;/p&gt;

&lt;p&gt;This can lead to problems if working with networks from outside their native timezone. The computer needs to convert to UTC then to the destination timezone every time the date is called, slowing down processes.&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;Good job tackling this advanced YAML syntax. While YAML might seem like a niche skill, it's a prerequisite for many jobs across the market. However, most coding interviews will not include YAML. The best way to demonstrate your YAML knowledge is to use it in a portfolio project or be able to show past experience with the technology.&lt;/p&gt;

&lt;p&gt;To help you wow recruiters with your YAML skills, Educative has created &lt;a href="https://www.educative.io/courses/introduction-to-yaml" rel="noopener noreferrer"&gt;&lt;strong&gt;Introduction to YAML&lt;/strong&gt;&lt;/a&gt;. This course covers beginner to expert level syntax and techniques in a condensed, hands-on format. By the end of the course, you'll be able to use YAML with confidence and will have your own YAML certification to put on your resume.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy learning!&lt;/em&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  Continue reading about YAML and foundational skills
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/yaml-tutorial" rel="noopener noreferrer"&gt;YAML Tutorial: get started with YAML in 5 minutes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/data-structures-algorithms" rel="noopener noreferrer"&gt;Top Data Structures and Algorithms every developer must know&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/big-o-notation-cheat-sheet" rel="noopener noreferrer"&gt;Big-O Notation Cheat Sheet: quick answers to Big-O questions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>yaml</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Spring Framework Tutorial: Getting Started with Spring</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Wed, 05 May 2021 23:00:51 +0000</pubDate>
      <link>https://dev.to/educative/spring-framework-tutorial-getting-started-with-spring-gib</link>
      <guid>https://dev.to/educative/spring-framework-tutorial-getting-started-with-spring-gib</guid>
      <description>&lt;p&gt;While often overlooked as old-fashioned, the Spring Framework is still a popular application development tool desired by enterprise companies across the globe. Spring offers unparalleled control, top-notch security, and a time-saving dependency system using Spring Beans. &lt;/p&gt;

&lt;p&gt;However, Spring is also notoriously difficult to learn due to its number of options and complex toolset.&lt;/p&gt;

&lt;p&gt;Today, we'll help you start your Spring development journey with a beginner tutorial on how and why to use Spring. In the end, we'll even get you started on your first Spring portfolio project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s what we’ll cover today:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is the Spring Framework?&lt;/li&gt;
&lt;li&gt;Salient features of Spring&lt;/li&gt;
&lt;li&gt;Spring Architecture and Components&lt;/li&gt;
&lt;li&gt;Get started with Spring&lt;/li&gt;
&lt;li&gt;Advanced Spring concepts to learn next&lt;/li&gt;
&lt;/ul&gt;



&lt;h4&gt;&lt;b&gt; Learn Spring in half the time &lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;Learn professional-level Spring techniques quickly with hands-on lessons.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/guide-spring-5-spring-boot-2" rel="noopener noreferrer"&gt;The Complete Guide to Spring 5 and Spring Boot 2&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Spring Framework?
&lt;/h2&gt;

&lt;p&gt;Spring is a lightweight, open-source application development framework that uses Java Enterprise Edition (Java EE) and Enterprise JavaBeans model (EJB). &lt;/p&gt;

&lt;p&gt;Spring is often thought of as a "framework of frameworks" because it supports other integrated frameworks in the Java ecosystem like Struts, Hibernate, and Tapestry. Spring comes in many variants that are tailored to particular uses such as Spring MVC, Spring Boot, or Spring Security.&lt;/p&gt;

&lt;p&gt;Spring is known for its dependency injection and Inversion of Control (IoC) systems, which allow you to create large-scale, loosely-coupled applications with ease. Spring is especially suited for financial and enterprise applications due to its speed, security, and easy-to-build transaction systems. The top employers of Spring developers are Citibank, eBay, Visa, and J.P. Morgan.&lt;/p&gt;

&lt;p&gt;Overall, Spring Framework allows you to create enterprise-scale applications that are secure and can automatically handle low-level functionalities like maintaining container lifecycles and managing dependencies. &lt;/p&gt;



&lt;h3&gt;
  
  
  Advantages of Spring
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Plain Old Java Object (POJO)&lt;/strong&gt;: Spring applications just use normal Java objects rather than servers or enterprise containers. This makes applications more lightweight.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Modularity&lt;/strong&gt; IoC and &lt;a href="https://www.educative.io/blog/mvc-tutorial" rel="noopener noreferrer"&gt;MVC&lt;/a&gt; allows you to reuse components across your application without manually managing the dependencies of each&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strong support for Java ecosystem&lt;/strong&gt;: Spring makes innovative uses of pre-existing technologies, such as ORM frameworks, JEE, and JDK timers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalable transactions&lt;/strong&gt;: Spring offers a consistent, scalable transaction management interface for both local transactions and global transactions. This includes caching protocols.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secure&lt;/strong&gt;: Easy to implement security modules with &lt;a href="https://www.educative.io/blog/kerberos-in-5-minutes" rel="noopener noreferrer"&gt;authentication&lt;/a&gt; and validation features.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible Configs&lt;/strong&gt;: Can opt to use Java-based annotations or XML configuration
​

&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages of Spring
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complexity&lt;/strong&gt;: Spring Framework opts for increased control and complexity over ease of use. Spring is therefore harder to pick up than other web frameworks. While very powerful, Spring is best suited for experienced developers that can handle its steep learning curve.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallel Mechanisms&lt;/strong&gt;: Spring's wide range of options means a single task can be accomplished in several ways. You'll need intricate knowledge of your available tools to choose the ideal solution and avoid cross-team confusion.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lacking robust documentation&lt;/strong&gt;: Spring's documentation is missing clear guidelines on a number of topics, especially around cybersecurity techniques. It's up to users to deal with common attacks like cross-site forgery and scripting attacks.
&amp;gt; Many of these disadvantages were addressed by the invention of the Spring Boot module, which is highly opinionated and designed for &lt;a href="https://www.educative.io/blog/microservices-architecture-tutorial-all-you-need-to-get-started" rel="noopener noreferrer"&gt;microservice architectures&lt;/a&gt;. 
&amp;gt;
&amp;gt; Most modern Spring applications are built on Boot but there are many older applications still maintained by long-standing companies. &lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Features of Spring
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inversion of Control (IoC)&lt;/strong&gt;: Shifts responsibility for dependencies from objects to the framework itself. Without IoC, each object must handle its own instance of the dependency. With IoC, the object simply lists that it needs a certain dependency and the framework configures and manages it automatically. This simplifies the app development process by consolidating the dependency system and reducing the workload on individual classes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Aspect-Oriented Programming&lt;/strong&gt;: Spring AOP allows you to have different class loaders to increase modularity and separate cross-cutting concerns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Injection&lt;/strong&gt;: The process Spring uses to automatically manage the dependencies of beans. Spring checks which beans are required for a particular bean to function and injects them as a dependency. Spring can perform dependency injection by using a constructor or by using a setter method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Container Lifecycle Management&lt;/strong&gt;: Automatically creates, manages, and configures application objects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MVC support&lt;/strong&gt;: Supports the MVC web architecture that separates functionalities between model, view, and controller layers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling&lt;/strong&gt;: Includes JDBC exception handling with an exception hierarchy system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Spring Architecture and Components
&lt;/h2&gt;

&lt;p&gt;Let's break down the fundamental pieces of a Spring Framework application to help you see the big picture.&lt;/p&gt;



&lt;h3&gt;
  
  
  Beans
&lt;/h3&gt;

&lt;p&gt;Spring Beans are instances of classes that are managed by Spring. They are the most fundamental component of a Spring program. &lt;/p&gt;

&lt;p&gt;Traditionally, objects would create personal instances of their dependencies. Spring manages all the dependencies of an object and instantiates the object into a bean after injecting the required dependencies. The &lt;code&gt;@Component&lt;/code&gt; annotation is the most common method of defining beans.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Component&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Beans have a set lifecycle and visibility based on their scope. There are six types of scopes: singleton, prototype, request, session, application, and websocket. The singleton and prototype scopes can be used in any application while the last four scopes are only available for a web application.&lt;/p&gt;

&lt;p&gt;The default scope of a bean is singleton, in which only one instance of the bean is created and cached in memory. Multiple requests for the bean return a shared reference to the same bean. In contrast, prototype scope results in the creation of new beans whenever a request for the bean is made to the application context.&lt;/p&gt;



&lt;h3&gt;
  
  
  Autowiring
&lt;/h3&gt;

&lt;p&gt;Spring's method of injecting beans into one and another. Spring identifies a selected bean's dependency, looks for a match, and then populates the dependency. The &lt;code&gt;@Autowired&lt;/code&gt; annotation tells Spring to find and inject a collaborating bean into another. If more than one bean of the same type is available, Spring throws an error. &lt;/p&gt;

&lt;p&gt;In the following scenario, two beans of type Operator are detected by Spring:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Component&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nf"&gt;Arithmetic&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="nd"&gt;@Autowired&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Operator&lt;/span&gt; &lt;span class="n"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;//...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@Component&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Addition&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Operator&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@Component&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Subtraction&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Operator&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h3&gt;
  
  
  IoC Container
&lt;/h3&gt;

&lt;p&gt;An IoC container is a framework that provides the Inversion of Control functionality. The IoC container manages the beans and creates any instances required.&lt;/p&gt;

&lt;p&gt;For example, say we have the class &lt;code&gt;Vehicle&lt;/code&gt; that depends on another class, &lt;code&gt;Engine&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Engine&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;//...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With IoC, the programmer only needs to mention the dependency and Spring will do the rest. The IoC container will create instances of both classes and inject &lt;code&gt;Engine&lt;/code&gt; into &lt;code&gt;Vehicle&lt;/code&gt; as a dependency.&lt;/p&gt;



&lt;h3&gt;
  
  
  Spring Modules and Spring Projects
&lt;/h3&gt;

&lt;p&gt;Modules are collections of tools grouped by their intended function. Developers can specify which modules beyond the basic set they'd like to import as dependencies for any given application.&lt;/p&gt;

&lt;p&gt;Modules are organized in groups called Projects. Each Project contains modules that are specialized for working in a specific platform or application type. The project and module systems help to keep your program lightweight as you can choose to load only the tools used in the application.&lt;/p&gt;

&lt;p&gt;The modules of the basic Spring Project architecture are shown below grouped together by their layer:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fzi7n68fgrbjhwxlcqc1c.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fzi7n68fgrbjhwxlcqc1c.PNG" alt="Alt Text" width="690" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Spring Core Container includes the 4 modules essential to use Spring: Beans, Core, Context, and Spring Expression Language (SpEL). These modules are responsible for the fundamental functionality of the Spring framework, like Inversion of Control (IoC), dependency injection, internationalization as well as support for querying the object at run time.&lt;/p&gt;

&lt;p&gt;The Spring Data access/integration layer provides support for interacting with databases and &lt;a href="https://www.educative.io/blog/java-agile-development" rel="noopener noreferrer"&gt;managing data&lt;/a&gt;. It has 4 main pieces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Java Database Connectivity (JDBC)&lt;/strong&gt; module, which allows the data layer to get, store, or interface with other systems without needing to write cumbersome standalone JDBC code.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Object Relational Mapping&lt;/strong&gt; (ORM) module, which allows your Spring web application to interface with ORM frameworks.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Java Messaging Service&lt;/strong&gt; (JMS) module, which allows Spring to produce messages of its own and consume messages from other systems. This is essential for reactive apps.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Object-XML Mapping&lt;/strong&gt; (OXM) module, which provides useful features to make object-to-XML file transformation easy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Web layer contains the Web, Servlets, Portlets, and Sockets modules used to create web applications.&lt;/p&gt;

&lt;p&gt;The Test module addresses the cross-cutting concern of unit testing. The Spring Test framework supports testing with JUnit, TestNG, as well as creating mock objects for testing the code in isolation.&lt;/p&gt;

&lt;p&gt;The AOP module provides Aspect-Oriented Programming functionalities like method interception, pointcuts, security, and logging features. Spring has its own module called Spring AOP that offers basic, aspect-oriented programming functionality. Advanced AOP functionality can be implemented through integration with AspectJ. AOP features cross-cutting concerns from business logic.&lt;/p&gt;

&lt;p&gt;Outside of this basic project, Spring includes projects for all major use cases. These projects include modules that are too niche for a  basic project but include invaluable APIs and functionalities for the target use. &lt;/p&gt;

&lt;p&gt;For example, Spring Cloud allows the development of &lt;a href="https://www.educative.io/blog/beginners-guide-cloud-computation" rel="noopener noreferrer"&gt;cloud native applications&lt;/a&gt; that can be dynamically configured and deployed. It provides functionality for handling common patterns in distributed systems. Other projects include Spring Boot, Spring Security, Spring DAO, Spring Context, and many more.&lt;/p&gt;


&lt;h4&gt;
  
  
  Keep learning the Spring Framework.
&lt;/h4&gt;

&lt;p&gt;Learn Spring quickly by building live projects that show you how and why to use your new skills. Educative's text-based courses are easy to skim and feature live coding environments to help you get lasting learning at your pace.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;a href="https://www.educative.io/courses/guide-spring-5-spring-boot-2" rel="noopener noreferrer"&gt;The Complete Guide to Spring 5 and Spring Boot 2&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Get started with Spring
&lt;/h2&gt;

&lt;p&gt;Now we'll get you some hands-on experience with your first Spring application: a simple movie recommendation system. &lt;br&gt;
Setting up a new project with Spring Framework is difficult because you need to set up the full architecture by hand, including which Apache Maven dependencies to use, whether to use XML or Java, and you must install a web server like Tomcat. &lt;/p&gt;

&lt;p&gt;Instead, we'll use the Spring Boot project to automate much of the setup process and use its built-in web server.&lt;/p&gt;


&lt;h3&gt;
  
  
  How to start your project
&lt;/h3&gt;

&lt;p&gt;We'll use Spring Initializr to create a Spring Boot project fast using its simple selection menu.&lt;/p&gt;

&lt;p&gt;First, go to &lt;code&gt;start.spring.io&lt;/code&gt;. You'll find a menu interface like the one below with settings selections and metadata fields. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fq7z71mvgy598ujcu9zh8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fq7z71mvgy598ujcu9zh8.PNG" alt="Alt Text" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this project, we'll select "Maven Project", choose Java as our language, and choose the latest version of Spring Boot. Avoid "SNAPSHOT" versions for now because these are versions being alpha or beta-tested. Under "Project Metadata", enter &lt;code&gt;io.datajek.springbasics&lt;/code&gt; for "GroupID" and &lt;code&gt;movie-recommmender-system&lt;/code&gt; for "ArtifactID. The group ID and artifact ID are basically the package name and class name. You'd normally add module dependencies under "Dependencies", but this project only requires default Spring tools.&lt;/p&gt;

&lt;p&gt;Once you've entered everything, press "Generate" to create a zip file with setup architecture. Unzip the folder into the desired location on your hard drive. This folder will contain a &lt;code&gt;pom.xml&lt;/code&gt; file to import into &lt;a href="https://www.educative.io/blog/best-java-ides-2021#eclipse" rel="noopener noreferrer"&gt;Eclipse IDE&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After a short moment, you'll see the following hierarchy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;src/main/java&lt;/code&gt; where the Java code will be written&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src/main/resources&lt;/code&gt; where the application properties are written&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src/test/java&lt;/code&gt; where the tests will be written
You can now right-click the &lt;code&gt;MovieRecommenderSystemApplication.java&lt;/code&gt; and run it as a Java application to produce the following console output.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.4.RELEASE)
2021-05-03 22:46:15.549  INFO 78 --- [           main] .b.m.d.MovieRecommenderSystemApplication : Starting MovieRecommenderSystemApplication v0.0.1-SNAPSHOT on b041f076fcbd with PID 78 (/Code/movie-recommender-system/target/movie-recommender-system-0.0.1-SNAPSHOT.jar started by root in /Code/movie-recommender-system/target)
2021-05-03 22:46:15.563  INFO 78 --- [           main] .b.m.d.MovieRecommenderSystemApplication : No active profile set, falling back to default profiles: default
2021-05-03 22:46:16.458  INFO 78 --- [           main] .b.m.d.MovieRecommenderSystemApplication : Started MovieRecommenderSystemApplication in 1.41 seconds (JVM running for 1.855)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Congratulations, you set up your first Spring application with Spring Boot!&lt;/p&gt;


&lt;h3&gt;
  
  
  Adding a Dependencies
&lt;/h3&gt;

&lt;p&gt;Now, we'll add a simple implementation of the movie recommender using Spring's dependency system. The program will take a movie title as input and return three movie titles of the same genre. For now, we'll be hardcoding our output so you can focus on learning the program's structure.&lt;/p&gt;

&lt;p&gt;First, create a new class in &lt;code&gt;src/main/java&lt;/code&gt; named &lt;code&gt;RecommenderImplementation&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3hf31w9tp0mmyhytagip.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3hf31w9tp0mmyhytagip.PNG" alt="Alt Text" width="794" height="936"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we'll add the &lt;code&gt;recommendMovies&lt;/code&gt; method to &lt;code&gt;RecommenderImplementation&lt;/code&gt;. The &lt;code&gt;recommendMovies&lt;/code&gt; method will take a String movie title as input and return the three recommendations in a String array. &lt;/p&gt;

&lt;p&gt;Use the hardcoded implementation below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;recommendMovies&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//use content based filter to find similar movies&lt;/span&gt;
    &lt;span class="c1"&gt;//return the results&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"M1"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"M2"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"M3"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, create an instance of the &lt;code&gt;RecommenderImplementation&lt;/code&gt; class in the &lt;code&gt;MovieRecommenderSystemApplication&lt;/code&gt; file, then call the &lt;code&gt;recommendMovies&lt;/code&gt; method through the &lt;code&gt;RecommenderImplementation&lt;/code&gt; class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;RecommenderImplementation&lt;/span&gt; &lt;span class="n"&gt;recommender&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; 
&lt;span class="nc"&gt;RecommenderImplementation&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;    
    &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;recommender&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;recommendMovies&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finding Dory"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we'll implement content-based filtering to find recommendations. To keep &lt;code&gt;recommendMovies&lt;/code&gt; independent of the filtering logic, we'll create a new class called &lt;code&gt;ContentBasedFilter&lt;/code&gt; with a method called &lt;code&gt;getRecommendations&lt;/code&gt;. This method would be where you could implement complex filtering that looks at relevant data like watch history, user-match rating, and so on. Keep these ideas in mind for when you continue expanding this project after the tutorial.&lt;/p&gt;

&lt;p&gt;For now, we'll hardcode &lt;code&gt;getRecommendations&lt;/code&gt;  to return the same three movies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;getRecommendations&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//logic of content based filter&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Happy Feet"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Ice Age"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Shark Tale"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now use the methods of the &lt;code&gt;ContentBasedFilter&lt;/code&gt; class in the &lt;code&gt;RecommenderImplementation&lt;/code&gt; class. Replace the previous hardcoded implementation of &lt;code&gt;recommendMovies&lt;/code&gt; with the following dependency-based implementation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;recommendMovies&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;ContentBasedFilter&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ContentBasedFilter&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getRecommendations&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finding Dory"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we'll add a &lt;code&gt;toString&lt;/code&gt; method to the &lt;code&gt;main&lt;/code&gt; method to make the String array readable as an output.&lt;br&gt;
Your program will now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;io.datajek.spring.basics.movierecommendersystem.lesson1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Arrays&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.SpringApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.autoconfigure.SpringBootApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nd"&gt;@SpringBootApplication&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MovieRecommenderSystemApplication&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;//SpringApplication.run(MovieRecommenderSystemApplication.class, args);&lt;/span&gt;
        &lt;span class="c1"&gt;//create object of RecommenderImplementation class&lt;/span&gt;
        &lt;span class="nc"&gt;RecommenderImplementation&lt;/span&gt; &lt;span class="n"&gt;recommender&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RecommenderImplementation&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;    

        &lt;span class="c1"&gt;//call method to get recommendations&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;recommender&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;recommendMovies&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finding Dory"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;//display results&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;io.datajek.spring.basics.movierecommendersystem.lesson1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RecommenderImplementation&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;recommendMovies&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;//use content-based filter to find similar movies&lt;/span&gt;

        &lt;span class="nc"&gt;ContentBasedFilter&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ContentBasedFilter&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getRecommendations&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finding Dory"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;//return the results&lt;/span&gt;
        &lt;span class="c1"&gt;//return new String[] {"M1", "M2", "M3"};&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;io.datajek.spring.basics.movierecommendersystem.lesson1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ContentBasedFilter&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;getRecommendations&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;//implement logic of content-based filter&lt;/span&gt;

        &lt;span class="c1"&gt;//return movie recommendations&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Happy Feet"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Ice Age"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Shark Tale"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The current implementation is tightly coupled because the &lt;code&gt;RecommenderImplementation&lt;/code&gt; class depends on &lt;code&gt;ContentBasedFilter&lt;/code&gt; to work. Now, we'll decouple these components to allow for multiple types of filtering, such as a &lt;code&gt;CollaborativeFilter&lt;/code&gt;. We'll use an abstract &lt;code&gt;Filter&lt;/code&gt; interface with different implementations based on the selected filter type.&lt;/p&gt;

&lt;p&gt;Spring makes this easy by automatically creating and managing the dependent instances for each component. It will automatically detect the dependency relationship between our classes, meaning you can focus on the code.&lt;/p&gt;

&lt;p&gt;Your decoupled project will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;io.datajek.spring.basics.movierecommendersystem.lesson2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Arrays&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.SpringApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.autoconfigure.SpringBootApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nd"&gt;@SpringBootApplication&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MovieRecommenderSystemApplication&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;//SpringApplication.run(MovieRecommenderSystemApplication.class, args);&lt;/span&gt;
        &lt;span class="c1"&gt;//passing name of the filter as constructor argument&lt;/span&gt;
        &lt;span class="nc"&gt;RecommenderImplementation&lt;/span&gt; &lt;span class="n"&gt;recommender&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RecommenderImplementation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ContentBasedFilter&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;    

        &lt;span class="c1"&gt;//call method to get recommendations&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;recommender&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;recommendMovies&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finding Dory"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;//display results&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;io.datajek.spring.basics.movierecommendersystem.lesson2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CollaborativeFilter&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Filter&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;getRecommendations&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//logic of content based filter&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Finding Nemo"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Ice Age"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Toy Story"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;io.datajek.spring.basics.movierecommendersystem.lesson2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ContentBasedFilter&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Filter&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;getRecommendations&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;//implement logic of content-based filter&lt;/span&gt;

        &lt;span class="c1"&gt;//return movie recommendations&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Happy Feet"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Ice Age"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Shark Tale"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;io.datajek.spring.basics.movierecommendersystem.lesson2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RecommenderImplementation&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//use filter interface to select filter&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Filter&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;RecommenderImplementation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Filter&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;//use a filter to find recommendations&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;recommendMovies&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;//print the name of interface implementation being used&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Name of the filter in use: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"\n"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getRecommendations&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finding Dory"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;io.datajek.spring.basics.movierecommendersystem.lesson2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Filter&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;getRecommendations&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Spring concepts to learn next
&lt;/h2&gt;

&lt;p&gt;Congratulations on completing your first decoupled Spring application! As you continue learning more advanced Spring concepts, try returning to this project and implementing more intricate filters and features. This will help you solidify your learning and give you a portfolio-ready project by the time you're ready to interview.&lt;/p&gt;

&lt;p&gt;Some new concepts to apply to this project are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implement advanced autowiring&lt;/li&gt;
&lt;li&gt;Optimize resource management with bean scope&lt;/li&gt;
&lt;li&gt;Convert to a web application using Spring Web MVC framework&lt;/li&gt;
&lt;li&gt;Create self-repairing systems using the BeanFactory design pattern&lt;/li&gt;
&lt;li&gt;Add relational database support with Hibernate templates and Java Persistence API (JPA)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To help you learn these concepts and apply them to this project, Educative has created &lt;a href="https://www.educative.io/courses/guide-spring-5-spring-boot-2" rel="noopener noreferrer"&gt;&lt;strong&gt;The Complete Guide to Spring 5 and Spring Boot 2&lt;/strong&gt;&lt;/a&gt;. This course walks you through all the advanced features of Spring Framework and shows you how to use each in a project setting. By the end, you'll have hands-on experience with all of these topics and have the Spring context you need to thrive in an interview. &lt;/p&gt;



&lt;h3&gt;
  
  
  Continue reading about Spring and Java
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/spring-webflux-tutorial" rel="noopener noreferrer"&gt;Spring WebFlux tutorial: how to build a reactive web app&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/40-spring-interview-questions" rel="noopener noreferrer"&gt;Top 40 Questions for a Spring Framework Interview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/java-agile-development" rel="noopener noreferrer"&gt;Java Agile Development: Data management with Java domain models&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>spring</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Bytesize: 2 Accidental discoveries that changed programming</title>
      <dc:creator>Ryan Thelin</dc:creator>
      <pubDate>Fri, 30 Apr 2021 20:55:24 +0000</pubDate>
      <link>https://dev.to/educative/bytesize-2-accidental-discoveries-that-changed-programming-j4a</link>
      <guid>https://dev.to/educative/bytesize-2-accidental-discoveries-that-changed-programming-j4a</guid>
      <description>&lt;p&gt;Bytesize is our 5-minute infusion of developer history, speculation, or otherwise fun knowledge that you can enjoy during a work or study break. &lt;/p&gt;

&lt;p&gt;When you set off to become a developer, you probably dreamed of working on self-driving cars, artificial intelligence, world-changing apps, or any number of other amazing products. However, there's a lot of learning and beginner developer work you need to do before you can get there. This can be draining and can make you lose sight of what got you excited to be a developer in the first place.&lt;/p&gt;

&lt;p&gt;When knee-deep in a tough concept or a product function that's fighting back, Bytesize is here every week to give you 5-minutes to shake it off and let your imagination fly once more.&lt;/p&gt;



&lt;h4&gt;&lt;b&gt; Never miss Educative content again &lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;Sign up for our free, bi-monthly newsletter to receive the latest in tech news and trends, right in your inbox.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; &lt;a href="https://www.educative.io/blog/blog-newsletter-annoucement" rel="noopener noreferrer"&gt;Learn more about our Newsletter&lt;br&gt;
&lt;/a&gt; &lt;/b&gt;&lt;/p&gt;



&lt;p&gt;&lt;a href="https://media2.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%2Fbc1g3zask47c94k4xqr8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fbc1g3zask47c94k4xqr8.PNG" alt="Alt Text" width="612" height="580"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Chaos Engineering
&lt;/h2&gt;

&lt;p&gt;Chaos Engineering is a form of stress testing that intentionally breaks your system or components under certain stresses to determine potential outages, locate weakness, and improve resiliency. Chaos Engineering is now used across large-scale tech companies to catch unpredictable situations, traffic levels, or unexpected race conditions.&lt;/p&gt;

&lt;p&gt;While gaining prominence now, it was famously invented by accident by Netflix in 2011. Between 2008 and 2011, Netflix was looking for a replacement for their on-premise server after a critical and unexpected error. &lt;br&gt;
Teams analyzed every part of the system trying to understand how the failure had occurred, why it had affected so much, and how they could prevent it in the future. Afterward, many engineers found that they had a much better understanding of the system they'd be using for years.&lt;/p&gt;

&lt;p&gt;They settled on an AWS distributed cloud architecture with many interworking components. The switch solved the major error they had encountered but introduced a new level of complexity that they had to explore.&lt;/p&gt;

&lt;p&gt;To learn more, the team considered how much they had learned about their system trying to troubleshoot the on-premises just a few years prior. They decided to create a program called &lt;strong&gt;Chaos Monkey&lt;/strong&gt; that would randomly shut down components of the system.&lt;br&gt;
Chaos Monkey allowed them to test if the services they were building were robust and resilient enough to deal with the unexpected errors that result from such large-scale products. &lt;/p&gt;

&lt;p&gt;The practice would become known as "Chaos Engineering" and Chaos Monkey was released as open-source software in 2012. It has since gained traction as an essential process for proactively correcting distributed, at-scale systems.&lt;/p&gt;

&lt;p&gt;From one critical error, Netflix was able to realize both the need for more resilient systems and found that frequent failure aversion was the key to truly understanding their system. They may not have intended it, but that one system failure in 2008 managed to lead developers down a whole new path of testing.&lt;/p&gt;



&lt;p&gt;&lt;a href="https://media2.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%2Fsuzxt2jya8hebyxa48n1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fsuzxt2jya8hebyxa48n1.PNG" alt="Alt Text" width="563" height="552"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Java for web development
&lt;/h2&gt;

&lt;p&gt;To understand this discovery we have to understand the state of computer science when Java was created.&lt;/p&gt;

&lt;p&gt;In the late 1980s and early 1990s, there was a large boom in computer science innovations when many started to recognize the varied applications of computers. One innovator named Patrick Naughton at Sun Microsystems was particularly interested in cross-device communication using a computer. The dream was to make what we'd now call a smart remote to control multiple appliances in your home with the same device.&lt;/p&gt;

&lt;p&gt;Both C and C++ were prevalent at the time but had a severe problem with cross-device code. Each compiler at the time would compile code to machine code only usable by the device it was compiled on. In other words, a C++ project compiled on a Macintosh computer couldn't be used by another type of device.&lt;/p&gt;

&lt;p&gt;They needed a new programming language that could work on many devices, so the team created Oak, which would eventually become Java. Oak was different from other languages of its time because it compiled, not into machine code, but into an intermediate language called bytecode. Any device with a bytecode interpreter could then translate this into its own machine code and run the program.&lt;/p&gt;

&lt;p&gt;Unfortunately, the original remote device failed to interest customers because most homes only had a handful of devices at that time. It was decided that there was little need for cross-device code and the project was scrapped.&lt;/p&gt;

&lt;p&gt;However, in 1993 the first Mosaic browser was released and the World Wide Web began to take off. Suddenly, there was a network that connected devices of all types, and the need for cross-device code skyrocketed. Sun Co-founder, Bill Joy, realized that Oak's bytecode was a perfect fit for sending programs to the many devices on the web. The project was quickly adapted to suit the web and by 1995 Naughton had produced &lt;strong&gt;HotJava&lt;/strong&gt;, a bytecode interpreter compatible with any browser. &lt;/p&gt;

&lt;p&gt;Using Java and HotJava, developers could produce a program and release it to any web-capable device without having to consider which devices would access it. Java is still used in web development today to create enterprise-scale dynamic web applications with Java Enterprise Edition (JEE) and JavaServer Pages (JSP). &lt;/p&gt;

&lt;p&gt;It's amazing to think that this language with cross-device properties seemingly tailor-made for web development was created before the web even existed -- to run a simple remote control!&lt;br&gt;
It just goes to show that no matter how mundane the project seems, you might discover the next world-changing technology.&lt;/p&gt;



&lt;h3&gt;
  
  
  Continue reading about these discoveries
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/chaos-engineering-process-principles" rel="noopener noreferrer"&gt;Chaos Engineering 101: principles, process, and examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/distributed-systems-considerations-tradeoffs" rel="noopener noreferrer"&gt;What are Distributed Systems? A quick introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/blog/learn-java-from-scratch" rel="noopener noreferrer"&gt;Learn Java from scratch with these easy steps&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>watercooler</category>
      <category>java</category>
      <category>todayilearned</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
