<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Programming on David Lang</title>
    <link>https://www.davidlang.tech/tags/programming/</link>
    <description>Recent content in Programming on David Lang</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Thu, 22 Jun 2023 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.davidlang.tech/tags/programming/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>TypeScript Arrays: 25 Essential Functions and Examples</title>
      <link>https://www.davidlang.tech/posts/typescript-arrays-25-essential-functions-and-examples/</link>
      <pubDate>Thu, 22 Jun 2023 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/typescript-arrays-25-essential-functions-and-examples/</guid>
      <description>&lt;h3 id=&#34;introduction&#34;&gt;Introduction:&lt;/h3&gt;&#xA;&lt;p&gt;Arrays are a fundamental data structure in TypeScript, allowing us to store and manipulate collections of elements. TypeScript provides a rich set of array functions that simplify common tasks and enhance the functionality of arrays. In this article, we will explore 25 essential functions of TypeScript arrays and provide practical examples to help you harness their power in your projects.&lt;/p&gt;&#xA;&lt;h4 id=&#34;1-push&#34;&gt;1. push():&lt;/h4&gt;&#xA;&lt;p&gt;Adds one or more elements to the end of an array.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Security - Authentication Workflows</title>
      <link>https://www.davidlang.tech/posts/security-application-authentication-workflows/</link>
      <pubDate>Sun, 05 Feb 2023 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/security-application-authentication-workflows/</guid>
      <description>&lt;p&gt;Here are three scenarios for implementing authentication workflows.&lt;/p&gt;&#xA;&lt;h2 id=&#34;internet-applications-public-facing&#34;&gt;Internet Applications (Public facing)&lt;/h2&gt;&#xA;&lt;p&gt;For internet web applications and APIs, Session based (SessionID cookie) and Token Based (JWT) Authentication can be implemented.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Session Based:&lt;/strong&gt; Implemented for a majority of traditional and stateful web applications. Once the user is authenticated, A Session state is created and stored in an external State server or SQL database. The Session state is identified by a unique SessionID. This SessionID is returned to the client and set as a cookie using &lt;code&gt;Set-Cookie: sessionid=38askse24d56dh43hrs7a8; HttpOnly; Path=/&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Efficient Data Flow in React: Unveiling the Power of Prop Drilling</title>
      <link>https://www.davidlang.tech/posts/efficient-data-flow-in-react-unveiling-the-power-of-prop-drilling/</link>
      <pubDate>Wed, 08 Jun 2022 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/efficient-data-flow-in-react-unveiling-the-power-of-prop-drilling/</guid>
      <description>&lt;h3 id=&#34;introduction&#34;&gt;Introduction:&lt;/h3&gt;&#xA;&lt;p&gt;React, the popular JavaScript library for building user interfaces, offers several powerful features that make it a developer-friendly choice. One such feature is prop drilling, a technique used for passing data from a top-level component to a deeply nested component. In this blog post, we will explore the concept of prop drilling, understand its benefits and limitations, and provide an example using TypeScript to demonstrate its usage.&lt;/p&gt;&#xA;&lt;h3 id=&#34;what-is-prop-drilling&#34;&gt;What is Prop Drilling?&lt;/h3&gt;&#xA;&lt;p&gt;Prop drilling refers to the process of passing data through multiple layers of components in order to make it accessible to a deeply nested component that needs it. In React, components are organized in a hierarchical structure, where data typically flows from parent components to their children. However, when a component deeply nested in the component tree requires data from a top-level component, prop drilling comes into play.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using React Hooks - useState and useEffect</title>
      <link>https://www.davidlang.tech/posts/using-reactjs-hooks-introduction-usestate-useeffect/</link>
      <pubDate>Tue, 15 Mar 2022 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/using-reactjs-hooks-introduction-usestate-useeffect/</guid>
      <description>&lt;p&gt;With the release of &lt;a href=&#34;https://reactjs.org/docs/hooks-intro.html&#34; title=&#34;React Hooks&#34;&gt;Hooks&lt;/a&gt; in React 16.8, it is now possible to store &lt;strong&gt;state&lt;/strong&gt; in a &lt;strong&gt;function&lt;/strong&gt;. We can add react features like useState and useEffect into the function directly without needing to create &lt;strong&gt;class&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;usestate&#34;&gt;useState&lt;/h2&gt;&#xA;&lt;p&gt;The &lt;strong&gt;useState&lt;/strong&gt; hook adds state to the functional components. useState hook allows you to declare one state variable at a time.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-react&#34; data-lang=&#34;react&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;import&lt;/span&gt; React, { useState } from &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;react&amp;#39;&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;function&lt;/span&gt; Counter() {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#586e75&#34;&gt;//Declare the &amp;#34;counter&amp;#34; state variable&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#268bd2&#34;&gt;const&lt;/span&gt; [counter, setCounter] &lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt; useState(&lt;span style=&#34;color:#2aa198&#34;&gt;0&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#719e07&#34;&gt;return&lt;/span&gt; (&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;div&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;p&lt;/span&gt;&amp;gt;Clicked {counter} times&amp;lt;/&lt;span style=&#34;color:#268bd2&#34;&gt;p&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#586e75&#34;&gt;//increment the counter by 1 on every click&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;button&lt;/span&gt; onClick&lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt;{() =&amp;gt; setCounter(counter &lt;span style=&#34;color:#719e07&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;1&lt;/span&gt;)}&amp;gt;Click here&amp;lt;/&lt;span style=&#34;color:#268bd2&#34;&gt;button&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &amp;lt;/&lt;span style=&#34;color:#268bd2&#34;&gt;div&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  );&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;useeffect&#34;&gt;useEffect&lt;/h2&gt;&#xA;&lt;p&gt;The &lt;strong&gt;useEffect&lt;/strong&gt; allows to manage side effects in a functional component. Some of the examples are fetching external data using api, manipulating DOM in react. It is similar to componentDidMount and componentDidUpdate from class component.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Advanced TypeScript: Generics and Utility Types</title>
      <link>https://www.davidlang.tech/posts/advanced-typescript-generics-and-utility-types/</link>
      <pubDate>Sat, 28 Aug 2021 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/advanced-typescript-generics-and-utility-types/</guid>
      <description>&lt;p&gt;Generics make functions and types reusable without sacrificing type safety. Utility types transform existing types-essential for API layers and form handling.&lt;/p&gt;&#xA;&lt;h2 id=&#34;generic-functions&#34;&gt;Generic Functions&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-typescript&#34; data-lang=&#34;typescript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;function&lt;/span&gt; first&amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;T&lt;/span&gt;&amp;gt;(arr: &lt;span style=&#34;color:#dc322f&#34;&gt;T&lt;/span&gt;[])&lt;span style=&#34;color:#719e07&#34;&gt;:&lt;/span&gt; T &lt;span style=&#34;color:#719e07&#34;&gt;|&lt;/span&gt; &lt;span style=&#34;color:#cb4b16&#34;&gt;undefined&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#719e07&#34;&gt;return&lt;/span&gt; arr[&lt;span style=&#34;color:#2aa198&#34;&gt;0&lt;/span&gt;];&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;const&lt;/span&gt; n &lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt; first([&lt;span style=&#34;color:#2aa198&#34;&gt;1&lt;/span&gt;, &lt;span style=&#34;color:#2aa198&#34;&gt;2&lt;/span&gt;, &lt;span style=&#34;color:#2aa198&#34;&gt;3&lt;/span&gt;]);      &lt;span style=&#34;color:#586e75&#34;&gt;// number | undefined&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;const&lt;/span&gt; s &lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt; first([&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;a&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;b&amp;#39;&lt;/span&gt;]);     &lt;span style=&#34;color:#586e75&#34;&gt;// string | undefined&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;constrained-generics&#34;&gt;Constrained Generics&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-typescript&#34; data-lang=&#34;typescript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;function&lt;/span&gt; getProperty&amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;T&lt;/span&gt;, K extends keyof T&amp;gt;(obj: &lt;span style=&#34;color:#dc322f&#34;&gt;T&lt;/span&gt;, key: &lt;span style=&#34;color:#dc322f&#34;&gt;K&lt;/span&gt;)&lt;span style=&#34;color:#719e07&#34;&gt;:&lt;/span&gt; T[K] {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#719e07&#34;&gt;return&lt;/span&gt; obj[key];&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;utility-types&#34;&gt;Utility Types&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;Partial&amp;lt;T&amp;gt;&lt;/code&gt; - all properties optional&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;Pick&amp;lt;T, K&amp;gt;&lt;/code&gt; - subset of keys&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;Omit&amp;lt;T, K&amp;gt;&lt;/code&gt; - exclude keys&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;Record&amp;lt;K, V&amp;gt;&lt;/code&gt; - keyed object type&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-typescript&#34; data-lang=&#34;typescript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;type&lt;/span&gt; UpdateUserDto &lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt; Partial&amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;Pick&lt;/span&gt;&amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;User&lt;/span&gt;, &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;name&amp;#39;&lt;/span&gt; | &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;email&amp;#39;&lt;/span&gt;&amp;gt;&amp;gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;Master generics and utilities before reaching for complex conditional types. They keep DTOs, reducers, and hook return types DRY and accurate.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Modern JavaScript ES2020: Top Features You Should Know</title>
      <link>https://www.davidlang.tech/posts/modern-javascript-es2020-top-features-you-should-know/</link>
      <pubDate>Sat, 28 Nov 2020 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/modern-javascript-es2020-top-features-you-should-know/</guid>
      <description>&lt;p&gt;ECMAScript 2020 added practical features that reduce boilerplate and improve null-safety. If you are still avoiding optional chaining, now is the time to adopt it.&lt;/p&gt;&#xA;&lt;h2 id=&#34;optional-chaining-and-nullish-coalescing&#34;&gt;Optional Chaining and Nullish Coalescing&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;const&lt;/span&gt; city &lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt; user&lt;span style=&#34;color:#719e07&#34;&gt;?&lt;/span&gt;.address&lt;span style=&#34;color:#719e07&#34;&gt;?&lt;/span&gt;.city &lt;span style=&#34;color:#719e07&#34;&gt;??&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;Unknown&amp;#39;&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;?.&lt;/code&gt; short-circuits on &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt;. &lt;code&gt;??&lt;/code&gt; returns the right side only when the left is &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt;-unlike &lt;code&gt;||&lt;/code&gt;, it preserves &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;&#39;&#39;&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;bigint-and-globalthis&#34;&gt;BigInt and globalThis&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;BigInt&lt;/code&gt; handles integers beyond &lt;code&gt;Number.MAX_SAFE_INTEGER&lt;/code&gt;. &lt;code&gt;globalThis&lt;/code&gt; provides a standard way to access the global object in browsers and Node.&lt;/p&gt;</description>
    </item>
    <item>
      <title>TypeScript for JavaScript Developers: Getting Started</title>
      <link>https://www.davidlang.tech/posts/typescript-for-javascript-developers-getting-started/</link>
      <pubDate>Sat, 18 Apr 2020 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/typescript-for-javascript-developers-getting-started/</guid>
      <description>&lt;p&gt;TypeScript adds static types to JavaScript, catching bugs at compile time and improving editor autocomplete. For full stack developers moving between frontend and backend, it is one of the highest-leverage skills to adopt.&lt;/p&gt;&#xA;&lt;h2 id=&#34;installing-and-configuring&#34;&gt;Installing and Configuring&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;npm install -D typescript @types/node&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;npx tsc --init&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A sensible &lt;code&gt;tsconfig.json&lt;/code&gt; for Node or React projects enables &lt;code&gt;strict&lt;/code&gt;, &lt;code&gt;esModuleInterop&lt;/code&gt;, and &lt;code&gt;skipLibCheck&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;core-concepts&#34;&gt;Core Concepts&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;Interfaces&lt;/strong&gt; describe object shapes. &lt;strong&gt;Generics&lt;/strong&gt; make reusable components type-safe. &lt;strong&gt;Union types&lt;/strong&gt; (&lt;code&gt;string | number&lt;/code&gt;) model values that can be one of several types.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
