<?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: Bjoern</title>
    <description>The latest articles on DEV Community by Bjoern (@bjoentrepreneur).</description>
    <link>https://dev.to/bjoentrepreneur</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%2F1272308%2F0b1d32fe-d08a-479d-a9b7-24e89fd61352.png</url>
      <title>DEV Community: Bjoern</title>
      <link>https://dev.to/bjoentrepreneur</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bjoentrepreneur"/>
    <language>en</language>
    <item>
      <title>Happy Birthday Solana 🎂</title>
      <dc:creator>Bjoern</dc:creator>
      <pubDate>Sat, 16 Mar 2024 13:26:49 +0000</pubDate>
      <link>https://dev.to/bjoentrepreneur/happy-birthday-solana-3dpo</link>
      <guid>https://dev.to/bjoentrepreneur/happy-birthday-solana-3dpo</guid>
      <description>&lt;p&gt;4 years ago, there was the first block ever minted on the Solana blockchain. Lots of things have happened since then and I thought it would be a good reason to ask:&lt;br&gt;
What are your experiences with blockchain technology? &lt;/p&gt;

</description>
      <category>web3</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Solana, Polygon, or ...?</title>
      <dc:creator>Bjoern</dc:creator>
      <pubDate>Mon, 04 Mar 2024 14:55:43 +0000</pubDate>
      <link>https://dev.to/bjoentrepreneur/solana-polygon-or--40l7</link>
      <guid>https://dev.to/bjoentrepreneur/solana-polygon-or--40l7</guid>
      <description>&lt;p&gt;... and why?&lt;/p&gt;

&lt;p&gt;I want to start developing a Dapp and would love to hear your thoughts about which ecosystem you prefer and why.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>discuss</category>
      <category>learning</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Solana, Polygon, or ...?</title>
      <dc:creator>Bjoern</dc:creator>
      <pubDate>Mon, 04 Mar 2024 14:55:35 +0000</pubDate>
      <link>https://dev.to/bjoentrepreneur/solana-polygon-or--2a17</link>
      <guid>https://dev.to/bjoentrepreneur/solana-polygon-or--2a17</guid>
      <description>&lt;p&gt;... and why?&lt;/p&gt;

&lt;p&gt;I want to start developing a Dapp and would love to hear your thoughts about which ecosystem you prefer and why.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>discuss</category>
      <category>learning</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Discussion: Supabase vs. Firebase - What do you think?</title>
      <dc:creator>Bjoern</dc:creator>
      <pubDate>Thu, 08 Feb 2024 01:28:48 +0000</pubDate>
      <link>https://dev.to/bjoentrepreneur/discussion-supabase-vs-firebase-what-do-you-think-4io2</link>
      <guid>https://dev.to/bjoentrepreneur/discussion-supabase-vs-firebase-what-do-you-think-4io2</guid>
      <description>&lt;p&gt;Hey there, &lt;br&gt;
I want to keep this short. As a tech enthusiast, I love to try new things. My normal tech stack would be a Firebase backend and a Vercel NextJS frontend. &lt;/p&gt;

&lt;p&gt;Now I stumbled upon two things that I got recommended by others and haven't had the chance to test so I thought I would ask you :)&lt;/p&gt;

&lt;p&gt;What are your experiences with Firebase? &lt;br&gt;
(Bonus: the second thing is Cloudflare Pages vs. Vercel but the more pressing question is the first)&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>backenddevelopment</category>
      <category>backend</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Ditch the ifs and elses with dictionaries</title>
      <dc:creator>Bjoern</dc:creator>
      <pubDate>Sat, 03 Feb 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/bjoentrepreneur/ditch-the-ifs-and-elses-1450</link>
      <guid>https://dev.to/bjoentrepreneur/ditch-the-ifs-and-elses-1450</guid>
      <description>&lt;p&gt;Have you ever found yourself tangled in a web of if/else statements or a bulky switch case just to map product IDs to their corresponding credits?&lt;/p&gt;

&lt;p&gt;I know I have, and while these approaches work, they can become messy and hard to maintain as the number of products grows. Today, I want to share a simple but effective alternative: type-safe dictionaries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Let's say you have an online store with various products, each with a unique ID and associated credit value. You need to write code to retrieve the credit amount for a given product ID.&lt;/p&gt;

&lt;p&gt;Here's how you might do it with traditional conditional statements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getCredits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&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;productId&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prod_A123&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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;productId&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prod_B456&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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;productId&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prod_C789&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This approach works, but imagine adding more products – the code becomes long, repetitive, and difficult to modify.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution: A type-safe dictionary!
&lt;/h2&gt;

&lt;p&gt;Instead of tangled conditionals, harness the power of type-safe dictionaries. Think of them as organized maps, where each product ID (a string) serves as the key and its credit value (a number) as the corresponding value.&lt;/p&gt;

&lt;p&gt;Here's the magic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// 1. Define the interface&lt;/span&gt;
&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;ProductCredits&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// 2. Initiate the dictionary&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;productCredits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ProductCredits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prod_A123&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;prod_B456&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;prod_C789&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// 3. Write a function to get the data returned&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getCredits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&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;productCredits&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This approach is cleaner and more type-safe. This updated getCredits function retrieves the credit value directly from the dictionary using the product ID as the key.&lt;/p&gt;

&lt;p&gt;If the ID is not found, it returns a default value of 0.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Readability:&lt;/strong&gt; Crystal-clear code, even for someone new to the logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintainability:&lt;/strong&gt; Adding new products involves updating the dictionary, not complex conditionals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type-Safety:&lt;/strong&gt; TypeScript ensures correct data types, preventing errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency:&lt;/strong&gt; Dictionary lookups are generally faster than conditional chains.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Beyond the Basics
&lt;/h3&gt;

&lt;p&gt;This is just the tip of the iceberg. Customize your solution further by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding comments to dictionary entries for clarity.&lt;/li&gt;
&lt;li&gt;Using a more structured data source like a database for larger datasets.&lt;/li&gt;
&lt;li&gt;Improve error handling for invalid product IDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Closing Thoughts
&lt;/h2&gt;

&lt;p&gt;Type-safe dictionaries offer a powerful alternative to conditional statements for managing product IDs and credits in TypeScript. This approach promotes code readability, maintainability, type-safety, and performance.&lt;/p&gt;

&lt;p&gt;So, the next time you face a similar challenge, remember: tame the TypeScript jungle with the elegance of type-safe dictionaries!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>performance</category>
      <category>coding</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
