<?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: Daniel J</title>
    <description>The latest articles on DEV Community by Daniel J (@danielj).</description>
    <link>https://dev.to/danielj</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%2F1138027%2Fa5f07fec-a973-460a-a754-42c37070dfab.jpeg</url>
      <title>DEV Community: Daniel J</title>
      <link>https://dev.to/danielj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danielj"/>
    <language>en</language>
    <item>
      <title>Ascii Art via the Command Line</title>
      <dc:creator>Daniel J</dc:creator>
      <pubDate>Tue, 02 Jan 2024 13:47:47 +0000</pubDate>
      <link>https://dev.to/danielj/ascii-art-via-the-command-line-147m</link>
      <guid>https://dev.to/danielj/ascii-art-via-the-command-line-147m</guid>
      <description>&lt;p&gt;There is something truly special about creating something visually using technology. The ability to use a bunch of binary digits to make something visually appealing for us humans. It's something so far removed from the original idea behind computer systems that it reminds me of the vast and endless opportunities we have as intelligent beings. That being said, it must be pointed out, the juxtaposition between working in a command line interface, and displaying some sort of art or image by using ASCII characters in said interface that's designed to be text based. Pushing the limits of technology is how we got to this point in the first place.&lt;/p&gt;

&lt;p&gt;The American Standard Code for Information Interchange (ASCII) is an encoding standard for communication between electronic devices. It was originally created out of a need for standardizing the communication's sent and received by our devices. It was used to encode up to 128 characters into different 7 bit integers. This was incredibly important and necessary to make our systems uniform and compatible. These days Unicode has taken the place of our standard encoding system and offers millions of code points compared to ASCII's 128, but the concept of using text characters to create art lives on.&lt;/p&gt;

&lt;p&gt;Originally, there was an artistic use to ASCII characters that was created near it's inception. It came due to the unreliability and imprecisions of modern day printers at the time. In the 60's and 70's printer technology wasn't nearly as good as it is today, they certainly weren't able to tweet off of their dot matrix printers like we can today with certain models. The resolution for image printing was difficult to get right and often not possible. In turn the idea was born to use dot's and other ascii characters to draw a larger image, producing higher resolution images than most standard printers. &lt;br&gt;
This is an image printed in 1961 using a teleprinter&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qUCdpAeE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34ek60hju5pp70w7fgix.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qUCdpAeE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34ek60hju5pp70w7fgix.jpg" alt="1961 image of dag" width="330" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These days ASCII art is much more expressive and free, often created as small ascii characters, phrases or pop culture references. The limits don't have to stop there however, as that is a great area of overlap for art and technology. Pushing the limits of what we have to create things we didn't think we could like creating art inside of our terminal! We can create something small and fun like the fortune | cowsay terminal packages that give you a "fortune" being told to you by an ascii cow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cO3DJz5I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99lgfbwlxhv9gdkpnmhh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cO3DJz5I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99lgfbwlxhv9gdkpnmhh.png" alt="fortune cowsay" width="459" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alternatively, if you are a math wizard and a programming wizard (AKA knowledge of programming in C), you can make something incredibly complex, like a rotating donut. (I can only show multiple screenshots due to formatting limitations.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IxFaHY_s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3d98pznucikwput2di7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IxFaHY_s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3d98pznucikwput2di7.png" alt="first donut" width="800" height="557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y6FnkGsh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yuxd560sy4zqda3bcjzm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y6FnkGsh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yuxd560sy4zqda3bcjzm.png" alt="second donut" width="800" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8YvBIm7p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4myzfmunn40trmuez7ho.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8YvBIm7p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4myzfmunn40trmuez7ho.png" alt="Third Donut" width="800" height="578"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ascii</category>
      <category>cli</category>
      <category>terminal</category>
      <category>programming</category>
    </item>
    <item>
      <title>Esoteric Programming Languages</title>
      <dc:creator>Daniel J</dc:creator>
      <pubDate>Mon, 11 Dec 2023 13:33:35 +0000</pubDate>
      <link>https://dev.to/danielj/esoteric-programming-languages-2340</link>
      <guid>https://dev.to/danielj/esoteric-programming-languages-2340</guid>
      <description>&lt;h2&gt;
  
  
  At the heart
&lt;/h2&gt;

&lt;p&gt;of programming lies the desire to create things. Whether it be for work, for fun, work or artistic purposes, we love to build functional things using computers. What happens though when we attempt to push the boundaries of what we understand programming to be? Today I'll cover some examples of just how far we can programming with rules, syntax and ideas that will make you question just how exactly someone could come up with something like an esoteric (programming) language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hNVwUu5z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oov7iw3onebxixy2oeiz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hNVwUu5z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oov7iw3onebxixy2oeiz.png" alt="brainf*ck helloworld" width="800" height="36"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may think to yourself, this seems like a weird line break to separate paragraphs, and you'd be right because it's not intended for that purpose. That line is the 'Hello World' test in what is likely the most popular esoteric language "BrainF**k". Your next thought is probably '...how?', which brings me to the purpose. Esoteric programming languages(esolangs), are not built for practical applications. The idea is to be creative and push the boundaries of what we know programming is, while ideally maintaining a system that is Turing-complete. This means that a language would be compatible with any turing system to manipulate, read and set data sets. This throws a pretty wide net for what can be usable, and makes the 'hello world' test a great benchmark for esolangs.&lt;/p&gt;

&lt;h2&gt;
  
  
  That being said,
&lt;/h2&gt;

&lt;p&gt;creating an esolang gives you the creative freedom to make your own rules. These rules are often convoluted for the sake of being unique or incomparable with any other programming languages. The same can be said for the syntax, design decisions and essentially everything when it comes down to esolang design. I'll be going over some esolang specific designs that I particularly enjoy due to the parody of them. As previously mentioned, "Brainf**k" is the most well known or most popular esolang and has inspired countless other esolang's with it's syntax and rules. It's standard setup accounts for around 30,000 cells, all set to 0 with a pointer pointing to the first cell. You can then move the pointer up and down the cells with commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4fk9XJGh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uqd4mhnpbholo2axt8a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4fk9XJGh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uqd4mhnpbholo2axt8a.png" alt="brainf**k commands" width="573" height="322"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, you manipulate the location of the pointer and alter the subsequent cell's byte value to represent a value inside of that cell. Here is another image from the esolang wikipedia that goes more in depth about the hello world example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cR5d3Yfp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxjh4es6lg9upbkx1yi0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cR5d3Yfp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxjh4es6lg9upbkx1yi0.png" alt="hello World detailed" width="619" height="763"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is essentially all downhill from here. This as previously mentioned this esolang inspired and fathered many other's that derived their structure from brainf*ck. Here are a list of commands for a language that is near identical to brainf*ck but changes the keywords and commands to "orangutan sounds".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PCr2zImx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/864x4w66cw95olv838hp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PCr2zImx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/864x4w66cw95olv838hp.png" alt="Ook!" width="619" height="308"&gt;&lt;/a&gt;&lt;br&gt;
It substitutes the special characters with different syntax for ook's to denote different commands. This makes for an especially verbose version of brainf**k that takes this to write "Hello World!"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y6ojo9jn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68brtydms2y6wvhq1s26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y6ojo9jn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68brtydms2y6wvhq1s26.png" alt="Ook hello world" width="620" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last language I want to cover is called "Malbolge", promptly named after the 8th circle of hell in Dante's inferno approaches this concept from an almost cryptographic standpoint. This is "Hello World!" in Malbolge.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eRGeuDms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1dddbjhcszblvxms714.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eRGeuDms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1dddbjhcszblvxms714.png" alt="Hello World in Malbolge" width="800" height="42"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the more cryptic proof of concept esolang, implementing extremely unique rules and instructions to make the language even usable. This is a list of all the instructions in malbolge, which are chosen by an equation. Malbolge has three processor registers that are each set to 0 at the start of the program. Each are responsible for different things and are denoted by &lt;strong&gt;a, c and d&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oICGsR_a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rgkc5bjm0kxyrgp7lv5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oICGsR_a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rgkc5bjm0kxyrgp7lv5.png" alt="Malbolge instruction" width="800" height="348"&gt;&lt;/a&gt;&lt;br&gt;
This language wasn't always Turing-complete and took other developer's interest in revamping things like a memory limit in order to make it work fully functionally. It's also important to note that a non-terminating loop wasn't even able to be performed until 2005, 7 years after it was created. It has gone through different iterations by other developers that made it more usable but still under the same umbrella idea that Malbolge was formed under. Malbolge has many more difficult and convoluted rules to follow that I won't be covering, but serves as a reminder of the proof of concept ideals that fall under the esolang category.&lt;/p&gt;

&lt;h2&gt;
  
  
  There is a common theme
&lt;/h2&gt;

&lt;p&gt;amongst these esolangs that speaks most to me in the parody and creative freedom. Since entering into the software developing world, I'd always had an interest in creating my own functional programming language. I'd initially wanted to create something convoluted, silly and not necessarily practical which is really what sparked my curiosity in esolangs. I encourage anyone who may feel like programming is too rigid or serious to take a look at the &lt;a href="https://esolangs.org/wiki/Main_Page"&gt;esolang wiki&lt;/a&gt; to check out how far we can test the limits of our systems.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Intro to Async / Await Syntax</title>
      <dc:creator>Daniel J</dc:creator>
      <pubDate>Thu, 30 Nov 2023 21:21:36 +0000</pubDate>
      <link>https://dev.to/danielj/intro-to-async-await-syntax-3bic</link>
      <guid>https://dev.to/danielj/intro-to-async-await-syntax-3bic</guid>
      <description>&lt;h2&gt;
  
  
  If
&lt;/h2&gt;

&lt;p&gt;you’ve spent any time coding in javascript on the back end of an application, you’re likely familiar with “promises”. If you aren’t familiar with promises as they relate to javascript, or code, they are essentially used to represent the eventual invocation/success/failure of an asynchronous function. An asynchronous function or operation is one that does not run at the time of interpretation, and can run in parallel with other operations. Synchronous code on the other hand runs one at a time without any ability to send more than one request at a time.&lt;br&gt;
Asynchronous programming is at the heart of our backend technologies as it allows for us to designate “nets” of asynchronous code to catch incoming or outgoing requests as well as send multiple requests at any time. The anatomy of a promise follows that of a function for the body, however we can use .then at the end of the function call to designate what happens next to the returned value of the promise. We simply name the returned value whatever we want and manipulate it in our .then block to make a promise chain. This can be anything from displaying something to a user on the client side to sending another request to another endpoint. When working with promises and asynchronous code, we need to ensure a good development experience by handling errors. With the setup of promises we need to handle errors that may arise as if we don’t, we will simply not get any information back to debug our code. We do this by using a .catch block after our .then block to handle any errors that may arise from our promise resolution. The beauty in promises is that they are always there, waiting to be used by our applications or users to handle the magic behind the scenes. All this to say there are issues that come from traditional promise chains. This is an issue that pertains to a lot of asynchronous code, that being illegibility. Asynchronous code can be large, daunting and difficult to read or follow. Programmers young and old have experienced the triangle of doom, a tale as old as time, stuck in callback hell. That is where Es6 saves the day. Upon the release of ES6 or ECMAScript(2015), the introduction of async/await syntax graced us. A new way to write promises that severely reduced the difficulty and intimidating stature of traditional promises. Async / await are essentially the same as promises but offer shorter, more concise code. It helps make the jungle of asynchronous code much more manageable, it may not seem like much, but when you’re looking at thousands of lines of async code, the benefits this syntax offers is unparalleled. This new syntax can be difficult for new programmers to pick up on top of the already relatively confusing idea of how promises work. The main syntactic difference is that you must declare a function asynchronous with the async keyword in the function declaration, and the blocks for then and catch would now be try and catch. Along with this comes the ability to use the await keyword to tell our program in these blocks to await the resolution of a promise and assign it to a variable, which also does away with the required use of Promise.all for multiple promises. All in all, there are some minor differences between the two, but it’s worth learning to save on the potential time waste and headache that can come with gigantic promise chains.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>promise</category>
      <category>backenddevelopment</category>
      <category>asynchronous</category>
    </item>
    <item>
      <title>Intro to Async / Await Syntax</title>
      <dc:creator>Daniel J</dc:creator>
      <pubDate>Mon, 27 Nov 2023 13:20:51 +0000</pubDate>
      <link>https://dev.to/danielj/intro-to-async-await-syntax-2g1h</link>
      <guid>https://dev.to/danielj/intro-to-async-await-syntax-2g1h</guid>
      <description>&lt;p&gt;If you’ve spent any time coding in javascript on the back end of an application, you’re likely familiar with “promises”. If you aren’t familiar with promises as they relate to javascript, or code, they are essentially used to represent the eventual invocation/success/failure of an asynchronous function. An asynchronous function or operation is one that does not run at the time of interpretation, and can run in parallel with other operations. Synchronous code on the other hand runs one at a time without any ability to send more than one request at a time.&lt;br&gt;
Asynchronous programming is at the heart of our backend technologies as it allows for us to designate “nets” of asynchronous code to catch incoming or outgoing requests as well as send multiple requests at any time. &lt;/p&gt;

&lt;h2&gt;
  
  
  The anatomy of a promise
&lt;/h2&gt;

&lt;p&gt;follows that of a function for the body, however we can use .then at the end of the function call to designate what happens next to the returned value of the promise. We simply name the returned value whatever we want and manipulate it in our .then block to make a promise chain. This can be anything from displaying something to a user on the client side to sending another request to another endpoint. When working with promises and asynchronous code, we need to ensure a good development experience by handling errors. With the setup of promises we need to handle errors that may arise as if we don’t, we will simply not get any information back to debug our code. We do this by using a .catch block after our .then block to handle any errors that may arise from our promise resolution. &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%2F8cxnle0mjnjdmdtuu6uh.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%2F8cxnle0mjnjdmdtuu6uh.png" alt="promise example"&gt;&lt;/a&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%2F8hkr9szzmr9pjfeqt0md.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%2F8hkr9szzmr9pjfeqt0md.png" alt="result log"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The beauty in promises is that they are always there, waiting to be used by our applications or users to handle the magic behind the scenes. All this to say there are issues that come from traditional promise chains. This is an issue that pertains to a lot of asynchronous code, that being illegibility. Asynchronous code can be large, daunting and difficult to read or follow. Programmers young and old have experienced the triangle of doom, a tale as old as time, stuck in callback hell. &lt;/p&gt;

&lt;h2&gt;
  
  
  This is where Es6 saves the day.
&lt;/h2&gt;

&lt;p&gt;Upon the release of ES8, the introduction of async/await syntax graced us. A new way to write promises that severely reduced the difficulty and intimidating stature of traditional promises. Async / await are essentially the same as promises but offer shorter, more concise code. It helps make the jungle of asynchronous code much more manageable, it may not seem like much, but when you’re looking at thousands of lines of async code, the benefits this syntax offers is unparalleled. This new syntax can be difficult for new programmers to pick up on top of the already relatively confusing idea of how promises work. The main syntactic difference is that you must declare a function asynchronous with the async keyword in the function declaration, and the blocks for then and catch would now be try and catch. Along with this comes the ability to use the await keyword to tell our program in these blocks to await the resolution of a promise and assign it to a variable, which also does away with the required use of Promise.all for multiple promises. All in all, there are some minor differences between the two, but it’s worth learning to save on the potential time waste and headache that can come with gigantic promise chains.&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%2Fpa8gulo0hijrk9cvhwlu.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%2Fpa8gulo0hijrk9cvhwlu.png" alt="async example&amp;lt;br&amp;gt;
"&gt;&lt;/a&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%2F6a7enf90p0rgv3z7zb56.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%2F6a7enf90p0rgv3z7zb56.png" alt="async example result"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>promise</category>
      <category>backenddevelopment</category>
      <category>asynchronous</category>
    </item>
    <item>
      <title>Data Encyption</title>
      <dc:creator>Daniel J</dc:creator>
      <pubDate>Mon, 16 Oct 2023 13:24:10 +0000</pubDate>
      <link>https://dev.to/danielj/data-encyption-3jbp</link>
      <guid>https://dev.to/danielj/data-encyption-3jbp</guid>
      <description>&lt;p&gt;&lt;strong&gt;Encryption&lt;/strong&gt; is a cryptographic act of taking a message and scrambling it to form another message to hide the contents of the original message. This principle plays a crucial role in our day to day lives in the form of data encryption. Because the internet is an open and public place, we need a way to secure our messages and private data that we transmit through the internet. It helps maintain security in our computer systems and applications to avoid having our sensitive private information secure on the web. So how exactly does our data go from plain text to cipher text(encrypted text), and how does that benefit me?&lt;/p&gt;

&lt;p&gt;Before talking about data encryption as we know it today, it's important to know what came prior to what we have today as well as some key definitions. A message is encrypted into a certain number of bits, depending on the type of encryption, symmetric encryption works by breaking up the message into 64 bits, the length of the bit string is the block size. Without delving too deep into its history, data encryption up until 2001 was handled by the Data Encryption Standard. This standard was a symmetric key algorithm, meaning that the same key that was used to encrypt the message into cipher text, is the same key that is used to decrypt the message into plain text. This encryption standard has a 56 bit encryption key, meaning that they possible number of permutations being 2 to the 56th power. This should not be confused with the block sizes, as that refers to the number of blocks per stream ciphers, meaning the message that is being transmitted. This may sound like a lot but compared to what we use today, it pales in comparison. Modern computers are able to brute force decryption for 56 bit encryption much faster than computers during the time for Data Encryption Standard.&lt;/p&gt;

&lt;p&gt;Symmetric encryption presents an issue as far as decryption goes, along with its small bit size, it's also impractical and inefficient to have two keys that share the same password between two parties. In enters Asymmetric encryption, specifically as it pertains to the Advanced Encryption Standard being combined with RSA encryption. AES uses a symmetric block cipher to store its 128 bits of data, and it's decryption keys have the option of being 128, 192, or 256 bits long, with each bit more being more secure than the last. This encryption method solves this issue in that it uses a mathematical algorithm to generate two separate keys, a public and a private key. There are many different algorithms used to generate keys, the most popular being RSA Say you want to send a message to your friend Bob and you don't want anyone else to read it. If Bob shares his public key with you, you can use it to send him the message, and in transmittal it will be encrypted so that no one can intercept that message or read it. The only way it can be decrypted, is with Bob's private key. This is because his public key is generated mathematically to match his private key so that only he can access any information transmitted to him. This is the key principle behind encryption and prevents antiquated technologies like DES. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W-xtB2B7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqkhj3tle7pq7qftdv0d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W-xtB2B7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqkhj3tle7pq7qftdv0d.png" alt="asymmetric key" width="684" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This RSA/AES encryption is used in every aspect of our data encryption today, anything you can think of that you use on a day to day basis is probably encrypted in AES, and if it isn't, your data is probably extremely vulnerable. Take for instance, HTTPs, this uses AES and if you dare venture to a site without it, you've probably received a warning message or two telling you that the site is unsecure. This is true for now, but with the advancement of technology, which seems to be logarithmically increasing every year, computers will soon catch up with AES in the same way that it did with DES. Once that happens, it's a scramble to standardize as much of the internet as possible to ensure that we all remain safe when we have access to things like quantum computers that can break AES encryption in minutes or seconds. This reality seems to be a very far way away, as even now, quantum computers are not widely available, and generally reserved for labs or universities. Quantum encryption standards seem to be the next frontier for encryption standards, as quantum computers can perform around a million computations at once while our normal computers can only do one at a time.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A short introduction to Penetration testing</title>
      <dc:creator>Daniel J</dc:creator>
      <pubDate>Mon, 09 Oct 2023 13:10:43 +0000</pubDate>
      <link>https://dev.to/danielj/a-short-introduction-to-penetration-testing-1jd6</link>
      <guid>https://dev.to/danielj/a-short-introduction-to-penetration-testing-1jd6</guid>
      <description>&lt;p&gt;As technology continues to grow and become a more and more integral part of our lives, so grows the need to keep that technology secure and safe for consumers. Whether it's cameras in our homes connected to wifi being tapped into, or the data being transmitted between companies being intercepted, cyber security continues to be paramount in our day to day lives to protect us from these insidious possibilities. We are reminded too frequently of how important this is with horror stories of data breaches, as recent as this past week, &lt;a href="https://fortune.com/2023/10/06/23andme-user-data-hacked/"&gt;23andMe had a data breach that is affecting millions of their users&lt;/a&gt;, having their profiles information listed for sale on shady online marketplaces. The information stolen included the users profile, gender, email address, photos, date of birth and ancestry information. These sorts of data breaches are a nightmare, and they are not exclusive to consumer companies either. Back in June of 2023, the &lt;a href="https://gov.louisiana.gov/index.cfm/newsroom/detail/4158"&gt;Louisiana Office of MotorVehicles(OMV) suffered a data breach&lt;/a&gt; that saw every single Louisiana resident with a state issued driver's license, ID or vehicle registration. The data stolen included, names, addresses, social security numbers, driver's license number, vehicle registration info, and more. This data breach occurred specifically by using a popular third party application called MOVEIt used for transferring large files. Targeting third party applications that other companies pay licensing for around the world to use  are a common attack vector for people who are trying to steal data. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So what can we do to deal with such attacks?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Penetration Testing,&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
also referred to as pen testing is a simulated cyber attack, typically done by a company that specializes in it. The simulated attack doesn't always have to be cyber, there are also physical pen testers who will be tasked with breaking into a companies facilities and making a physical extraction of data. If you've worked for a company where you have an email attached to your employment, it's likely you have experienced a very small scale form of pen testing in automated phishing emails. As silly as those things might be, they are extremely important in keeping companies secure as they can train their employees to identify suspicious emails and attachments. This is especially important as research by Deloitte found that &lt;a href="https://www.yeoandyeo.com/resource/91-of-cyberattacks-begin-with-a-phishing-email#:~:text=Research%20by%20Deloitte%20found%20that,billion%20user%20accounts%20to%20criminals."&gt;91% of all cyber attacks begin with a phishing email&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;When a penetration testing company sets up an agreement with a consumer company, they usually have a contract. This contract states the guidelines for the penetration test, where they can and can't enter, the information that they would want to see if they could access(if any specifically), as well as any edge cases or constraints that the requesting company would like to place on them like whether it would come from a phishing attempt or an exploitation attempt on their software or application. The guidelines to the contract ensure that both parties remain safe legally as it is extremely likely that they will be handling secure information in their attempted extraction. This step will also be defining in the next steps as this part will also go over the scope of the penetration test.&lt;/p&gt;

&lt;p&gt;The next step in this process is open source intelligence or Opsec, as well as figuring out the attack vector, contingent on the contract and it's restraints. If a company wants pen testers to gain entry solely through phishing attempts, it would be more specific in that spear phishing would be the route to take. Spear phishing is the same concept as phishing however it is designed to be specific to an individual to create believability and induce trust for the targeted person to feel safe in clicking it. This works startlingly well, as when we recognize an email that seems suspicious, but they include details about us personally that show that this person knows us (or of us), then we are more likely to fall into the trap. Opsec comes into play here in a big way, what if they might have something pertinent to our linkedin job interests, all of a sudden this suspicious email surely would be real and not an attempt at gaining access to our systems. Penetration testers will often have a tool kit with a variety of different proprietary software to aid in their tasks, along with other pen testing specific products that make their job a lot easier. If a pen tester can get their foot in the door, and get higher level clearance through their chosen attack vectors, the job becomes a whole lot easier. &lt;/p&gt;

&lt;p&gt;Once inside, it can be extremely hard for people in the IT department to combat this intruder, especially if this is a blind pen test where the employees are not aware that they are being tested by the company to see if they can protect their data. This is important as a lot of penetration tests will include maintaining control of the systems, to check and see how long they can stay inside and remain unfound, untouched and unnoticed. Dependent on the situation, some pen tests will want extraction and then exit, but most of the time, a company will want to see how long an intruder could remain in their system without raising alarm bells. &lt;/p&gt;

&lt;p&gt;By the end of this entire process, whether they're found out or not, the penetration testers will compile a report that has details of their assessment. This assessment will usually contain information on attack vectors or strategies used in their attack, their specific point of entry, what information they were able to take or what damage they were able to cause, and how long they were able to remain in the system without being noticed or removed. There will be various details and recommendations included by the penetration testers and sometimes even a rating.&lt;/p&gt;

&lt;p&gt;Penetration tests are extremely important, invaluable services as they provide a real time simulation of a potential catastrophic and preventable situation. This obviously is a great benefit as the data is not actually being stolen, and their systems are not actually in danger. However if the company does poorly, it is a scary indicator that they would need to instill better practices in their employees or better security measures for their applications.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>An introduction to Webscraping (with python)</title>
      <dc:creator>Daniel J</dc:creator>
      <pubDate>Mon, 02 Oct 2023 13:45:37 +0000</pubDate>
      <link>https://dev.to/danielj/an-introduction-to-webscraping-with-python-3fg5</link>
      <guid>https://dev.to/danielj/an-introduction-to-webscraping-with-python-3fg5</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Webscraping&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;is a concept that has existed since the inception of the internet. It is known by many other names, (web based) data extraction, data harvesting, web crawling and many more. A webscraper is a program that's sole purpose is to do exactly those things, target a website (or websites) and crawl through it's HTML elements to extract data that we want to see. It's not unreasonable to see this explanation and think to yourself:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So...like...browsing the web? Through a program? What's so great about that?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well there are so many great things about it but the main idea behind it is automation! As human beings not only do we experience life, often without a lot of time to browse the web for everything we want or need, but we experience fatigue in repetitive tasks. For example, imagine for a moment you spend 8-12 hours a day working, with minimal time to take care of things in your personal life. You do everything you can but are left with practically no time to browse the web for products you want or maybe even need in order to help your workflow. Luckily for you, you know a little bit of python and are a pro at googling, so enter in your little automated webscraper to save the day.&lt;/p&gt;

&lt;p&gt;Stepping back from the example for a moment, there are pros and cons to be had with webscraping that are important to understand before delving into an example.&lt;br&gt;
Pros:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Saves time and headache by automating any data you want to find on the web.&lt;/li&gt;
&lt;li&gt;Can be &lt;strong&gt;completely&lt;/strong&gt; automated, in that we can set our webscraper up to grab data by the second, minute, hour, day etc..&lt;/li&gt;
&lt;li&gt;Depending on the reason for data collection, this can give you a huge edge over others if for instance you're searching for a product that is not frequently in stock.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic websites make for a hard time with webscrapers.&lt;/li&gt;
&lt;li&gt;A webscraper is essentially a bot, something that is not exactly liked by many sites you may try to scrape data from.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That being said, I'll be using a static test website created by &lt;a href="https://webscraper.io/"&gt;Webscraper.io&lt;/a&gt;, the link to the specific test site can be found &lt;a href="https://webscraper.io/test-sites/e-commerce/allinone/computers/laptops"&gt;here.&lt;/a&gt; Feel free to visit the test site and inspect the HTML to see for yourself the elements we'll target for this webscraper. This is the first step to building any webscraper as this is how we will tell it where to grab data from.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RSn2bhUK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1plk3zona6ney9mfj6c3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RSn2bhUK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1plk3zona6ney9mfj6c3.png" alt="HTML first image" width="800" height="344"&gt;&lt;/a&gt;&lt;br&gt;
Using our element selector tool, we test the waters to see what the title of the first product looks like in the html, and we see it's an "a" tag with a class of "title". This is a great start to figuring out what pieces of information we want, but it still isn't good enough. We want to zoom out and find the div storing all of the products on the page, not just the specific one we initially targeted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RENC5KNk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wnypdtzazd6fy2l8dyru.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RENC5KNk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wnypdtzazd6fy2l8dyru.png" alt="Product div" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is perfect! We see now that the div storing all of the product information on the test page is stored under a class of "col-md-9". This is the div we will want to isolate to break down all the data inside it and get what we're looking for! Looking over to our code editor, I'm creating this webscraper using python as well as 3 different libraries. To start we'll be using the &lt;a href="https://pypi.org/project/requests/"&gt;requests&lt;/a&gt; library for our HTTP requests and the &lt;a href="https://pypi.org/project/beautifulsoup4/"&gt;BeautifulSoup&lt;/a&gt; library for the actual scraping of data. For the sake of read time, pseudocode is included to explain what is happening in the code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bJ68DOQz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ayljgatx3yjom9v37j1l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bJ68DOQz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ayljgatx3yjom9v37j1l.png" alt="IDE setup" width="800" height="146"&gt;&lt;/a&gt;&lt;br&gt;
Now that we've completed the setup, we can target the div that stores all the product data using BeautifulSoup's find function. Once it's stored, we can use find_all to grab all the instances of title classes, price classes, description classes and ratings classes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qtLIOYLF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tscscv3grplggsn89mhb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qtLIOYLF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tscscv3grplggsn89mhb.png" alt="Code ex" width="800" height="270"&gt;&lt;/a&gt;&lt;br&gt;
Since we've scraped all the data we're looking for, its time to print it to see what it looks like!&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--435Lzxwq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1854ect92l5e9td2n1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--435Lzxwq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1854ect92l5e9td2n1p.png" alt="results" width="800" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SRYrAJgc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bqe4b4rp9bj6h7b913m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRYrAJgc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bqe4b4rp9bj6h7b913m.png" alt="results 2" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voila! We now have a printed table in our terminal containing each of those things in a nice legible list. You can do all sorts of things from here, changing the products you scrape to be only of a certain rating, titles containing a certain brand, the possibilities are endless! Although now we have all this data we wanted, the terminal isn't exactly the prettiest place to view all of it. Here is where our third library comes in, &lt;a href="https://pandas.pydata.org/"&gt;Pandas.&lt;/a&gt; Pandas is a data analysis library for python that we can use to extrapolate our data into a more legible format. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--puUwy0EX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ouhfcmj5ot84cj7aqxvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--puUwy0EX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ouhfcmj5ot84cj7aqxvy.png" alt="pandas code" width="800" height="310"&gt;&lt;/a&gt;&lt;br&gt;
Lastly, all we need to do is export our data frame that we created with pandas to a csv file for readability.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lFaXXAby--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4j3q80ztsiclc9f64k8k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lFaXXAby--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4j3q80ztsiclc9f64k8k.png" alt="csv" width="800" height="334"&gt;&lt;/a&gt;&lt;br&gt;
We now have access to a nice spreadsheet of 117 rows with the 4 columns of Title, Price, Description and Ratings, with barely any code! The same process can be applied to almost any static website, but the real challenge comes with dynamic websites. There are other methods to scrape such websites but that'll be covered in an upcoming blog where I'll be using &lt;a href="https://www.selenium.dev/selenium/docs/api/javascript/index.html"&gt;Selenium&lt;/a&gt; in tandem with some of the same tech used in this blog. &lt;/p&gt;

</description>
      <category>python</category>
      <category>webscraping</category>
      <category>programming</category>
      <category>beautifulsoup</category>
    </item>
    <item>
      <title>Repetition can make you loopy!: Intro to JavaScript Loops</title>
      <dc:creator>Daniel J</dc:creator>
      <pubDate>Mon, 14 Aug 2023 14:27:13 +0000</pubDate>
      <link>https://dev.to/danielj/repetition-can-make-you-loopy-intro-to-javascript-loops-11o4</link>
      <guid>https://dev.to/danielj/repetition-can-make-you-loopy-intro-to-javascript-loops-11o4</guid>
      <description>&lt;p&gt;Looping is a concept utilized in most programming languages we use today. The idea behind it is central to what we strive for as programmers, that being minimizing our workload as much as humanly possible. Focusing in on that idea, we can point to the &lt;strong&gt;&lt;em&gt;D.R.Y.&lt;/em&gt;&lt;/strong&gt; principle, otherwise known as "Don't Repeat Yourself," originally coined in &lt;a href="https://www.amazon.com/Pragmatic-Programmer-Anniversary-Journey-Mastery/dp/B0833FBNHV/ref=sr_1_1?keywords=the+pragmatic+programmer&amp;amp;qid=1691883635&amp;amp;sprefix=the+pragmatic%2Caps%2C144&amp;amp;sr=8-1" rel="noopener noreferrer"&gt;"The Pragmatic Programmer"&lt;/a&gt;. After all, why repeat yourself when the computer can do it for you! In this discussion, I'll go over looping in the context of JavaScript with examples using JavaScript and p5js. However, keep in mind that the concept is largely transferrable across other languages that utilize loop structures. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So what is a loop?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A loop is a block of code that performs an action for us a specified - or sometimes unspecified - amount of times. The possibilities become endless with loops, allowing us to create complex programs and avoid Carpal Tunnel Syndrome. JavaScript has a few different loop methods at its disposal, but we'll be going over the 3 most common that you'll come across:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For loops&lt;/li&gt;
&lt;li&gt;For.. in loops&lt;/li&gt;
&lt;li&gt;While loops&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  For loops
&lt;/h2&gt;

&lt;p&gt;A for loop will loop through a collection of data, declaring a starting point, an ending point and an incrementation. The syntax in a for loop looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array [1, 2, 3, 4, 5]

       start          end      increment      
         |             |           |
for (let i = 0; i &amp;lt; array.length; i++) { //be sure to separate by ;
    //do something here
    console.log(array[i])
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;console will log&lt;br&gt;
1&lt;br&gt;
2&lt;br&gt;
3&lt;br&gt;
4&lt;br&gt;
5&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Lets break down this code to better understand what's going on under the hood.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We begin the loop with the &lt;strong&gt;for&lt;/strong&gt; keyword, (who would've thought!) before opening up a parentheses to begin our chain of logic.&lt;/li&gt;
&lt;li&gt;Our starting point is declared with variable keyword declaration &lt;strong&gt;let&lt;/strong&gt; or &lt;strong&gt;var&lt;/strong&gt;. (&lt;strong&gt;IMPORTANT: You can use const but remember it cannot be reassigned.&lt;/strong&gt;) I prefer using let, and in JavaScript, using &lt;strong&gt;i&lt;/strong&gt; as the name of the variable in a for loop is a common naming convention, but it can be anything your heart desires!&lt;/li&gt;
&lt;li&gt;So, we've initiated our for loop. We've told the computer that we want the variable &lt;strong&gt;i&lt;/strong&gt; to be 0 at the start of the loop. Now, we want to tell it when to stop. Once again, this stopping point can be anything you want it to be. However, for this example, we're using the .length array prototype method to indicate that we want the loop to end at the last index of the array. Fun tip about the .length method: using .length allows us to make this loop flexible with an array whose quantity may increase or decrease throughout the program.&lt;/li&gt;
&lt;li&gt;Lastly, we want to indicate our increment amount, which again can be anything! In my above example, I used the ++ operator to indicate i+1.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now let's see an example with different start and stop points, as well as iteration by iteration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; 10; i ++) {
 console.log(i);
};
iteration 1: i=0, 0 is &amp;lt; 10 incr by 1 and log the iteration's value(0)
iteration 2: i=1, 1 is &amp;lt; 10 incr by 1 and log the iteration's value(1)
etc.. 
console will log numbers 1 - 9 as when i = 10 it is no longer less than 10.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  For...in Loops
&lt;/h2&gt;

&lt;p&gt;For...in loops are used to loop through an object's properties to achieve the same result, but for objects! The syntax for a for...in loop looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let car = {
manufacturer: 'BMW',
wheels: 4,
doors: 2
year: 1985
};
for (let key in car) {
console.log(key, car[key])
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expected output for the above code to the console log would be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;manufacturer BMW&lt;br&gt;
wheels 4&lt;br&gt;
doors 2&lt;br&gt;
year 1985&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Let's break it down like an old BMW!&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We start off with our &lt;strong&gt;for&lt;/strong&gt; keyword before opening up some parentheses to declare our variable for the keys in object.(foreshadowing!)&lt;/li&gt;
&lt;li&gt;Next, using a variable declarer of your choice like &lt;strong&gt;let&lt;/strong&gt;, we declare the name we want that variable to have, one of the most common naming conventions being &lt;strong&gt;key/keys&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Here's where that &lt;strong&gt;in&lt;/strong&gt; keyword shines! We use it to tell our computer where to check, that being &lt;strong&gt;in&lt;/strong&gt; the object that is declared after.&lt;/li&gt;
&lt;li&gt;The final piece of the puzzle is the object we're looping through. In the above example, it's the &lt;strong&gt;car&lt;/strong&gt; object. &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  While loops
&lt;/h2&gt;

&lt;p&gt;While loops are probably my least favorite kind of loop. It can excel with small looping quantities and smaller scale programs, but otherwise it's usually not recommended. This loop essentially works by telling the computer to execute some task &lt;strong&gt;while&lt;/strong&gt; x condition is true. The syntax for a while loop looks like this:&lt;br&gt;
&lt;/p&gt;

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

while (i &amp;lt; 10) {
console.log(i);
i++;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Lets break it down, one last time!&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The syntax for this code is pretty straightforward. Outside of the while loop, we declare a variable &lt;strong&gt;i&lt;/strong&gt; and assign it to 0. This is the setup for our while loop that works based off a certain condition remaining true.&lt;/li&gt;
&lt;li&gt;We then use the &lt;strong&gt;while&lt;/strong&gt; keyword to start off, before starting our conditional logic. Here we will say while &lt;strong&gt;i&lt;/strong&gt; is less than 10, we want some block of code to be executed.&lt;/li&gt;
&lt;li&gt;Lastly, and arguably the most &lt;em&gt;important&lt;/em&gt; part about this loop, is the incrementation of &lt;strong&gt;i&lt;/strong&gt; that occurs on the last line of the code block. We need to increment &lt;strong&gt;i&lt;/strong&gt; as if we do not, we will create an infinite loop, since &lt;strong&gt;i&lt;/strong&gt; will remain 0 infinitely.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'm sure by now, you're able to see the utility loops can provide us in our programs. We can pass in collections of data to retrieve information, repeat executable code as much as we want, and stay true to our &lt;strong&gt;D.R.Y.&lt;/strong&gt; principle. &lt;/p&gt;

&lt;h2&gt;
  
  
  Visual examples through p5js
&lt;/h2&gt;

&lt;p&gt;In this last section, I'll be creating some visual examples to show how helpful loops can be. I'll be using &lt;a href="https://p5js.org/" rel="noopener noreferrer"&gt;p5js&lt;/a&gt;, a JavaScript library with functionality for creative coding. That being said, I'll try to give a condensed version of the functions being utilized in the following examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function setup() {
  createCanvas(800, 600);
  background('beige');
}

function draw() {
  translate(width / 2, height / 2);
  rectMode(CENTER);
  noFill();
  rect(0, 0, 400, 400);
  noLoop();//this function is to stop the draw func from looping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This block of code renders a canvas that is 800x600 pixels, and draws a rectangle in the cartesian coordinates (0, 0) and a width and height of (400, 400). It looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmi26k3hg2azggq9zwu7x.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%2Fmi26k3hg2azggq9zwu7x.png" alt="Beige Canvas with Rectangle in middle"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I want you to imagine you have to draw 100 rectangles on this canvas at random x and y coordinates, with random width and height arguments (between 0 and 10) and you have no idea that loops exist (or recursion!). The code would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function draw() {
  noFill();
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  rect(random(width), random(height), random(10), random(10));
  noLoop();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sketch would look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhb7rjuc5ju9t26m91isy.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%2Fhb7rjuc5ju9t26m91isy.png" alt="beige background p5js sketch with 14 random placed rect"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Which is fine and dandy but I stopped after 14 pastes, and you can imagine how painful 100 would be.&lt;/p&gt;

&lt;p&gt;Now lets actually draw 100 rectangles of the same arguments using a for loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function draw() {
//I removed the translate func to allow it to start from the top left of the screen
  noFill();
  for (let i = 0; i &amp;lt; 100; i++) {
  rect(random(width), random(height), random(10), random(10));
  noLoop();
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which produces an image similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fev5aliy6e7k2l9lkxv94.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%2Fev5aliy6e7k2l9lkxv94.png" alt="Beige background p5js sketch with 100 rectangles randomly placed and sized"&gt;&lt;/a&gt;&lt;br&gt;
We can go as far as our computer's strength can take us!&lt;br&gt;
The same loop but with 5,000 rectangles:&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%2Ff3fll7qoq5ttbwmq84x9.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%2Ff3fll7qoq5ttbwmq84x9.png" alt="beige bg 5k rect random size and placement"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This truly puts into perspective how powerful loops can be. That single loop can cut down a theoretically infinite number of lines of typing that same function in less than &lt;strong&gt;5 lines&lt;/strong&gt;. You can read more about &lt;a href="https://p5js.org/reference/" rel="noopener noreferrer"&gt;p5js functionality&lt;/a&gt; to fill in the bits of information on native p5js functions, as well as the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration" rel="noopener noreferrer"&gt;Mozilla Developer Docs&lt;/a&gt; to get more information on loops.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>p5js</category>
    </item>
  </channel>
</rss>
