<?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: Firecrow Silvernight</title>
    <description>The latest articles on DEV Community by Firecrow Silvernight (@firecrow8).</description>
    <link>https://dev.to/firecrow8</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%2F1248273%2Fda9ebb5f-2cac-463a-8544-3fd0da9e6748.jpg</url>
      <title>DEV Community: Firecrow Silvernight</title>
      <link>https://dev.to/firecrow8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/firecrow8"/>
    <language>en</language>
    <item>
      <title>Introducing TempLang - an abbreviated FE framework</title>
      <dc:creator>Firecrow Silvernight</dc:creator>
      <pubDate>Thu, 04 Apr 2024 22:31:09 +0000</pubDate>
      <link>https://dev.to/firecrow8/introducing-templang-an-abbreviated-fe-framework-3em4</link>
      <guid>https://dev.to/firecrow8/introducing-templang-an-abbreviated-fe-framework-3em4</guid>
      <description>&lt;p&gt;Hi All, I've created a new frontend framework. It's designed to make the most common front end task &lt;em&gt;very&lt;/em&gt; fast to write.&lt;/p&gt;

&lt;p&gt;I've found that during my time as a front end developer the amount of time spent wiring stuff in ways that could be automated was high enough to build something new. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://templang.org" rel="noopener noreferrer"&gt;https://templang.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'll start by introducing a few concepts that used to take a up a lot of my time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Event Binding&lt;/strong&gt;: you can now tag things with on:click="^update(color=key)" and it i will call the on:update handler of any parent node with the value of &lt;em&gt;key&lt;/em&gt; as the property &lt;em&gt;color&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Property Renaming&lt;/strong&gt;: color=key is sending the value of &lt;em&gt;key&lt;/em&gt; as the property &lt;em&gt;color&lt;/em&gt; as the event propagates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Access to the &lt;em&gt;target&lt;/em&gt; and &lt;em&gt;handler element&lt;/em&gt;&lt;/strong&gt;: each event contains a &lt;em&gt;target&lt;/em&gt; and &lt;em&gt;dest&lt;/em&gt; prop so it's easy to do things with all the elements involved. &lt;em&gt;vars&lt;/em&gt; contains any variables on either element to make it easy to do stuff!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Styles and Classes on the fly&lt;/strong&gt;: Styles can be built per element, you'll notice in the example that &lt;code&gt;base-style="background-color: ${key}"&lt;/code&gt; creates a new style rule as &lt;code&gt;.custom-element-6 { background-color: rgb(187, 0, 0);}&lt;/code&gt; from the data &lt;code&gt;{name: "Red", key: "#B00"}&lt;/code&gt; for that element.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's still in development and getting cleaner with every generation.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Does limiting state matter on the FrontEnd?</title>
      <dc:creator>Firecrow Silvernight</dc:creator>
      <pubDate>Mon, 01 Apr 2024 18:27:36 +0000</pubDate>
      <link>https://dev.to/firecrow8/does-limiting-state-matter-on-the-frontend-1e79</link>
      <guid>https://dev.to/firecrow8/does-limiting-state-matter-on-the-frontend-1e79</guid>
      <description>&lt;p&gt;Hi all, I have a statement I just published that I'd like the communities take on.&lt;/p&gt;

&lt;p&gt;For background, I've been a frontend and backend engineer over the years, and have noticed that there are nuances in each domain worth considering.&lt;/p&gt;

&lt;p&gt;It has been common to encounter companies with more leadership from their backend engineers, and I question how much of the usual best-practices have been shaped without enough front end domain consideration.&lt;/p&gt;

&lt;p&gt;here is the statement, what do you think?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Case for Variables on Elements&lt;/p&gt;

&lt;p&gt;It's a good idea to keep state in as few places as possible right?&lt;/p&gt;

&lt;p&gt;Not always... locality is the best chance a user-interface has for making sense during development. &lt;/p&gt;

&lt;p&gt;This is not a casual idea, it's because immutability is a loosing battle when there are a lot of user events involved. &lt;/p&gt;

&lt;p&gt;Localized ownership of internal state is a more scalable solution, and it leads to a "what you see is what you get" authoring process, which is more discussable, and thereby maintainable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://templang.org" rel="noopener noreferrer"&gt;https://templang.org&lt;/a&gt;&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>state</category>
      <category>webdev</category>
      <category>career</category>
    </item>
    <item>
      <title>Closure is as Closure does</title>
      <dc:creator>Firecrow Silvernight</dc:creator>
      <pubDate>Mon, 01 Apr 2024 12:40:31 +0000</pubDate>
      <link>https://dev.to/firecrow8/closure-is-as-closure-does-33d4</link>
      <guid>https://dev.to/firecrow8/closure-is-as-closure-does-33d4</guid>
      <description>&lt;p&gt;I'd like to share my experience of when to use closures and when to use more basic things.&lt;/p&gt;

&lt;p&gt;The old joke I've come to enjoy is this, "When do Senior and Junior engineers write the same thing... When the clever function is not necessary."&lt;/p&gt;

&lt;p&gt;Let's consider to possible solutions to using data from an Array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;objA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;objB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;objC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;objD&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;doStuff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="c1"&gt;// do stuff here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Version One - with a closure&lt;/span&gt;
&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;doStuff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Version Two - with a for loop&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nf"&gt;doStuff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code &lt;em&gt;does&lt;/em&gt; the same thing, but there are a few differences in which actions are done &lt;em&gt;more&lt;/em&gt;. The array access in version two with [] may be less efficient under the hood than having the &lt;code&gt;forEach&lt;/code&gt; pre-load the items. And the creation of a function context for each iteration will be more expensive in version One because it will open a closure track all the variables involved each time.&lt;/p&gt;

&lt;p&gt;Lets look at that last case, the creation of a closure and function context.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a scope record in memory&lt;/li&gt;
&lt;li&gt;Retain the closure until all variables are no longer in use&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By contrast, the for loop body is only ever in one place, and references one scope.&lt;/p&gt;

&lt;p&gt;So in terms of comparing performance we have a competition of two things.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Array access vs pre-loaded execution (this is because the item.forEach is predictable, whereas [i] can be any out of order access of an element, making it harder to optimize)&lt;/li&gt;
&lt;li&gt;or Function context creation for each item&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's highly likely (depending on the JavaScript implementation) that the array access being random is a far lower cost than the creation of a closure for each item.&lt;/p&gt;

&lt;p&gt;You will also notice I've pulled out the length into a variable &lt;code&gt;len&lt;/code&gt;, this is because for certain collections (such as DOM Element Collections), the length property is actually a calculation. If you have a list of DOM elements, accessing the length property will climb the elements and calculate the total length, every time the loop iteration runs, pulling out a variable will avoid this.&lt;/p&gt;

&lt;p&gt;While the &lt;code&gt;.forEach&lt;/code&gt; looks fantastic and is easy to look at, lets consider how it scales with human effort in how it is modified.&lt;/p&gt;

&lt;p&gt;Lets introduce the idea of an &lt;em&gt;early out&lt;/em&gt;, lets say we only need to run until we find 3 items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;elidgableThree&lt;/span&gt; &lt;span class="o"&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;NEEDED_COUNT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&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;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;objA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;objB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;objC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;objD&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;doStuff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nx"&gt;elidgableThree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;elidgableThree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;NEEDED_COUNT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Version One - with a closure&lt;/span&gt;
&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;doStuff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Version Two - with a for loop&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;allDone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;doStuff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;allDone&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have a control flow return value, it's much easier to control our code with the &lt;code&gt;for&lt;/code&gt; loop than the &lt;code&gt;forEach&lt;/code&gt;. This is another example of how convenience that hides ugly details can take away flexibility.&lt;/p&gt;

&lt;p&gt;Version Two is unquestionably uglier, and also more adjustable to a variety of circumstances.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>scope</category>
      <category>closure</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
