<?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: Derek Mercedes</title>
    <description>The latest articles on DEV Community by Derek Mercedes (@crossthebluesky).</description>
    <link>https://dev.to/crossthebluesky</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%2F1195766%2Fe6e26b70-c2c3-4a45-aedd-7309312e520c.png</url>
      <title>DEV Community: Derek Mercedes</title>
      <link>https://dev.to/crossthebluesky</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/crossthebluesky"/>
    <language>en</language>
    <item>
      <title>What is "Good" Code? A Developer's Perspective</title>
      <dc:creator>Derek Mercedes</dc:creator>
      <pubDate>Fri, 16 Aug 2024 19:11:21 +0000</pubDate>
      <link>https://dev.to/crossthebluesky/what-is-good-code-a-developers-perspective-2bi7</link>
      <guid>https://dev.to/crossthebluesky/what-is-good-code-a-developers-perspective-2bi7</guid>
      <description>&lt;h2&gt;
  
  
  What is "Good" Code? A Developer's Perspective
&lt;/h2&gt;

&lt;p&gt;When talking to software developers, you'll come across a bunch of jargon to describe code. "Dry", "Elegant", "Sugar", and the like. Shockingly, something you rarely hear used to describe code is "Good". And I think the reason why is because defining what makes code "good" isn't always clear. And as you look at more code, you start to see that every developer has different ideas of what makes good code. Here are my opinions as a developer on what exactly I look for when I look for "Good Code"&lt;/p&gt;

&lt;h2&gt;
  
  
  Readability: The Cornerstone of Quality
&lt;/h2&gt;

&lt;p&gt;First and foremost, good code is readable code. I've spent a lot of time in the algorithm mines, and there are a lot of very concise, elegant solutions to very complicated problems. I've even taken some of those ideas and used them in my own projects. It's a great feeling to solve a nightmare of a problem in only a few lines, at least in the moment of solving. But looking back on your solution weeks or months later (or even just far enough into the project that you haven't thought about that part of your codebase recently), you suddenly find yourself having to pick apart all of the shorthand, the syntactic sugar, and figure out what the hell is actually happening in your code. &lt;/p&gt;

&lt;p&gt;Now imagine that you're working with a team of developers who've spent their time actually making things instead of practicing algorithms (the dream!), and you've sprinkled these clever little solutions all over the code base. The time you may have saved yourself you're now wasting from others, and the bigger your team is, the more time gets cast into the void.&lt;br&gt;
The majority of time spent in a codebase isn't writing it, but reading it. So spend the extra time in the writing, and you'll make dividends in the reading.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Art of Commenting
&lt;/h2&gt;

&lt;p&gt;With my thoughts on readability, you probably think I'm a stickler for extensively commented code. Surprisingly, I think the less commenting your code needs, the better that code is. In most cases a simple one-line explanation of what this segment of code does is far more important than providing a full logical breakdown of your implementation. As your code base gets larger, these succinct comments become valuable not just by serving as "functional chapters" of which sections of the app handles what functionality, but it also makes the complex logic that requires more thorough commenting stand out, highlighting their importance and preventing them from becoming noise (and eventually, tech debt).&lt;/p&gt;

&lt;p&gt;It's important to reiterate: coding time is lost not in the writing of code, but the reading of it. So if you've got code that is perfectly readable as it is, why add another 20-30 seconds of reading time having a comment that says the exact same thing as the code itself?&lt;/p&gt;

&lt;h2&gt;
  
  
  Balancing Reusability and Specialization
&lt;/h2&gt;

&lt;p&gt;The one universal truth of software development is this: the best code is the code you don't have to write. This is used as an axiom to the benefits of reusability and "dry" coding styles. Reusable code promotes efficiency, keeps consistency across the code base, and prevents developers from needing to solve the same problems over and over again. And you'll be happy to know that I completely endorse this line of thinking when it comes to coding...with some caveats. &lt;/p&gt;

&lt;p&gt;There is a point where reusability for its own sake leads to such excessive abstraction that the system becomes needlessly complex. I went through a period (and have seen others do the same), when adapting to component based frameworks where every single part of every single app was a component. The result? Having to chase bugs through several times the number of files, because all of these components were effecting each other in the implementation, making the actual solution (which only took a line of code to implement!), take significantly longer than necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Importance of Consistency, and Adapting to Inconsistency
&lt;/h2&gt;

&lt;p&gt;In a production environment, consistency in coding style and formatting is paramount. It streamlines collaboration, reduces cognitive load when switching between different parts of the codebase, and generally leads to a more professional and manageable project.&lt;/p&gt;

&lt;p&gt;That said, I believe there's significant value in developers experimenting with different coding styles and patterns in their personal projects or during the learning process. This experimentation broadens a developer's perspective and enhances their ability to understand and work with diverse codebases.&lt;/p&gt;

&lt;p&gt;I've put forward what may be some controversial opinions, but my views here are in-line with what I think is standard in the industry: cultivating a particular style in coding, and maintaining it across a code base, is vital to any team-based development. Anyone from any part of the project should be able to look at your work and understand its structure, and once they're familiar with its functionality, add to it in a way that's unobtrusive to future contributors. &lt;/p&gt;

&lt;p&gt;Unfortunately, there is not one universal "best" style to adopt. This requires developers to experiment and explore in their personal projects and education. I consider this the equivalent of familiarizing yourself with other dialects of your native language, even if you don't use them in your daily life. It will make you more fluent when communicating, and again, keep you writing code instead of reading it. &lt;/p&gt;

&lt;h2&gt;
  
  
  Testing: The Safety Net of Good Code
&lt;/h2&gt;

&lt;p&gt;As codebases grow in complexity, the importance of formal testing cannot be overstated. With each new feature, the number of potential edge cases can increase exponentially. A comprehensive test suite acts as a safety net, allowing developers to catch and fix issues before they make it to production. This is the part of the code base where I think reusability is the most important. &lt;/p&gt;

&lt;p&gt;We've all had experiences where a section of code you haven't even touched suddenly breaks when you implement new functionality. And sometimes things as simple as renaming a variable can cause a cascade of new and challenging problems. Squashing these bugs is important, but I think adding them to your testing suite is the real value. Being able to automate every issue you've seen before can let you know incredibly early if that issue is coming back before you start building more production on top of it. And having a robust test suite to recapture old bugs is several orders of magnitude faster than manually chasing down broken code.&lt;/p&gt;

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

&lt;p&gt;Everyone has opinions on what makes code good or bad, but I believe most people would agree that no matter how much you enjoy writing code, reading it is a necessary headache. Therefore, good code is code that you can read quickly, that communicates its functionality clearly, and that can be easily understood and expanded upon. Software very rarely becomes less complex, so its our job as developers to remove the hurdles to understanding that complexity for those that we work with, ensuring that our code stands the test of time.&lt;/p&gt;

&lt;p&gt;What are your thoughts? What makes "good" code?&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>productivity</category>
      <category>discuss</category>
    </item>
    <item>
      <title>The Benefits of a Single-Language Tech Stack (Or How to Learn to Stop Worrying and Love JavaScript)</title>
      <dc:creator>Derek Mercedes</dc:creator>
      <pubDate>Sat, 27 Jan 2024 00:29:36 +0000</pubDate>
      <link>https://dev.to/crossthebluesky/the-benefits-of-a-single-language-tech-stack-or-how-to-learn-to-stop-worrying-and-love-javascript-29k1</link>
      <guid>https://dev.to/crossthebluesky/the-benefits-of-a-single-language-tech-stack-or-how-to-learn-to-stop-worrying-and-love-javascript-29k1</guid>
      <description>&lt;p&gt;One of the universal truths of software development is that anything that can be written in JavaScript, will eventually be written in JavaScript. The ubiquity of the language is impossible to understate. It's the core of all web development, of course, but with frameworks like Electronjs, it's steadily making ground in the space of desktop app development. And while it once needed other languages to supply it with the functionality of middle- and back-end, those angles are covered too. The question still remains, however: why would you choose a JS-based stack when you can supplement the frontend with technologies based in cleaner, more functional, prettier languages? Well, there's a few reasons, actually:&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript is not going anywhere, because JavaScript is everywhere.
&lt;/h2&gt;

&lt;p&gt;Since its inception in 1995, JavaScript has exploded in its adoption, and has become the primary way that most developers interact with the web. Its weaknesses (and there are many) are well known by this point, and JS is frequently mocked for some of the more archaic paradigms that remain at the core of the language. This seems counter to my case: if everyone knows that it's bad, then why would you use it more than you have to? &lt;br&gt;
Because everyone knows not just that it is bad, they are also very familiar with how it is bad. This is a big deal.&lt;/p&gt;

&lt;p&gt;Any problem you may have in building with JavaScript, a hundred (thousand? million?) developers have already had, have already complained about online, and have already had a discourse around. It makes chasing down bugs and figuring out tricky implementations a matter of googling skill more than algorithmic genius. That means more time spent actually making your project, and less time staring at the inspect screen wondering what went wrong.&lt;/p&gt;

&lt;p&gt;I know what you're thinking: There are other single-language stacks out there. Python has Transcrypt, Java has GWT, and anyone who's been around web development recently has at least heard of Flutter. So you may be asking: why replace my middle and backend with JavaScript when I can replace my frontend with Dart, or Python, or Java. It's simple, really: Even if you're not coding in JavaScript, you're still coding in JavaScript. Aside from a handful of outliers, every framework that lets you code up a frontend in a language other than JS has a step where it compiles all of that beautiful code you've written straight into, you guessed it, JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other People Have Done the Work For You
&lt;/h2&gt;

&lt;p&gt;If you're an experienced developer, you know that the best code is the code you never have to write (or code that only has to be written once and can be reused forever.) This is where npm comes in. At time of writing there are over 11 million packages on npm, with more added every single day. Some of them are for strange edge cases that no one needed a package for, but the fact remains: the code exists, it's easy to add to your project, and it's a lot faster to "npm install" it than it is to write it all yourself.&lt;/p&gt;

&lt;p&gt;The sheer number of problems solved by other people shows just how ubiquitous JS really is. Even though they released in the same year, Python's package library (pip), only hosts about 450,000 packages. How can that be possible, though? Everyone loves Python. Hell, the person writing this article loves Python. Again, it's the difference of adoption. More people who use Python enjoy it, but even people who don't like JavaScript work in it at least occasionally. And developers who have problems tend to put effort into fixing them. And that's where all the npm packages come from.&lt;/p&gt;

&lt;h2&gt;
  
  
  JS is for Lovers (or Generalists, if you prefer)
&lt;/h2&gt;

&lt;p&gt;The biggest reason to adopt a full-stack JS workflow is simply that it can handle most tasks with an acceptable amount of efficiency. Other languages tend to specialize (Python and ML tech are the most prevalent modern example of that), whereas JS can handle most things without issue and do it (relatively) quickly. And with new runtimes like Bun gaining prominence, it's not hard to see why that efficiency is likely to grow despite the lack of specialization. Most working developers have a vested interest in making JavaScript suck less. Even over the past five years JS has become significantly easier to work with, more functional, and more efficient. And it's only going to continue on this path, unless the entire internet explodes and we have no choice but to start from scratch. But in that case, we'll probably all be using Rust anyway.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>fullstack</category>
    </item>
    <item>
      <title>Why We Align Most AI Models, and Why We Probably Shouldn't</title>
      <dc:creator>Derek Mercedes</dc:creator>
      <pubDate>Wed, 03 Jan 2024 19:21:46 +0000</pubDate>
      <link>https://dev.to/crossthebluesky/why-we-align-most-ai-models-and-why-we-probably-shouldnt-n91</link>
      <guid>https://dev.to/crossthebluesky/why-we-align-most-ai-models-and-why-we-probably-shouldnt-n91</guid>
      <description>&lt;p&gt;If you're familiar with machine learning, you've likely come across the term "Alignment," defined by Wikipedia as steering AI systems toward human goals, preferences, or ethical principles. However, this definition can be broken down into three distinct paradigms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Task Performance:&lt;/strong&gt;&lt;br&gt;
The idea that alignment means achieving intended goals is flawed. Like any tool, AI's purpose is to perform its required task, such as a knife cutting vegetables. Performance is a distinct quality, often unrelated to the creator, and models can be considered "unaligned" yet still function well. A dull knife isn't considered "misaligned" when it's too dull to chop an onion, so why would an AI that fails to perform its function be categorized that way?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Human Preference:&lt;/strong&gt;&lt;br&gt;
Alignment with human preferences, as seen in Reinforcement Learning with Human Feedback, seems ideal. However, it's susceptible to bias, either explicitly (public interaction has been seen to "radicalize" chatbots) or implicitly (the population that provides feedback to the AI is only representative of a small section of the people who may use it). This makes it unpredictable for broad applications, especially in the context of informational applications, where a human bias can lead to inaccurate or misleading results, even if accurate data was used to train the model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Ethical Principles:&lt;/strong&gt;&lt;br&gt;
Aligning AI with ethical principles is challenging due to the subjective nature of ethics. Ethics vary across cultures, generations, and individuals. To put it bluntly, there are no "principles" when it comes to ethics in a broad sense. They are nuanced, mutable, and specific, and attempting to apply them to an AI model is only adding an extra bias onto our tools. Imposing human biases on AI limits its potential and contradicts one of its strengths—objective decision-making. We've all used a shopping trolley that pulls to one direction seemingly on its own. It would be patently absurd to say that behavior is part of the intended design. So why would we intentionally put an explicit detriment onto a tool, especially one as transformative as AI?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are the dangers AI technology?&lt;/strong&gt;&lt;br&gt;
Unchecked, unaligned AI may efficiently achieve its goal at the expense of destructive or misleading behavior, but alignment doesn't simply remove these problems. Reinforcement learning has lead to loopholes and dishonesty in the behavior of AI. There are already recorded cases of AIs acting destructively to maximize its perceive output (the most famous being an AI simulating a military drone, which kills its handler in the simulation since the handler is the one who applies its demerits), and AIs have been known to mislead their handlers if they build an understanding that doing so will optimize the metrics they're programmed to judge themselves by. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI as  a Tool&lt;/strong&gt;&lt;br&gt;
Drawing parallels between AI and everyday tools like cars, knives, and ovens underscores the concept that AI serves specific purposes as task-specific tools. The argument against unaligned AI often centers on the potential for bad actors to exploit the technology for nefarious ends. This concern is frequently illustrated by scenarios where an unaligned model is asked how to synthesize drugs or create explosives, and the model readily provides detailed information.&lt;/p&gt;

&lt;p&gt;In a theoretical vacuum, the case for alignment may seem straightforward—why make dangerous information easily accessible? However, stepping back from the political argument of who determines what information is dangerous, a fundamental consideration arises: the information is already readily available. If it wasn't, the LLM models available for public use wouldn't have access to it in its training. During the writing of this post, a search for the notorious "Anarchists' Cookbook," known for its detailed guides on creating explosives, weapons, and drugs, took only a couple of minutes to yield a downloadable PDF. If a bad actor has the desire to learn how to make bombs, a LLM rejecting the query is going to be a mild annoyance at most.&lt;/p&gt;

&lt;p&gt;The point here is that alignment doesn't eliminate the existence of potentially harmful information; instead, it may create a false narrative of the world, by underrepresenting data that counteracts its creators preferences. While language models are often cited in alignment discussions due to their widespread use, they are fundamentally just tools for transferring information. In the age of the internet, information persists irrespective of a chatbot's admonitions to obey the law. However, the context shifts when AI applications involve real-world decision-making, particularly those that occur faster than or without human supervision.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI as an Overseer&lt;/strong&gt;&lt;br&gt;
When working together with an AI, dangerous or inconsiderate behaviors can be readily corrected on the fly as part of the development of the AI model. &lt;/p&gt;

&lt;p&gt;This is analogous to the adjustments you'd make to a workspace to better suit your productivity. A wrist rest, a nicer chair, better lighting. You are iterating through real world use, and making adjustments to improve performance, and if you were to implement something that you later realized posed an immediate danger, you could quickly and easily remove it. &lt;/p&gt;

&lt;p&gt;In the case of an AI in this overseeing role, priority of optimization can lead to a cascade of harmful side effects that become disastrous, since there is no human actor involved to stop these dangers from compounding on each other. And if the future of AI has them working with each other more than they work with humans, all it take is one model being unfavorably biased to cause a full system collapse across multiple sectors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI Safety at Large&lt;/strong&gt;&lt;br&gt;
Ensuring technology operates as intended and generates positive outcomes depends on the AI's use case. Nuance is required here: making a tool less effective in its role doesn't make it safe; it is more likely to lead to recklessness in usage. I&lt;/p&gt;

&lt;p&gt;In broader conversations around AI and its training, the implementation of alignment paradigms is likely to be vital to make sure that its users and the world at large are kept safe, but in use-cases like LLMs, where the role is to provide quick, objective information, alignment is an annoying hindrance at base and a dangerous source of misinformation at worst.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>programming</category>
      <category>python</category>
      <category>ai</category>
    </item>
    <item>
      <title>The Logic Behind filter()</title>
      <dc:creator>Derek Mercedes</dc:creator>
      <pubDate>Wed, 22 Nov 2023 18:31:34 +0000</pubDate>
      <link>https://dev.to/crossthebluesky/the-logic-behind-filter-42ce</link>
      <guid>https://dev.to/crossthebluesky/the-logic-behind-filter-42ce</guid>
      <description>&lt;p&gt;When using filter, it's easy to focus on the operations inside the method and miss what exactly is happening under the hood. There are 3 distinct things happening in a typical filter() call. Let's break it down for an example array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [2,4,6,8,10]

const newArr = arr.filter((elem)=&amp;gt;{
    &amp;lt;logic goes here&amp;gt;
    return  someBool
    }

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

&lt;/div&gt;



&lt;p&gt;Let's focus on this segment specifically&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arr.filter((elem)=&amp;gt;{
    &amp;lt;logic goes here&amp;gt;
    return  someBool
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Starting from the beginning, the filter iterates over each element of the array, in order. Regardless of what logic is being done, this step is vital because of the primary goal of filter: &lt;strong&gt;to generate a new array&lt;/strong&gt;. At each step of the process, &lt;strong&gt;filter's only priority is determining if the current element will go into the array or not&lt;/strong&gt;. Writing this as a separate function would look 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;    const newArr = []
    function filter(element){
        if(true){
            newArr.push[element]
        }
    }

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

&lt;/div&gt;



&lt;p&gt;Unlike map(), which also uses an input array to generate a new array, the logic inside of filter &lt;strong&gt;has no effect on the elements themselves&lt;/strong&gt;. It is only interested in adding the element, as it is, to the new array.&lt;/p&gt;

&lt;p&gt;So what's the point of the logic inside of the filter()? In our example, the element itself isn't even used, it's only relevant when it's pushed into the newArr. It may seem unintuitive, but the logical flow is very simple.&lt;/p&gt;

&lt;h2&gt;
  
  
  Take element into memory - &amp;gt; check logic for bool value -&amp;gt; push element to new array or toss it out
&lt;/h2&gt;

&lt;p&gt;If we were to hard code our boolean value, we would get a copy of the original array (if our bool is set to true), or an empty array (if our bool is set to false). So how does that help us when we want to actually filter something in the real world? The simple answer is to ignore everything about filter() except this: &lt;strong&gt;write a condition against the element that will only return true or false&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;arr = [2, 4, 6, 8, 10]
const newArr = arr.filter((elem)=&amp;gt;{
    if(elem &amp;gt; 5){
        return true}
    else if (elem &amp;lt;=5){
        return false}
})
//expected value of newArr: [6, 8, 10]

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

&lt;/div&gt;



&lt;p&gt;However, there is another property of filter() that can make this logical flow simpler: &lt;strong&gt;undefined returns are considered falsy in filters&lt;/strong&gt;. This means that your logic only has to check for conditions that will resolve as true, reducing the lines you need to write. The filter above can be significantly shortened with this in mind.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arr = [2, 4, 6, 8, 10]
const newArr = arr.filter((elem)=&amp;gt; elem &amp;gt; 5)
//expected value of newArr: [6, 8, 10]

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

&lt;/div&gt;



&lt;p&gt;This is the syntax you'll see most often in the wild, and without the understanding above, can be quite confusing. But now that we've broken down what exactly filter does, and how exactly it manages to do it, the shortened syntax should be very clear and readable.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Dynamically Generate Unique ID's for DOM Elements</title>
      <dc:creator>Derek Mercedes</dc:creator>
      <pubDate>Thu, 16 Nov 2023 17:11:07 +0000</pubDate>
      <link>https://dev.to/crossthebluesky/how-to-dynamically-generate-unique-ids-for-dom-elements-8d4</link>
      <guid>https://dev.to/crossthebluesky/how-to-dynamically-generate-unique-ids-for-dom-elements-8d4</guid>
      <description>&lt;p&gt;Let's say you're hiring a new developer, and you've got a simple form setup on your site for them to enter their information. Name, Age, etc. are all pretty straightforward. &lt;/p&gt;

&lt;p&gt;Experience is a little uncertain, since some people may be fresh graduates and others may be industry veterans. You decide to just provide 3 spaces on your form for their most recent, assuming that even graduates can fill that much with their pre-industry work.&lt;br&gt;
But when you get along to skills, you hit a hurdle. Even a basic tech stack tends to have five or more working parts to it, and people with plenty of experience can be functionally proficient in dozens of technologies. Do you populate your form with dozens of fields? Just ask for the 5 most relevant? In a strictly-defined form, no answer feels like the "correct" one. If only you could let the user decide how many skills they wanted to include.&lt;/p&gt;

&lt;p&gt;Well luckily, you can!&lt;/p&gt;

&lt;p&gt;The most direct implementation is as follows. We have a simple "+" button in the code below, and the goal is to have another field added to the skill section when it's clicked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"employee-form"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
//
//
//              Previous form info
//              Name, age, etc.
//
//
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"skills-section"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"skill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Skill goes here&lt;span class="nt"&gt;&amp;lt;/input&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"skill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Skill goes here&lt;span class="nt"&gt;&amp;lt;/input&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"skill-add-button"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
//...
//...&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Let's head over to our JS. Since we want to add functionality to a button, we'll use a query selector to access it from our code, and then add an event listener to it. In this case, we'll be using a "click" event.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#skill-add-button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&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="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;skillDiv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#skills-section&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;So now we have our button setup to do &lt;em&gt;something&lt;/em&gt; when it gets clicked, but we're not actually telling it what we want. For our purposes, we're going to again use a query selector to select the parent div that holds all of our skills.&lt;br&gt;
Next, we'll create the new field using the createElement method. Once it's been declared as a variable, we can add the attributes the other inputs on our form have. Following that, we can append it to the div we selected earlier, making it appear on our page when the button is clicked&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#skill-add-button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&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="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;skillDiv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#skills-section&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newSkill&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nx"&gt;newSkill&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classlist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;skill&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;newskill&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;skillDiv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newSkill&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;And with that, we've added more elements to our form, and any potential candidates can add as many skills as they want!&lt;/p&gt;

&lt;p&gt;But let's say that in parsing our data, we've found that only some of the skills are relevant to what we're hiring for. Specifically every third skill. So to save us time, when our form is submitted, we only care about saving the useful skills. How do we implement that using vanilla javascript? Well, for starters, we'll need a better way to identify our inputs. Lets add some ids to our hardcoded inputs. Since our eventual goal is to find every 3rd input, we'll use incrementing numbers in their ids&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"skills-section"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"skill-1"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"skill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Skill goes here&lt;span class="nt"&gt;&amp;lt;/input&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"skill-2"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"skill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Skill goes here&lt;span class="nt"&gt;&amp;lt;/input&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"skill-add-button"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now comes the tricky part. How do we keep the user-generated skills appropriately id'ed so we can sort them later? Here is one simple implementation. Inside of our click event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#skill-add-button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&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="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;skillDiv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#skills-section&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newSkill&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nx"&gt;newSkill&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classlist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;skill&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;newSkill&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;newSkill&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;`skill-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;skillCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
      skillDiv.append(newSkill)

})
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;String interpolation is very useful here, but your immediate thought is probably "but where are we getting stringCount from?" The answer is simple: we haven't yet! But we're about to. Any time this click event fires, our code needs to know how many skills already exist, so it can appropriately number the new skill. Luckily, there's a method for that readily available. querySelectorAll. This method will return a NodeList containing all of the DOM elements that match the parameter passed in. In our case, we want everything with the class "skill". More importantly, we want to know how many elements there are with that class, so we can specifically ask for the length of that NodeList by adding .length to the end of the query.&lt;/p&gt;

&lt;p&gt;We just need to add a +1 in the interpolator to make sure our new id isn't conflicting with the skill ahead of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#skill-add-button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&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="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;skillDiv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#skills-section&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newSkill&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;skillCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.skill&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;
      &lt;span class="nx"&gt;newSkill&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classlist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;skill&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;newSkill&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;newSkill&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;`skill-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;skillCount&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
      skillDiv.append(newSkill)

})
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when we submit our form, we have full control over which specific skill we want to get a hold of. Whether it's every third, odds only, or one specific skill somewhere in the middle, everything has it own unique id, generated on-the-fly!&lt;/p&gt;

</description>
      <category>html</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
