<?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: Gyau Boahen Elvis</title>
    <description>The latest articles on DEV Community by Gyau Boahen Elvis (@gyauelvis).</description>
    <link>https://dev.to/gyauelvis</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%2F1127871%2Fea0291ee-47d6-44c9-8707-89b2d57eff37.jpeg</url>
      <title>DEV Community: Gyau Boahen Elvis</title>
      <link>https://dev.to/gyauelvis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gyauelvis"/>
    <language>en</language>
    <item>
      <title>Carbon: The new C++?</title>
      <dc:creator>Gyau Boahen Elvis</dc:creator>
      <pubDate>Mon, 26 Aug 2024 13:33:13 +0000</pubDate>
      <link>https://dev.to/gyauelvis/carbon-the-new-c-35fn</link>
      <guid>https://dev.to/gyauelvis/carbon-the-new-c-35fn</guid>
      <description>&lt;p&gt;A large number of the most effective programming languages available today descended from earlier languages. C++, for instance, was developed to improve up the powerful yet fearsome C, a language that makes it so so easy to shoot yourself in the foot. TypeScript emerged from the messy JavaScript, while Kotlin stepped up to refine Java's complexity. Objective-C made way for the elegant Swift. It's a cycle of evolution, each language learning from the flaws of its forerunners to become sharper, safer, and more efficient. &lt;/p&gt;

&lt;p&gt;The Big Question we wish to answer after this video is after C++, what comes next?&lt;/p&gt;

&lt;p&gt;But wait, is there supposed to be something beyond C++? Sure, C++ is a powerhouse, but it's also a beast to handle. You almost need four legs to keep up because C++ is notoriously tough. This complexity makes fast, scalable development a real challenge. Compared to other languages, C++ can slow you down with its careful memory management. And With error messages looking like Shakespeare's poems, it will take you years to build something you'll build in days in other languages.  The language's commitment to backward compatibility with C adds to its technical debt it has accumulated over the years, making modernization a headache. Unlike JavaScript's npm or Python's pip3, C++ lacks a default package manager, forcing developers to juggle dependencies manually.&lt;/p&gt;

&lt;p&gt;According to Bjarne Stroustrup, the creator of C++, in his book &lt;code&gt;Design and Evolution of C++&lt;/code&gt;, he stated that within C++, there is a much smaller and cleaner language struggling to get out.&lt;/p&gt;

&lt;p&gt;Is it Rust? Dear Rustaceans, Rust is great, but no. Rust isn't the cleaner and smaller language Bjarne Stroustrup was referring to. One reason is that Rust isn't interoperable with C++, and besides, Rust's performance doesn't match that of C++. C++ has been used to build numerous applications across various industries, and no developer ever wants to undertake the daunting task of converting an entire C++ codebase, especially a large one, to a different programming language.&lt;/p&gt;

&lt;p&gt;At the C++ Conference in Toronto in July 2022, Google's engineer Chandler Carruth introduced Carbon, an experimental successor to C++ built with using LLVM, with low-level access to bits and addresses. This new language is designed to provide seamless access to the entire C++ ecosystem, building on and around it. Google's aim isn't necessarily to have all developers abandon their C++ code but to offer a viable alternative for those who may benefit from a different approach. &lt;/p&gt;

&lt;p&gt;Just as some developers have shifted entirely to TypeScript, even though JavaScript is still widely used, Carbon could become the go-to for certain workflows while others continue with C++. The idea isn't to replace C++ entirely, but to provide options, just like TypeScript has done for JavaScript.&lt;/p&gt;

&lt;p&gt;Carbon has bidirectional interoperability with C++, allowing you to use Carbon code in C++ and vice versa. This makes it easier for engineers to migrate C++ codebases to Carbon or build upon C++ with Carbon. Designed for performance-critical applications, Carbon also offers a gentle learning curve, thanks to its simple syntax and introducer keywords. This simplicity makes Carbon easy to parse for humans, IDEs, and compilers—unlike C++.&lt;/p&gt;

&lt;p&gt;For instance, if you search for 'the most vexing parse,' you'll find a C++ example on Wikipedia. It's a notorious issue that highlights the complexity of C++, making Carbon's ease of use even more valuable.&lt;/p&gt;

&lt;p&gt;It is designed to be a memory-safe language that makes it very difficult and almost impossible to shoot yourself in the foot and even when you do, there will be tools and simple sentences and easy-to-understand error messages to bail you out. Let's look at some code.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Esoteric Languages: What are they, and why you should be concerned?</title>
      <dc:creator>Gyau Boahen Elvis</dc:creator>
      <pubDate>Fri, 02 Feb 2024 05:46:00 +0000</pubDate>
      <link>https://dev.to/gyauelvis/esoteric-languages-what-are-they-and-why-you-should-be-concerned-592d</link>
      <guid>https://dev.to/gyauelvis/esoteric-languages-what-are-they-and-why-you-should-be-concerned-592d</guid>
      <description>&lt;p&gt;In the dimension of programming languages, certain languages are widely regarded as proficient and effective, including &lt;code&gt;TypeScript&lt;/code&gt;, &lt;code&gt;Kotlin&lt;/code&gt;, and &lt;code&gt;Rust&lt;/code&gt;, among others. On the other hand, some may express reservations about languages like &lt;code&gt;PHP&lt;/code&gt;, &lt;code&gt;Java&lt;/code&gt;, and &lt;code&gt;Perl&lt;/code&gt;, deeming them as less favorable. &lt;br&gt;
Beyond the conventional languages are a category of programming languages known as &lt;strong&gt;Esoteric languages&lt;/strong&gt;. These are languages invented seemingly to make developers cringe at the mere mention of their names.&lt;/p&gt;

&lt;p&gt;Can you imagine a programming language that only recognizes eight characters? Anything else written in this language, apart from the recognized characters &lt;code&gt;&amp;lt; &amp;gt; [ ] , . + -&lt;/code&gt;, is considered a comment. It might seem impossible! One notable example is &lt;strong&gt;Brainfuck&lt;/strong&gt;, a language that executes only the characters mentioned; any other character used in coding is treated as a comment. &lt;/p&gt;

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

&lt;p&gt;In this article, we will delve deeper into Esoteric programming languages &lt;code&gt;(esolangs for short)&lt;/code&gt;. We'll explore five examples of the most bizarre Esolangs out there, and, to top it off, we will attempt to write &lt;code&gt;hello world&lt;/code&gt; in some of these languages, if it's possible. Are you curious to learn more about Esolangs? Put on your helmet, and let's ride together because it's going to be a long but exciting journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Esoteric Languages?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;These are programming languages created for fun, code obfuscation, or as an experiment in pushing the boundaries of programming.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Esolangs are designed to be nothing like the conventional languages developers are used to. They are the outlaws of the programming dimension that are intentionally created to have features that deviate from the &lt;code&gt;normal&lt;/code&gt; programming languages, either as a joke or just to push the boundaries of programming languages a little further. The intention of esolang designers is not for these languages to be used in mainstream programming, although some of these languages have led to emphasis and conversations about some mainstream programming language features.  &lt;/p&gt;

&lt;p&gt;Time to get our hands dirty. Let's dig into some of the most popular and interesting Esolangs out there.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Compiler Language With No Pronounceable Acronym (INTERCAL)
&lt;/h2&gt;

&lt;p&gt;Imagine a scenario where including the keyword &lt;code&gt;Please&lt;/code&gt; in your code is mandatory; otherwise, the compiler deems it impolite and rejects the code. Striking a balance is crucial because too few &lt;code&gt;Please&lt;/code&gt; might be interpreted as rudeness, while an excess of politeness might also lead to rejection. Think it's impossible? Allow me to introduce you to the &lt;code&gt;Compiler Language With No Pronounceable Acronym&lt;/code&gt;, abbreviated as &lt;code&gt;INTERCAL&lt;/code&gt;—a name chosen for reasons only known to its creators, Don Woods and James M. Lyon.&lt;/p&gt;

&lt;p&gt;INTERCAL was created in 1970 to be nothing like the conventional programming languages. It intentionally contains puzzling and redundant features; it defies the norms of typical programming languages, which make it impossible to understand. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hello World in INTERCAL&lt;/strong&gt;&lt;/p&gt;

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

&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;
&lt;span class="n"&gt;PLEASE&lt;/span&gt; &lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;238&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;108&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;112&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;194&lt;/span&gt;
&lt;span class="n"&gt;PLEASE&lt;/span&gt; &lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;48&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;26&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;244&lt;/span&gt;
&lt;span class="n"&gt;PLEASE&lt;/span&gt; &lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;168&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;
&lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;SUB&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;162&lt;/span&gt;
&lt;span class="n"&gt;PLEASE&lt;/span&gt; &lt;span class="n"&gt;READ&lt;/span&gt; &lt;span class="n"&gt;OUT&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;PLEASE&lt;/span&gt; &lt;span class="n"&gt;GIVE&lt;/span&gt; &lt;span class="n"&gt;UP&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  2. EMOJICODE
&lt;/h2&gt;

&lt;p&gt;If you've ever imagined coding in emojis, then Emojicode is for you! Emojicode is a Turing complete Esolang consisting of emojis that was designed by Theo B. Weidmann. He came up with the idea after receiving texts with lots of emojis and his mind automatically started interpreting them as codes. This language uses C-style syntax for coding, but with emojis as functions. &lt;/p&gt;

&lt;p&gt;To create an Emojicode source file, you use the file extension .🍇 or .emojic &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

🏁🍇

🍉


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

&lt;/div&gt;

&lt;p&gt;This is the basic structure of every Emojicode. The 🏁 is the special keyword[key-emoji] every program written in this language must start with. Every block of code must start with 🍇 and end with the 🍉. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hello World in Emojicode&lt;/strong&gt;&lt;/p&gt;

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

🏁 🍇
  😀 🔤Hello World!🔤❗️
🍉


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

&lt;/div&gt;

&lt;p&gt;A string in Emojicode is defined as the characters positioned between any two instances of the emoji 🔤. To illustrate, we invoke the print function using the &lt;code&gt;grinning face with big eyes&lt;/code&gt; emoji 😀, passing the identified string as an argument. The ❗️ denotes the termination of the list of arguments supplied to the print function.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Whenever
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Whenever&lt;/code&gt; lacks control flow—the aspect of every programming language that makes your code run in a systematic and well-structured order. This absence results in the language executing any part of the code whenever it wants, not in the order specified by the programmer. Whenever does not just lack control flow; it also lacks variables and data structures, which makes it impossible for &lt;code&gt;Whenever&lt;/code&gt; to be used in mainstream programming.'&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hello World in Whenever&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To write 'hello world' in Whenever is done similarly to Python, with the only difference being the mandatory inclusion of a line number and a semicolon.&lt;/p&gt;

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

&lt;span class="mi"&gt;1&lt;/span&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;If we decide to write &lt;code&gt;1 print('hello');&lt;/code&gt; and &lt;code&gt;2 print('World')&lt;/code&gt; on different lines, we will sometimes get 'Hello World' outputted to the console or 'World Hello' at other times.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  4. WHITESPACE
&lt;/h2&gt;

&lt;p&gt;Unlike most programming languages that assign little or no meaning to whitespace characters, the only recognizable characters in Whitespace are the whitespace characters—tab, space, and line feed; anything else is ignored by the language. For this very reason, a &lt;code&gt;Whitespace&lt;/code&gt; program looks like nothing but whitespace until you highlight the characters in the document.&lt;/p&gt;

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

&lt;p&gt;The language was released on April 1, 2003, as an April Fool's joke by Chris Morris, and it is not intended to be used for mainstream programming. Obviously, who would want to use a John Cena form of programming language?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hello World in Whitespace&lt;/strong&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  5. BrainFuck
&lt;/h2&gt;

&lt;p&gt;Brainfuck is not merely the name of a programming language; it also characterizes your mental state following your initial encounter with this unique language. Brainfuck exclusively acknowledges eight characters: &lt;code&gt;&amp;lt; &amp;gt; [ ] , . + -&lt;/code&gt;. Anything outside these recognized characters in the code is treated as a comment.&lt;/p&gt;

&lt;p&gt;Urban Müller developed Brainfuck in 1993 with the goal of creating the smallest-ever programming language compiler, measuring only 296 bytes. This endeavor followed Wouter van Oortmerssen's creation of the &lt;code&gt;False language&lt;/code&gt;, which had a compiler size of 1024 bytes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hello World in BrainFuck&lt;/strong&gt;&lt;/p&gt;


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

&lt;p&gt;&amp;gt;++++++++[&amp;lt;+++++++++&amp;gt;-]&amp;lt;.&lt;br&gt;
&amp;gt;++++[&amp;lt;+++++++&amp;gt;-]&amp;lt;+.&lt;br&gt;
+++++++..&lt;br&gt;
+++.&lt;br&gt;
&amp;gt;&amp;gt;++++++[&amp;lt;+++++++&amp;gt;-]&amp;lt;++.&lt;br&gt;
------------.&lt;br&gt;
&amp;gt;++++++[&amp;lt;+++++++++&amp;gt;-]&amp;lt;+.&lt;br&gt;
&amp;lt;.&lt;br&gt;
+++.&lt;br&gt;
------.&lt;br&gt;
--------.&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt;++++[&amp;lt;++++++++&amp;gt;-]&amp;lt;+.&lt;/p&gt;

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

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Conclusion&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Esolangs represent the unconventional form of programming that decides to deviate from the rules of the programming dimension. They are not meant for mainstream coding but just to push the boundaries of the programming field.&lt;/p&gt;

&lt;p&gt;As we delve into esolangs, you begin to appreciate the importance of mainstream languages that make our everyday coding efficient and effective.&lt;/p&gt;

&lt;p&gt;Hey Devs, g.elvis🚀 here and its peace out.✌&lt;/p&gt;

</description>
      <category>esolang</category>
      <category>learning</category>
      <category>coding</category>
      <category>programming</category>
    </item>
    <item>
      <title>Programming Languages Every Developer Should Watch Out For</title>
      <dc:creator>Gyau Boahen Elvis</dc:creator>
      <pubDate>Mon, 02 Oct 2023 18:31:44 +0000</pubDate>
      <link>https://dev.to/gyauelvis/programming-languages-every-developer-should-watch-out-for-1ak4</link>
      <guid>https://dev.to/gyauelvis/programming-languages-every-developer-should-watch-out-for-1ak4</guid>
      <description>&lt;p&gt;In the ever-changing field of programming, staying updated with the trends of new programming languages, frameworks, and other required tools is a necessity for every developer who seeks to thrive in this field. Remember &lt;code&gt;Ada&lt;/code&gt; and &lt;code&gt;COBOL&lt;/code&gt;? These were two dominant languages in the '90s, but today? Not so much. &lt;code&gt;TypeScript&lt;/code&gt; was released in &lt;code&gt;2012&lt;/code&gt;, and it is a requirement for most full-stack developer jobs out there today. &lt;code&gt;Dart&lt;/code&gt; first appeared in 2011 and has become a global phenomenon in the field of mobile app development. These are a few examples to illustrate how dynamic the field of computer programming is. New programming languages are released all the time, and it's better to stay updated and have a good knowledge of them now before they become a requirement for every job opportunity out there.&lt;/p&gt;

&lt;p&gt;In this article, we will be looking at some of these "new" programming languages that every developer should keep an eye on, to keep it simple, we will be giving you reasons why you should care and to top it off, we will write "Hello, World" in each of them. &lt;/p&gt;

&lt;p&gt;So buckle up, and let's dive in because it's going to be an exciting journey 🚀.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  1. &lt;a href="https://github.com/carbon-language/carbon-lang" rel="noopener noreferrer"&gt;Carbon&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Imagine if C++ is easy to read, write, understand, and had a smooth learning curve. It would be every developer's number one choice when it comes to building performance-critical applications. However, it's evident that C++ is not.&lt;/p&gt;

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

&lt;p&gt;There are other programming languages out there, like Rust, that have relatively simple syntax and can be used to build performance-critical applications. The problem, though, is that these languages are not interoperable with C++. C++ has been used to build numerous applications across various industries, and no developer wants to undertake the daunting task of converting an entire C++ codebase to a different programming language. &lt;/p&gt;

&lt;p&gt;This is the problem that Carbon seeks to solve. Carbon was first announced by Google in 2022 and is meant to be the successor to C++. Carbon is C++ interoperable, with a simple syntax, while also providing the performance of C++. The language is still a work in progress, and the official release date for Carbon 1.0 is set for either 2024 or 2025. Want to&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hello World Program in Carbon&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn Main() -&amp;gt; i32 {
 var s: auto = "Hello, World!";
 Print(s); 
 return 0; 
}

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

&lt;/div&gt;



&lt;p&gt;Similar to C++, every program begins with a main function, serving as the entry point. It's declared using the &lt;code&gt;fn&lt;/code&gt; keyword, and specifying &lt;code&gt;i32&lt;/code&gt; indicates that the program will return a 32-bit integer.&lt;/p&gt;

&lt;p&gt;To declare a variable, we utilize the &lt;code&gt;var&lt;/code&gt; keyword and place a colon before the variable's identifier to specify its type. In this particular case, we've assigned the type &lt;code&gt;auto&lt;/code&gt; to our variable, indicating that its type will be determined based on its initializer. The &lt;code&gt;Print&lt;/code&gt; keyword is employed to display the value of &lt;code&gt;s&lt;/code&gt; on the screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://www.rust-lang.org/" rel="noopener noreferrer"&gt;Rust&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Rust is used in building systems where performance is critical, such as game engines, databases and operating systems. It is an excellent choice for WebAssembly. It offers relatively simple syntax and delivers with the speed of languages like C and C++. &lt;/p&gt;

&lt;p&gt;Traditionally, high-level languages like Python use garbage collection for automatic memory management, while low-level languages like C++ provide functions like &lt;code&gt;new&lt;/code&gt;, &lt;code&gt;delete&lt;/code&gt;, and &lt;code&gt;free&lt;/code&gt; to allocate and release memory spaces when needed. However, Rust takes a different approach, using the concepts of borrowing and ownership to ensure memory safety and proper management.&lt;/p&gt;

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

&lt;p&gt;By default, all variables in Rust are immutable, meaning that attempting to assign a different value to a variable after it has already been given one will result in a compilation error. Instead of multiple variables, values are assigned to a single variable called the owner. When the program goes out of the scope of the owner, the memory space assigned to the variable is released using a special function known as &lt;code&gt;drop&lt;/code&gt; in Rust.&lt;/p&gt;

&lt;p&gt;Rust includes a standard library that provides various functionalities such multithreading, file systems, and input and output operations, among others.&lt;/p&gt;

&lt;p&gt;It's also accompanied by a package manager and build tool called Rust Cargo. You don't have to concern yourself with programming dependencies and setups; all you need to do is specify the library, and Cargo will take care of the rest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, World!"&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;code&gt;main()&lt;/code&gt; function is the entry point to the program, and it is declared using the &lt;code&gt;fn&lt;/code&gt; keyword. &lt;code&gt;println&lt;/code&gt; is used to display "Hello, World!" to the console. The &lt;code&gt;!&lt;/code&gt; in front of the &lt;code&gt;println&lt;/code&gt; indicates it no regular function call but a &lt;a href="https://doc.rust-lang.org/book/ch19-06-macros.html" rel="noopener noreferrer"&gt;macro in rust&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;a href="https://docs.modular.com/mojo/" rel="noopener noreferrer"&gt;Mojo&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;While Python is an excellent choice for productive programming, it does tend to lag behind other languages such as C++ and Rust when it comes to raw performance. This is where Mojo enters the scene, it's a superset of Python, and it boasts the remarkable ability to accelerate your code to speeds up to 35,000 times faster than standard Python.&lt;/p&gt;

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

&lt;p&gt;Mojo, released in May 2023, comes from Modular, a company founded by the creator of Swift, which, replaced Objective-C. What sets Mojo apart is its full compatibility with Python, meaning you can still use your favorite python libraries with Mojo&lt;/p&gt;

&lt;p&gt;Mojo also enhances Python with strong type checking, which can optimize your code. Dynamic programming, just like in Python, remains fully supported in Mojo.&lt;br&gt;
Just like Rust, Mojo uses the concept of Ownership and Borrowing for memory safety and management. Just like python—Mojo is designed with a focus on programming for AI hardware GPUs. It comes equipped with built-in auto-tuning capabilities to optimize your code specifically for your target device.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.modular.com/mojo/" rel="noopener noreferrer"&gt;Mojo&lt;/a&gt; truly unlocks a world of possibilities in high-performance computing. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hello World Program in Mojo&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn main():
   print("Hello, world!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is so simple and requires no explanation. Enjoy 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;a href="https://elixir-lang.org/" rel="noopener noreferrer"&gt;Elixir&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Elixir is a dynamic and general purpose functional programming language with a straightforward syntax, similar to Ruby. It was released in 2012 by Jose Valim. Elixir runs on the Beam Erlang virtual machine, making applications created with Elixir very concurrent, resilient at runtime, and fault-tolerant—qualities that many applications built with programming languages like Python and Ruby often lack. Elixir consistently ranks among the most beloved languages by developers with a growing ecosystem, characterized by a welcoming community eager to share resources and valuable libraries with beginners.&lt;/p&gt;

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

&lt;p&gt;These capabilities and Elixir tooling enable developers to be productive across a wide range of industries in fields such as web development, embedded software, machine learning, data pipelines, and multimedia processing.&lt;/p&gt;

&lt;p&gt;It is used by discord to handle a massive amount of concurrent users. It is also used by Pinterest, Heroku and other notable applications. &lt;/p&gt;

&lt;p&gt;Elixir comes with the Phoenix web framework, which offers most of what you need for web development tasks. It provides features that help developers easily keep track of multiple users connected to their applications. The LiveView feature of Phoenix makes it much easier for developers to build rich and interactive user interfaces without having to introduce a separate frontend tool to handle interactivity.&lt;br&gt;
With simple syntax but efficient and concurrent performance, Elixir will take over the programming industry in no time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hello World Program in Elixir&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;puts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello world from Elixir"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;IO.puts&lt;/code&gt; just like in Ruby, is the responsible for displaying the "Hello world from Elixir" to the console. The parenthesis is optional in writing this program. &lt;/p&gt;

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

&lt;p&gt;Hey Devs, In this field, just like you already know, you never stop learning; you have to gain the required knowledge the programming market expects you to, and it is quite a dynamic market. I hope this article gives you a fair idea of how the programming market will be in the years to come.&lt;/p&gt;

&lt;p&gt;g.elvis here and Peace Out✌️&lt;/p&gt;

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

</description>
      <category>programming</category>
      <category>tutorial</category>
      <category>coding</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Comprehensive Guide to APIs and the Fetch API</title>
      <dc:creator>Gyau Boahen Elvis</dc:creator>
      <pubDate>Fri, 08 Sep 2023 20:29:15 +0000</pubDate>
      <link>https://dev.to/gyauelvis/a-beginners-guide-to-apis-4ce4</link>
      <guid>https://dev.to/gyauelvis/a-beginners-guide-to-apis-4ce4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Have you ever wondered how Shazam instantly recognizes a song once a snippet is sent to it?🤔 How about, how Facebook automatically display your Instagram photos? The concept behind these amazing technological feats is not about your device storing every song or image in the world, but rather the fascinating concept of APIs (Application Programming Interfaces).&lt;/p&gt;

&lt;p&gt;In this article, we will embarking on a journey to explore the inner workings of APIs, understand their various architectural types, and appreciate why mastering them is a neccessity in the world of software development. We'll specifically dive into the Fetch API, a JavaScript method that acts as a bridge between your applications and external servers, enabling seamless communication.&lt;/p&gt;

&lt;p&gt;Buckle up and lets dig deep into this amazing concept together.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  What are APIs?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="//ibm.com/topics/api"&gt;According to IBM&lt;/a&gt;, An API, or Application Programming Interface, is a set of defined rules that enable different applications to communicate with each other. It acts as an intermediary layer that processes data transfers between systems, letting companies open their application data and functionality to external third-party developers, business partners, and internal departments within their companies.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The API is just the waiter that sends your order to the chef and then gets the food for you when it is ready. In this scenario, we are assuming that the chef is our server and you, the one making the order: the client. The waiter acts as the API-(mediator) between the client and the server, allowing communication between these two parties.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Types of API Architectures
&lt;/h2&gt;

&lt;p&gt;APIs are categorized according to the set of protocols they follow, which govern the allowed data formats and commands. Significant APIs among these classes are stated below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. REST API&lt;/strong&gt;&lt;br&gt;
Representational State Transfer API is the most popular and widely used API today. It exchanges data using HTTP requests. This API follows the REST Guidelines, and a few of them are given below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Client Server Interaction&lt;/code&gt;: Client-server interaction should take the form of a request from the client and a response from the server. The server is never allowed to make a request, and the client, never allowed to make responses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Uniform Interface&lt;/code&gt;: To ensure interoperability between any client and any server, all requests must use HTTP as the communication format. All server responses must be in JavaScript Object Notation format.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Stateless&lt;/code&gt;:  The interaction between a server and a client is distinct from all other interactions. Servers don't store any data from past interactions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. SOAP&lt;/strong&gt;: These APIs employ the Simple Object Access Protocol to send data across a network. It uses XML to encode data across the network. It specifies exactly how data should be shared across a network. When compared to REST APIs, this makes it very safe for data exchange. Because of its rigorous constraints, this API is more difficult to implement and thus less popular among developers. It is usually used for internal data sharing, which necessitates a high level of security. The Amazon Web Services API is an example of a SOAP API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. GraphQL&lt;/strong&gt;: Graph Query Language empowers clients to request only data they require, making it easier to evolve APIs over time and enabling strong developer tools. Given that we're using GitHub's API, you could use GraphQL to get only usernames or repository descriptions without receiving additional data apart from the ones requested. These APIs are efficient and boost application performance.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Master APIs
&lt;/h2&gt;

&lt;p&gt;Over 10,000 APIs were made available for public use by businesses in 2013, which is four times more than there were in 2010. You can probably guess how many APIs are currently available. &lt;br&gt;
With so many companies making investment in APIs, possessing a deeper understanding of API becomes a necessity in the software industry.&lt;/p&gt;

&lt;p&gt;API is an essential part of the world we live in today. They are used everywhere on the internet, from using them to perform simple activities such logging in or signing up to your account with third party applications such as Google or Apple to integrating payment systems like PayPal or messaging systems into your applications as a developer. They also form the backbone of complex applications such as Spotify, Netflix and X (Twitter) among others.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.turing.com/kb/7-examples-of-APIs" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrvyvz61pzgb0ay2lyev.png" alt="Every day applications of APIs"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The Fetch API
&lt;/h2&gt;

&lt;p&gt;Fetch API is used to fetch resources over a network. It is the JavaScript method that is used to make requests to servers. It provides a flexible interface, making it very easier for our applications to communicate with servers. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;How does the fetch API work?&lt;/em&gt; &lt;br&gt;
The fetch API is a promised based method, that is: anytime we use the fetch API it returns a Promise object. &lt;/p&gt;

&lt;p&gt;This Promise Object is more like a real-life promise in where we commit to doing something and, as a result, make a promise; in the end, it is either the promise we made is fulfilled and resolved or it is failed and rejected. This is exactly how JavaScript Promises work, too. &lt;/p&gt;

&lt;p&gt;The Promise Object has three states: &lt;br&gt;
🔃 &lt;code&gt;The pending state&lt;/code&gt;: Promise is neither Fulfilled nor rejected&lt;br&gt;
✅ &lt;code&gt;The Fulfilled&lt;/code&gt;: Operation successfully carried out&lt;br&gt;
❌ &lt;code&gt;The rejected state&lt;/code&gt;: Operation failed.&lt;/p&gt;

&lt;p&gt;The Promise Object comes with two hidden properties: &lt;code&gt;value&lt;/code&gt; and  &lt;code&gt;onFulfilment array&lt;/code&gt;. The value property keeps the response object from the server, and the &lt;code&gt;onFulfilment array&lt;/code&gt; stores the function(s) we wish to call after receiving the response object. These functions are added to &lt;code&gt;onFulfilment array&lt;/code&gt; using the &lt;code&gt;.then()&lt;/code&gt; method and are called immediately as soon as the &lt;code&gt;value&lt;/code&gt;property gets updated.&lt;/p&gt;

&lt;p&gt;No need to worry about the &lt;code&gt;value&lt;/code&gt; and &lt;code&gt;onFulfilment array&lt;/code&gt; properties, since you won't ever use them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulv3r42dhwg8t9l3gzgm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulv3r42dhwg8t9l3gzgm.gif" alt="Fetch API Promise Visualized "&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementing the Fetch API
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;The fetch API takes two arguments. The first argument is the URL to the resource we want to fetch - this is a compulsory. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.example.com&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;The second argument is optional, and it contains additional information we want to add to the URL. The additional information include&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Methods: This tells the server the action the client wants to perform. They include&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;GET&lt;/code&gt; - Retrieve resource from server. This is the default method if no method is stated.&lt;br&gt;
&lt;code&gt;POST&lt;/code&gt; - Ask server to create new resource&lt;br&gt;
&lt;code&gt;PUT&lt;/code&gt; - Update resource on server&lt;br&gt;
&lt;code&gt;DELETE&lt;/code&gt; - Delete resource on server&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;
     &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;post&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;ul&gt;
&lt;li&gt;Headers: This provides meta information about the user's request. This includes the time of request, size of request, content-type among others.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;
     &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
         &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


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

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Body: This where data the client wants to send to the server is included. Unlike the headers and methods with strict rules on how to include them, in the body the user is at complete liberty to include whatever they want.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;
     &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
         &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
     &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;userName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Gyau&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;The server returns a &lt;code&gt;response&lt;/code&gt; which is then resolved to the response object. This object comes with several properties which could be used to check the status of the response from the server. Some of these properties include the &lt;code&gt;ok&lt;/code&gt; property which will have a value of &lt;code&gt;true&lt;/code&gt; if the request was successful, the &lt;code&gt;status&lt;/code&gt; property which holds the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" rel="noopener noreferrer"&gt;HTTP Status response&lt;/a&gt; code of the response.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;catch()&lt;/code&gt; method holds the function to be called when the promise is rejected.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;
     &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
         &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
     &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;userName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Gyau&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
         &lt;span class="c1"&gt;// Handling response&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Do something else&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// function to run when promise is rejected&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;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;In the code snippet below, we are making an API GET to the &lt;a href="https://randomuser.me/" rel="noopener noreferrer"&gt;Random User API&lt;/a&gt;, this API helps generate random users for testing your application.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://randomuser.me/api/&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;The &lt;code&gt;then()&lt;/code&gt; method in the code snippet below uses the &lt;code&gt;.ok&lt;/code&gt; property to determine whether the request was successful. If it was not, it throws an error; however, if it was, it uses the &lt;code&gt;.json()&lt;/code&gt; method on the Response object to parse the response body as JSON. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://randomuser.me/api/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;

     &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Failed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;The JSON body of the response object is passed as an argument to the next &lt;code&gt;.then()&lt;/code&gt; method. Then it is processed as specified in the function body. In the code above, we just console log the data to the console. &lt;/p&gt;

&lt;p&gt;During the fetch or the processing of the response from the fetch API, if any error occurs, it is passed to the &lt;code&gt;.catch()&lt;/code&gt; to handle the error.&lt;/p&gt;
&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;API is an essential part of the software engineering industry, and possessing a deeper understanding of what it is and how to use the fetch API to integrate and sync systems together is a necessity in this field. I hope this article gives you a proper introduction to the concept of APIs and the fetch API. A tutorial by freeCodeCamp has been linked at the bottom of this article for further studies.&lt;/p&gt;

&lt;p&gt;Happy coding out there, guys. Peace Out✌️&lt;/p&gt;

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

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

</description>
      <category>api</category>
      <category>javascript</category>
      <category>fetch</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Beginners Guide: Polymorphism, Virtual Functions, and Abstract Classes With C++</title>
      <dc:creator>Gyau Boahen Elvis</dc:creator>
      <pubDate>Wed, 09 Aug 2023 11:15:26 +0000</pubDate>
      <link>https://dev.to/gyauelvis/a-beginners-guide-polymorphism-virtual-functions-and-abstract-classes-1m6</link>
      <guid>https://dev.to/gyauelvis/a-beginners-guide-polymorphism-virtual-functions-and-abstract-classes-1m6</guid>
      <description>&lt;h2&gt;
  
  
  Polymorphism
&lt;/h2&gt;

&lt;p&gt;Polymorphism comes from two words: &lt;em&gt;Poly&lt;/em&gt; which means many and &lt;em&gt;Morph&lt;/em&gt; which means form. Polymorphism as a word simply means many forms. In Objected Oriented Programming, Polymorphism refers to a function or an object behaving in different forms. &lt;/p&gt;

&lt;p&gt;Using a woman as an example, she could be a wife to one person, a mother to another, a friend to another, and a relative to another. The same woman, yet her job varies from person to person.&lt;/p&gt;

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

&lt;p&gt;This is the idea polymorphism seeks to replicate in Objected Oriented Programming. Polymorphism gives us the ability to use the same expression to denote different operations.&lt;/p&gt;

&lt;p&gt;Types of Polymorphism include &lt;strong&gt;run-time polymorphism&lt;/strong&gt; and &lt;strong&gt;compile time polymorphism&lt;/strong&gt;. Compile time polymorphism is achieved through &lt;strong&gt;function overloading&lt;/strong&gt; or &lt;strong&gt;operator overloading,&lt;/strong&gt; while run-time polymorphism is achieved through &lt;strong&gt;virtual functions&lt;/strong&gt;. &lt;/p&gt;

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

&lt;h2&gt;
  
  
  Function Overloading
&lt;/h2&gt;

&lt;p&gt;By using function overloading, we can have two functions that share the same name but carry out different operations. Below is an illustration:  &lt;/p&gt;

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

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;private:&lt;/span&gt;
  &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
  &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="c1"&gt;//Finds the area by taking just two argument eg: Rectangles&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="c1"&gt;//Finds the area by taking just one argument eg: Square&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;In the above code snippet, the Shape class has two area functions. The area function computes the area of a shape and returns its result. The first area function receives one argument, while the second takes two. The same function, but when given two arguments, it does something different from when given one. Isn't that incredible😁?&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Virtual Functions
&lt;/h2&gt;

&lt;p&gt;Given, we have the class &lt;em&gt;PetType&lt;/em&gt;. This class defines a constructor that initializes the &lt;em&gt;name&lt;/em&gt; member variable under the private access specifier. This class also declares the &lt;em&gt;print&lt;/em&gt; function that prints out the name member variable. The implementation of this class is given below.&lt;/p&gt;

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

&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PetType&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;private:&lt;/span&gt;
    &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="n"&gt;PetType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;PetType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;PetType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;PetType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;name&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;Using the above codes as base class, we can derive the &lt;strong&gt;dogType class&lt;/strong&gt; from our base class. This class also has a constructor which initializes &lt;strong&gt;breed&lt;/strong&gt; and the &lt;strong&gt;name&lt;/strong&gt; member variables of this derived class.&lt;/p&gt;

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

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;dogType&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;PetType&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nl"&gt;private:&lt;/span&gt;
    &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;breed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;dogType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;breed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&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;Note that the name variable of our base class is under the private member access specifier, and this implies that the derived class does not have a direct to this variable. In order to have access to this variable we have to do that through the public functions that were defined above, this is because our derived class has direct access to these functions. &lt;/p&gt;

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

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;dogType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;PetType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;breed&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="n"&gt;dogType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;dogType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;breed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;PetType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;breed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;breed&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;In the &lt;em&gt;print&lt;/em&gt; function of our derived class, since we don't have direct access to the &lt;em&gt;name&lt;/em&gt; variable then we can't directly print out the name variable &lt;em&gt;print&lt;/em&gt; function, so to print out the &lt;em&gt;name&lt;/em&gt; variable we have to call the print() of our base class.&lt;/p&gt;

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

&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//error in the print()&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;We don't have access to the name variable in the constructor of our derived class too, and hence the reason behind the code above. &lt;/p&gt;

&lt;p&gt;**Note: **We can solve the problem of not having direct access to the name variable of our base class in the derived class by changing the private specifier to protected.&lt;/p&gt;

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

    &lt;span class="c1"&gt;// Slight modification in the base class&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;With the above modification: We are at complete liberty to make the modifications below without encountering an error during runtime of our program.&lt;/p&gt;

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

&lt;span class="c1"&gt;// Modifications in the function definition of the dogType class.&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;dogType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;breed&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="n"&gt;dogType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;dogType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;breed&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;breed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;breed&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;Given that, we have the function below that takes in an object of the class PetType as an argument and then calls the print method(function) of the object. &lt;/p&gt;

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

void callPrint(PetType&amp;amp; p){
    p.print();
}


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

&lt;/div&gt;

&lt;p&gt;In our main function&lt;/p&gt;

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

&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&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="mi"&gt;3&lt;/span&gt;   &lt;span class="n"&gt;PetType&lt;/span&gt; &lt;span class="n"&gt;pet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Lucky"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//Lin&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt;   &lt;span class="n"&gt;dogType&lt;/span&gt; &lt;span class="nf"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Tommy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"German Shepherd"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt;   &lt;span class="n"&gt;pet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;   &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt;   &lt;span class="n"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="mi"&gt;8&lt;/span&gt;   &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"*** Calling the function callPrint ***"&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;9&lt;/span&gt;   &lt;span class="nf"&gt;callPrint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt;  &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;11&lt;/span&gt;  &lt;span class="nf"&gt;callPrint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;12&lt;/span&gt;  &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;13&lt;/span&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

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

&lt;p&gt;Now you may think the output of line 7 and line 11 of the codes in the main function may run to give us the same output. From the output of running the program you realize line 7 prints out &lt;strong&gt;Tommy&lt;/strong&gt; on one line and &lt;strong&gt;German Shepherd&lt;/strong&gt; on another line but line 11 prints out just &lt;strong&gt;Tommy&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;To explain why this happens: remember, our derived class has 2 print() functions; the one it inherits from the base class and the other that print() that is written in the derived class. Remember in the definition of the callPrint function the parameter type that was assigned to p was of the class PetType and as such the compiler calls the PetType::print() on line 11.&lt;/p&gt;

&lt;p&gt;This is a possible bug that we seek to resolve in C++ in the sense that we want line 11 to have the same output as line 7 and this because the print function related to the  dogType class should print out both the breed and the name variables. &lt;/p&gt;

&lt;p&gt;In the definition of the print function in the base class, we could prefix that the declaration with the virtual keyword. &lt;/p&gt;

&lt;p&gt;By marking a function as "virtual," you indicate to the compiler that the function should be dynamically bound at runtime, which means the correct implementation of the function will be determined based on the actual object type.&lt;/p&gt;

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

&lt;span class="c1"&gt;//Modification In the PetType class&lt;/span&gt;
&lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;With this slight modification in the base class, our output becomes&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Importance of Virtual Function
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Virtual functions are important because they enable you to write more flexible and extensible code. They allow you to design base classes with certain behaviors while leaving the specific implementation details to derived classes. This promotes code reusability and modularity, as well as simplifies the management of objects with varying behaviors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When a function is prefixed with the virtual keyword, the compiler is instructed to decide the function's behavior based on the object type of the function rather than just the pointer or reference pointing to the function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Abstract Classes / Pure Virtual Functions
&lt;/h2&gt;

&lt;p&gt;Assume we have a shape class with a draw function that draws the shape. This function's implementation is shown below.&lt;/p&gt;

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

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
 &lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="c1"&gt;//Function to draw the shape.&lt;/span&gt;

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


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

&lt;/div&gt;

&lt;p&gt;The shape class serves as the base class for other derived classes such as Rectangle and Oval among others. &lt;/p&gt;

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

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Rectangle&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
 &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="c1"&gt;//Function to draw the rectangle.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Oval&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
 &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="c1"&gt;//Function to draw the oval.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



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

&lt;/div&gt;

&lt;p&gt;Because the definitions of the draw function is more specific to a particular shape, each derived class can provide an appropriate definition of these functions.&lt;/p&gt;

&lt;p&gt;The definition of the base class which is the Shape class requires that we write the definition of the draw function in the base class, but at this point which is in the base class there is no shape to draw. As a result, the draw function of our base class must have no code. How do we resolve this?&lt;/p&gt;

&lt;p&gt;You may have guessed it right, that is, we define the virtual class as stated below:&lt;/p&gt;

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

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;Shape&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;draw&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;There is a disadvantage to defining the function like stated above. In the code above, since we have provided a definition to the draw function of the Shape class, we give users of the class the liberty to create objects of the Shape class and call the draw function on the object when the draw function does nothing. &lt;/p&gt;

&lt;p&gt;In order to prevent this, C++ gives us abstract classes or Pure Virtual Functions. &lt;/p&gt;

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

&lt;p&gt;To make a function a pure virtual function, we declare it as a virtual function and then use the assignment operator to assign the function's declaration to 0.&lt;/p&gt;

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

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
 &lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="c1"&gt;//Function to draw the shape.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Since this function has no definition but it just an abstract class, C++ does not allow objects of this class to be created, but we can create a pointer from the base class that will point to the derived class.&lt;/p&gt;

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

&lt;span class="n"&gt;Shape&lt;/span&gt; &lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="c1"&gt;//errror&lt;/span&gt;
&lt;span class="n"&gt;Shape&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;s2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// No error&lt;/span&gt;


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

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Polymorphism is an important concept of object-oriented programming. It simply means more than one form. That is, the same entity (function or operator) behaves differently in different scenarios.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To make a function virtual, we prefix the function declaration in our base class with the &lt;em&gt;virtual&lt;/em&gt; keyword.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// In our base class&lt;/span&gt;
&lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//Assuming there is a print function in our base class&lt;/span&gt;


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

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Given that the definitions of some functions in the base class are more specific to the derived class, and we want to make that function a pure virtual function, all we need to do is set the function's declaration to 0.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;span class="c1"&gt;// In our base class&lt;/span&gt;
&lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="o"&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;Hey guys😊 Elvis here, Don't forget to  ask all your questions in the comment section right below. Like and share this please🥲. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy Coding out there&lt;/strong&gt;&lt;/p&gt;

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

</description>
      <category>oop</category>
      <category>cpp</category>
      <category>beginners</category>
      <category>polymorphism</category>
    </item>
    <item>
      <title>Mastering Background Image Darkening with CSS: Simple Yet Effective Techniques</title>
      <dc:creator>Gyau Boahen Elvis</dc:creator>
      <pubDate>Thu, 27 Jul 2023 17:52:43 +0000</pubDate>
      <link>https://dev.to/gyauelvis/mastering-background-image-darkening-with-css-simple-yet-effective-techniques-1cmn</link>
      <guid>https://dev.to/gyauelvis/mastering-background-image-darkening-with-css-simple-yet-effective-techniques-1cmn</guid>
      <description>&lt;p&gt;Upon scrolling through amazing landing page designs on &lt;strong&gt;Behance&lt;/strong&gt; I found myself googling how to darken background images with CSS because I wanted to build a page like the one below.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foss36y961c75ty8gbfmr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foss36y961c75ty8gbfmr.jpg" alt="A landing page with darkened background image"&gt;&lt;/a&gt;&lt;br&gt;
I went through a few posts on &lt;strong&gt;Stack overflow&lt;/strong&gt; and the answers were so overwhelming. I then decided to ask &lt;strong&gt;ChatGPT&lt;/strong&gt; how I would darken my background image with CSS. The answers Stack Overflow suggested were not so different from what ChatGPT's answers. Both suggested I use an overlay then apply the background-color property to the overlay and set it to rgba(0,0,0,0.7). They also suggested I use the filter property which ended up reducing the brightness of the text on the page too. Another suggestion was that I use before or after pseudo-elements. &lt;/p&gt;

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

&lt;p&gt;As a beginner who is not so comfortable with these concepts, I decided to read on the various background image and background color properties on &lt;a href="https://developer.mozilla.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Mozilla Developer Network&lt;/strong&gt;&lt;/a&gt; and found the two-line secret to darkening background images.&lt;/p&gt;

&lt;p&gt;But before that let's go through using the various concepts suggested by ChatGPT and Stack overflow to darken our background image. &lt;br&gt;
Throughout this article this the HTML codes we will be using&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="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&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;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Document&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"style.css"&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;main&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;"text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lorem ipsum dolor sit amet consectetur adipisicing elit. Ullam, laudantium.&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/main&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;A few CSS Styling to make our work look nice&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&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;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url("./img/workspace-gdfb557ae9_1280.jpg")&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-repeat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;no-repeat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&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;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="nc"&gt;.text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&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="nb"&gt;xx-large&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This the link to the background image we will be using in this article &lt;a href="https://pixabay.com/photos/workspace-laptop-mockup-photoshop-2443050/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;strong&gt;Using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/filter" rel="noopener noreferrer"&gt;FILTER&lt;/a&gt; CSS Property&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's add this piece of code to our CSS styling we have above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;brightness&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;-webkit-filter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;brightness&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;50%&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://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vcaeev4dur08pyta3px.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vcaeev4dur08pyta3px.jpeg" alt="The result after applying the filter CSS property"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is one of the easiest techniques of darkening your background image. The only disadvantage to this technique is that it reduces the legibility of the text on your page. &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/::before" rel="noopener noreferrer"&gt;::before&lt;/a&gt; pseudo-elements
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;100vw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&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="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="nc"&gt;.text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20&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://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi1j0oyz04dyv6mriudqd.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi1j0oyz04dyv6mriudqd.jpeg" alt="The result after using the ::before pseudo-element"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For just darkening your background image while making sure the texts on the page are legible, this just too much from my point of view and probably every beginner's point of view. It contains so many concepts that may be difficult for beginners to grasp.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-blend-mode" rel="noopener noreferrer"&gt;background-blend-mode&lt;/a&gt; CSS Property
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;main&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="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="py"&gt;background-blend-mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;darken&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This the simplest and the most effective way of darkening your background image while making sure your texts on your page are legible. &lt;/p&gt;

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

&lt;p&gt;There are several methods to darken a background image using CSS, but the most effective and beginner-friendly approach is by using the background-blend-mode property with the value of darken. This method allows you to darken the background image without affecting the text's legibility on the page.&lt;/p&gt;

&lt;p&gt;Here's the final CSS code using the background-blend-mode property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url("./img/workspace-gdfb557ae9_1280.jpg")&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-repeat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;no-repeat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&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;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&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="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;background-blend-mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;darken&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="nc"&gt;.text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&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="nb"&gt;xx-large&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;



</description>
      <category>webdev</category>
      <category>css</category>
      <category>beginners</category>
      <category>html</category>
    </item>
  </channel>
</rss>
