<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Keka Engineering - Medium]]></title>
        <description><![CDATA[Keka is a SaaS employee experience platform that combines HR, payroll, ATS and performance management in a single suite of tools - Medium]]></description>
        <link>https://medium.com/keka-engineering?source=rss----a91bd7d31e72---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Keka Engineering - Medium</title>
            <link>https://medium.com/keka-engineering?source=rss----a91bd7d31e72---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 08:34:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/keka-engineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exploring Angular v16]]></title>
            <link>https://medium.com/keka-engineering/exploring-angular-v16-ce9bc4d3244e?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/ce9bc4d3244e</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[P Venkata Narasimha Raju]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 04:10:59 GMT</pubDate>
            <atom:updated>2024-11-28T04:10:59.756Z</atom:updated>
            <content:encoded><![CDATA[<h4>New Features and Updates in Angular v16</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*4_HNTlBW7oUm875t.jpg" /></figure><p>Hey, web warriors!</p><p>Angular 16 isn’t just about new features. It’s about making the development process more efficient and intuitive. Angular 16 has something to offer whether your goal is to increase workflow speed, manage state more efficiently, or enhance performance.</p><h4>Angular Signals</h4><p>Angular introduces new reactivity primitives: signal, computed, and effect. These are designed to make your app&#39;s reactive programming simpler and more efficient. You can explore these new features in the <a href="https://angular.io/guide/signals">signals guide</a>.</p><h4>Enhanced Hydration</h4><p>With the enhanced hydration feature, Angular now reuses existing DOM nodes, improving page load performance.</p><p><strong>How It Works</strong></p><ol><li><strong>Initial Server-Side Rendering</strong>:</li></ol><ul><li>The server renders the HTML and sends it to the client. The HTML looks like this:</li></ul><pre>&lt;ul id=&quot;item-list&quot;&gt;<br>  &lt;li&gt;Item 1&lt;/li&gt;<br>  &lt;li&gt;Item 2&lt;/li&gt;<br>  &lt;li&gt;Item 3&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>2. <strong>Client-Side Hydration</strong>:</p><ul><li>Instead of discarding the current DOM nodes and rendering the entire page again, Angular will reuse the &lt;ul&gt; and &lt;li&gt; elements when a server-side rendered page is reloaded.</li><li>After that Angular will add event listeners and any additional functionality that is required to these already-existing elements.</li></ul><p>Check out the <a href="https://v17.angular.io/guide/hydration">hydration guide</a> for more details.</p><h4>Faster Builds with esbuild</h4><p>Angular CLI now provides a developer preview of new builders based on esbuild, which greatly improves build times. Additionally, Vite integration is included for a quicker development server. To test it out, make the following changes to your angular.json :</p><pre>&quot;architect&quot;: {<br>  &quot;build&quot;: {<br>    &quot;builder&quot;: &quot;@angular-devkit/build-angular:browser-esbuild&quot;</pre><h4>Creating a New Angular App with Standalone Components</h4><p>With Angular v16, you can now create new applications using standalone components without needing traditional NgModules. Here’s how:</p><ul><li>To start a new Angular project with standalone components, simply use the command:</li></ul><pre>ng new --standalone</pre><h4>Required Inputs</h4><p>You can now mark component and directive inputs as required, ensuring all necessary inputs are specified at build time. Here’s an example:</p><pre>export class ColorPicker {<br>  @Input({ required: true }) defaultColor!: string;<br>}</pre><p>This feature helps catch errors early, making your applications more robust.</p><h4>Wrapping Up</h4><p>Angular v16 brings a lot of improvements and new features that make developing Angular applications faster and more efficient.</p><p>I hope this simplifies the new features for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce9bc4d3244e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/exploring-angular-v16-ce9bc4d3244e">Exploring Angular v16</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 16 Signals]]></title>
            <link>https://medium.com/keka-engineering/angular-16-signals-53c19d28ef64?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/53c19d28ef64</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[P Venkata Narasimha Raju]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 03:59:50 GMT</pubDate>
            <atom:updated>2024-11-28T03:59:50.521Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Enhance Your Angular with Signal-Based State Management</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*obIDTY-JqLEZJldZ.jpeg" /></figure><p>Angular 16 introduces <strong>Signals</strong>, a game-changer in handling <strong>reactive state management</strong>. Imagine having a “live feed” for your app’s data — Signals help track and update this data seamlessly across your application. Let’s dive into what makes Signals the future of state management in Angular.</p><p><strong>What are Signals?</strong></p><p>Think of Signals as <strong>observable variables</strong> that automatically notify Angular when their value changes. This magic allows the framework to update the UI without the need for manual updates or complex RxJS subscriptions.</p><p><strong>How Do Signals Work?</strong></p><p>A Signal is like a <strong>container</strong> for a value, created with an initial value. Whenever you <strong>read</strong> or <strong>update</strong> the Signal, Angular tracks it and updates all dependencies.</p><p><strong>Example: Counter App</strong></p><ol><li><strong>Setting Up a Signal</strong></li></ol><pre>import { signal } from &#39;@angular/core&#39;;</pre><pre>export class CounterComponent {<br>  count = signal(0); // Create a Signal with an initial value of 0</pre><pre>  increment() {<br>    this.count.update((value) =&gt; value + 1); // Update the Signal&#39;s value<br>  }</pre><pre>  decrement() {<br>    this.count.update((value) =&gt; value - 1);<br>  }<br>}</pre><p>2. <strong>Binding Signal to the Template</strong></p><pre>&lt;div&gt;<br>  &lt;h1&gt;Counter: {{ count() }}&lt;/h1&gt; &lt;!-- Use count() to read Signal value --&gt;<br>  &lt;button (click)=&quot;increment()&quot;&gt;+&lt;/button&gt;<br>  &lt;button (click)=&quot;decrement()&quot;&gt;-&lt;/button&gt;<br>&lt;/div&gt;</pre><p><strong>How It Works</strong></p><ol><li>count() reads the current value of the Signal.</li><li>increment()and decrement() update the Signal’s value.</li><li>The UI (template) automatically updates whenever the Signal changes.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*q6EgeYrUtpN13Y2I.png" /></figure><p><strong>Why Signals Are Awesome</strong></p><ul><li><strong>No RxJS Complexity:</strong> With Signals, there’s no need for Subject, subscribe or unsubscribe making the codebase cleaner and easier to maintain.</li><li><strong>Automatic Dependency Tracking:</strong> Angular automatically detects when a Signal’s value is used and ensures that only the affected parts of the UI are updated, enhancing performance.</li><li><strong>Easier Debugging:</strong> Signals simplify the debugging process, providing a more straightforward approach compared to complex RxJS streams.</li><li><strong>Simpler State Management:</strong> Signals can replace some use cases of BehaviorSubject or RxJS, making state management less complex and more intuitive.</li></ul><p><strong>Conclusion</strong></p><p>Angular Signals make managing reactive state easier and reduce the need for complex code compared to traditional RxJS methods. By using this powerful tool, you can streamline your state management and build more efficient and maintainable Angular applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53c19d28ef64" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/angular-16-signals-53c19d28ef64">Angular 16 Signals</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparing Alphanumeric Strings in JavaScript]]></title>
            <link>https://medium.com/keka-engineering/comparing-alphanumeric-strings-in-javascript-90f731d1e0b4?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/90f731d1e0b4</guid>
            <dc:creator><![CDATA[P Venkata Narasimha Raju]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 03:57:45 GMT</pubDate>
            <atom:updated>2024-11-28T03:58:41.004Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Simple Guide</h4><p>Hey, web warriors!</p><p>Comparing two alphanumeric strings isn’t as straightforward as it might seem. Because it should be valid in numerical and lexicographical order.</p><p>Let’s understand by example, file10 and file2. If you order purely in lexicographically, then file10 comes before file2 which is incorrect in numerical order.</p><p>So, to make alphanumeric strings in the correct order, we can use this JavaScript function.</p><pre>/**<br> * Compares two alphanumeric strings for numerical and lexicographical order.<br> * <br> * @param stringA - The first string to compare.<br> * @param stringB - The second string to compare.<br> * @returns A negative number if `stringA` &lt; `stringB`, 0 if equal, positive if `stringA` &gt; `stringB`.<br> */<br>function alphaNumericComparator(stringA, stringB) {<br>    // Split strings into numbers and letters<br>    const numberOrNonNumberRegex = /(\d+|\D+)/g;<br>    const [stringASubStrings, stringBSubStrings] = [stringA.match(numberOrNonNumberRegex), stringB.match(numberOrNonNumberRegex)];<br><br>    // Compare each part<br>    for (let index = 0; index &lt; Math.min(stringASubStrings.length, stringBSubStrings.length); index++) {<br>        const [stringASubString, stringBSubString] = [stringASubStrings[index], stringBSubStrings[index]];<br><br>        // Numeric or lexicographic comparison<br>        const difference = !isNaN(+stringASubString) &amp;&amp; !isNaN(+stringBSubString)<br>            ? +stringASubString - +stringBSubString<br>            : stringASubString.localeCompare(stringBSubString);<br><br>        if (difference) return difference; // Return the difference if found<br>    }<br><br>    // Compare by length if parts are equal<br>    return stringASubStrings.length - stringBSubStrings.length;<br>}</pre><p><strong>Breaking Down the Function:</strong></p><ol><li><strong>Splitting the Strings:</strong></li></ol><p>The regular expression (\d+|\D+) we have used in this code is the key for dividing input strings into alternating sequences of numbers and non-numbers. Let’s understand by example that the string file10test20 becomes [&quot;file&quot;, &quot;10&quot;, &quot;test&quot;, &quot;20&quot;].</p><p>2. <strong>Comparing Corresponding part:</strong></p><p>while iterating through the sequences, comparing each segment from stringA with the corresponding segment from stringB.</p><ul><li>If both segments are numbers (i.e., !isNaN(+stringASubString) &amp;&amp; !isNaN(+stringBSubString)), then we perform numerical comparison. Let’s understand by example that we have file10 and file2 where 2 should come before 10 .</li><li>If the segments are not numbers, we use localeCompare for a lexicographical comparison.</li></ul><p>3. <strong>Returning the Difference:</strong></p><p>If a difference is found during any part comparison, it is immediately returned.</p><p>The return value can be a</p><ul><li>negative number if stringA &lt;stringB</li><li>positive number if stringA &gt; stringB</li></ul><p>4.<strong> Handling Equal Parts:</strong></p><p>If all parts of the strings are equal, we compare the lengths of the split arrays (stringASubStrings.length - stringBSubStrings.length). This ensures that file2 is considered smaller than file2O if all previous segments are the same.</p><p><strong>Use Cases:</strong></p><ul><li><strong>File Name Sorting:</strong> File names like file1, file10, and file2are sorted in the correct numerical order.</li><li><strong>Version Control: </strong>Comparing version numbers such as1.10 and 1.2.</li></ul><p><strong>Conclusion:</strong></p><p>By breaking strings into their numeric and non-numeric components and comparing these segments, we ensure that file2 correctly precedes file10 .</p><p>Happy coding, and may your strings always be in perfect order!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90f731d1e0b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/comparing-alphanumeric-strings-in-javascript-90f731d1e0b4">Comparing Alphanumeric Strings in JavaScript</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular v17]]></title>
            <link>https://medium.com/keka-engineering/angular-17-3197771e4101?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/3197771e4101</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[P Venkata Narasimha Raju]]></dc:creator>
            <pubDate>Wed, 20 Nov 2024 10:25:07 GMT</pubDate>
            <atom:updated>2024-11-20T10:25:07.368Z</atom:updated>
            <content:encoded><![CDATA[<h4>What’s New and Exciting</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T2-s9cDTf63dD0tZ.png" /></figure><p>Hey, web warriors! Angular 17 is here, and it’s packed with goodies that’ll make your coding life a lot more fun. Let’s dive into the cool new features in simple terms.</p><ol><li><strong>Simplified Control Flow:</strong></li></ol><p>Angular 17 simplifies conditional rendering with a new syntax that resembles standard JavaScript control flow statements. Instead of using the traditional *ngIf and *ngFor, developers can now use @if and @for .This change not only enhances readability but also reduces bundle size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*g_7Q6P0zCPRTU0cZqe-jMQ.png" /></figure><p><strong>2. Lazy Loading Made Lazier: Deferrable Views</strong></p><p>Why load everything at once when you can do it smartly? Angular 17 lets you load parts of your app only when needed, kind of like only taking snacks from the fridge when you’re hungry. Faster load times = happier users.</p><pre>&lt;div @defer=&quot;isInViewport&quot;&gt;<br>   Content to lazy load<br>&lt;/div&gt;</pre><p><strong>3. Faster Page Loads: Server-Side Rendering (SSR)</strong></p><p>Server-Side Rendering (SSR) in Angular 17 improves the speed at which your web pages load. With SSR, the server generates the HTML for a page before sending it to the user’s browser. This means users can see the content faster because it doesn’t rely on their browser to build the page. Plus, search engines can better understand and rank your site, helping it appear higher in search results.</p><p><strong>4. TypeScript 5.2 Compatibility</strong></p><p>Angular 17 now supports TypeScript 5.2. This update brings improvements like faster type checking and better code readability. It enhances your development experience by making your code more robust and easier to maintain.</p><p><strong>5. Enhanced Performance</strong></p><p>Angular 17 boasts up to 90% faster runtime compared to previous versions, with significant reductions in memory usage (up to 30% less) and improved change detection mechanisms that only mark affected components as dirty</p><p><strong>6. Standalone Components</strong></p><p>Angular 17 allows components to function independently without being tied to Angular modules. This means you can now create and use components more freely, making your code more flexible and easier to manage.</p><p><strong>7. Faster Page Loads</strong></p><p>The new control flow features in Angular 17 lead to faster page loads and updates. Tests show that initial loading times are over 50% quicker, making your applications much faster.</p><p><strong>8. Automatic CSS Cleanup</strong></p><p>Angular 17 automatically removes CSS from the DOM when a component is destroyed. This helps keep your application running smoothly and prevents any performance issues from leftover styles.</p><p><strong>Wrapping Up</strong></p><p>Angular 17 brings exciting updates that make web development faster and easier. Key features like declarative control flow, deferrable views, and improved server-side rendering help create efficient and user-friendly applications.</p><p>I hope this simplifies the new features for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3197771e4101" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/angular-17-3197771e4101">Angular v17</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to achieve thread safety in iOS]]></title>
            <link>https://medium.com/keka-engineering/how-to-achieve-thread-safety-in-ios-7b139d0a2a6a?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/7b139d0a2a6a</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Srinivas Prayag]]></dc:creator>
            <pubDate>Tue, 12 Nov 2024 08:27:00 GMT</pubDate>
            <atom:updated>2024-11-12T08:27:00.723Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s world of mobile app development, performance is crucial. But with performance comes the complexity of <strong>multithreading</strong>. Threads allow us to perform multiple tasks simultaneously, which significantly improves the responsiveness and performance of an app. However, with multiple threads comes the responsibility of <strong>thread safety</strong>. In this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ujm0Q6qjrnW-PynpOXVTQ.png" /></figure><p>This article aims to explain what thread safety is, why it matters, and how you can implement it effectively in iOS development using Swift.I will be solely concentrating on modern concurrency-based thread safety.</p><p>We will move forward this article in below order.</p><p>1. What is Thread Safety?<br>2. The Shift to Modern concurrency in Swift.<br>3.async/await Simplified Asynchronous Programming.<br>4. Actors: Built-in Protection for Shared State.<br>5. The Sendable Protocol: Ensuring Data Safety Across Threads.<br>6. Common Thread-Safety Pitfalls in iOS.<br>7. Best Practices for Thread Safety with Swift’s Modern Concurrency.<br>8. Conclusion: A Safer Future with Swift’s Concurrency.</p><h4>1. What is Thread Safety?</h4><p>In its simplest form, <strong>thread safety</strong> ensures that data can be accessed and modified by multiple threads without leading to race conditions, data corruption, or crashes. A <strong>race condition</strong> happens when two or more threads try to access shared data simultaneously, resulting in unpredictable behavior.</p><p>While thread safety has traditionally required careful management of threads and locks, Swift’s modern concurrency features make it far easier to handle multithreading correctly.</p><h4>2. The Shift to Modern concurrency in Swift.</h4><p>The introduction of <strong>modern concurrency</strong> in Swift with async/await, actors, andSendable fundamentally changed how developers approach thread safety. These features allow you to write code that is both <strong>easier to read</strong> and <strong>safer to run concurrently</strong>.</p><p>Here’s how Swift’s modern concurrency model helps with thread safety.</p><h4>3. Simplified Asynchronous Programming with async/await.</h4><p>Swift’sasync/await syntax is a game-changer for writing asynchronous code. Before this feature, developers had to deal with complex completion handlers and manual dispatching to background queues. async/await simplifies the process and ensures your background tasks run safely without blocking the main thread.</p><pre>func fetchData() async {<br>    let data = await fetchFromNetwork()<br>    await updateUI(with: data)<br>}</pre><p>This snippet shows how we can fetch data asynchronously without affecting the UI thread. The<strong>await</strong> keyword pauses execution until the asynchronous task completes, ensuring that the code that follows runs in the correct order.</p><p>Key points:<br><strong>a. Avoid blocking the main thread</strong>: By usingasync, background tasks are neatly dispatched to background threads without risking UI hangs.<br><strong>b. Clear structure</strong>: Asynchronous code reads like synchronous code, reducing the chance of bugs or unintended race conditions.</p><h4>4. Actors: Built-in Protection for Shared State.</h4><p>One of the most significant advancements in Swift’s concurrency model is <strong>actors</strong>. An actor is a reference type that protects its mutable state by serializing access to its data. This means only one task at a time can modify the actor’s state, preventing race conditions.</p><p>Here’s how an actor ensures thread safety:</p><pre>actor Counter {<br>    private var value = 0<br>    func increment() {<br>        value += 1<br>    }<br>    func getValue() -&gt; Int {<br>        return value<br>    }<br>}</pre><p>With this <strong>Counter actor</strong>, we don’t need to worry about two threads modifying value at the same time. The actor ensures that its internal state is safe from concurrent access, handling the complexity of synchronization for you.</p><p>Why actors are important:<br><strong>a. Automatic thread safety</strong>: Actors automatically handle access to their mutable state, so you don’t need to manually synchronize access to shared data.<br><strong>b. Concurrency without locks</strong>: In traditional threading, locks are often used to synchronize access to shared data, but they can lead to deadlocks and complexity. Actors remove the need for explicit locking.</p><h4>5. The Sendable Protocol: Ensuring Data Safety Across Threads</h4><p>While actors handle shared mutable state, Swift also introduced the <strong>Sendable protocol</strong> to ensure that values can be safely passed between concurrent contexts (such as tasks). Types that conform to Sendable guarantee that they are safe to be shared between threads.</p><p>For instance, simple types like Int, Bool, and String automatically conform to Sendable. However, for custom types, you might need to explicitly ensure they are thread-safe:</p><pre>struct UserData: Sendable {<br>    let name: String<br>    Let age: Int<br>}</pre><p>The Sendable protocol enforces that any type passed between tasks or threads is either immutable or designed to be accessed safely. This is another layer of protection against race conditions in concurrent programming.</p><p>Key benefits:<br><strong>a. Compile-time safety</strong>: Swift checks at compile time whether a type conforms to Sendable, catching potential concurrency issues before your app runs.<br><strong>b. Safer code architecture</strong>: By using Sendable, you’re explicitly declaring that your types are safe to use concurrently.</p><h3>6. Common Thread-Safety Pitfalls in iOS</h3><p>Even with modern concurrency, thread safety can still be tricky. Let’s explore common pitfalls and how modern Swift features can help you avoid them.</p><p><strong>a. Race Conditions<br></strong>A <strong>race condition</strong> occurs when multiple threads try to modify the same data simultaneously. Actors and Sendable types are the best defenses against this. Actors serialize access to mutable states while Sendable ensures that only safe types are passed between threads.</p><p><strong>b. Deadlocks<br></strong>A <strong>deadlock</strong> happens when two threads are waiting on each other to finish, causing both to freeze. With <strong>actors</strong>, you don’t need to worry about locks, significantly reducing the risk of deadlocks.</p><p><strong>c. UI Updates on the Main Thread<br></strong>In iOS, UI updates should always happen on the <strong>main thread</strong>. Using thisasync/await, you can ensure that background tasks handle data processing and UI updates are safely executed on the main thread:</p><pre>await MainActor.run {<br>    // Safely update UI on the main thread<br>}</pre><p>This use of MainActor.run guarantees that any UI-related changes occur in the right thread, avoiding UI glitches or crashes.</p><h4>7. Best Practices for Thread Safety with Swift’s Modern Concurrency</h4><p>To make the most of Swift’s modern concurrency tools, here are some best practices:</p><p><strong>a. Prefer </strong><strong>async/await Over GCD<br></strong>While <strong>Grand Central Dispatch (GCD)</strong> is still useful for low-level concurrency management, async/await provides a simpler, more readable way to handle asynchronous tasks. It also naturally integrates with Swift’s type system for compile-time safety.</p><p><strong>b. Use Actors for Shared Mutable State<br></strong>If your code requires sharing mutable state across tasks, prefer using <strong>actors</strong>. They provide a safer alternative to manual locking mechanisms like DispatchSemaphore or NSLock.</p><p><strong>c. Make Types </strong><strong>Sendable<br></strong>When working with concurrency, always ensure that types passed between tasks or actors are <strong>Sendable</strong>. This prevents subtle threading issues from creeping into your code.</p><p><strong>d. Avoid Over-Synchronizing<br></strong>While actors and Sendable make concurrency easier, it’s still essential not to over-synchronize. Unneeded synchronization can lead to performance bottlenecks.</p><p><strong>e. Use the Main Thread for UI Updates<br></strong>Ensure all UI updates happen on the <strong>main thread</strong> using MainActor.run. Swift’s concurrency model makes this easy, allowing you to shift execution back to the main thread as needed.</p><h4><strong>8. Conclusion: A Safer Future with Swift’s Concurrency</strong></h4><p>Swift’s modern concurrency model significantly reduces the complexity of writing thread-safe code. By using async/awaitactorsSendable, iOS developers can focus more on building features and less on the intricacies of threading. These tools provide compile-time guarantees and abstractions that make concurrent code both safer and easier to reason about.</p><p>With the power of <strong>Swift’s modern concurrency</strong>, you can write fast, responsive apps without worrying about the common pitfalls of multithreading. Embrace these tools in your codebase, and thread safety will become second nature.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b139d0a2a6a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/how-to-achieve-thread-safety-in-ios-7b139d0a2a6a">How to achieve thread safety in iOS🧵🧶</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding nonisolated in Swift actors?]]></title>
            <link>https://medium.com/keka-engineering/understanding-nonisolated-in-swift-actors-0b8e2ef4ded6?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/0b8e2ef4ded6</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Srinivas Prayag]]></dc:creator>
            <pubDate>Tue, 12 Nov 2024 07:57:07 GMT</pubDate>
            <atom:updated>2024-11-12T07:57:07.294Z</atom:updated>
            <content:encoded><![CDATA[<h4>Swift’s actors provide a powerful way to safely manage concurrent access to a shared, mutable state. By isolating their internal data, actors prevent race conditions and ensure thread safety. However, there are scenarios where certain methods or properties within an actor don’t require this isolation. For such cases, Swift introduces the nonisolated keyword.</h4><p>In this article, we’ll dive into what nonisolated means, why it&#39;s useful, and when to apply it to your Swift code. We’ll explore these concepts with a practical example, using an actor called DataProcessor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*d8uHjwI26cZ4AYhJhvt-gg.png" /></figure><h3>Why Actor Isolation Matters</h3><p>Before we explore nonisolated, it’s important to understand actor isolation. Actors enforce isolation to protect their internal mutable state from being accessed or modified from outside the actor&#39;s context. This ensures that no two parts of the code can simultaneously modify an actor’s state, which is essential for avoiding race conditions in concurrent programming. This is what <strong>actors</strong> do which <strong>class</strong> doesn’t to maintain thread safety.</p><p>By default, every access to an actor’s properties or methods must be done asynchronously using await. This includes both reading from and writing to the actor’s data. Here’s an example:</p><pre>actor DataProcessor {<br>    var processedData: [String] = []<br>    func process(data: String) {<br>        processedData.append(data)<br>    }<br>}</pre><p>In this case, the process(data:) method modifies the processedData array, which requires actor isolation. When calling process(data:) from outside the actor, Swift enforces safe access via await:</p><pre>let processor = DataProcessor()<br>await processor.process(data: &quot;New Data&quot;)</pre><p>This ensures that only one part of the program interacts with the actor’s state at a time. While this is crucial for mutable state, it becomes unnecessary for methods or properties that don’t interact with mutable state.</p><h3>Enter nonisolated: Relaxing Unnecessary Isolation</h3><p>Not all methods inside an actor need to access or modify the actor’s state. Some methods may perform simple calculations, return constant values, or format strings — operations that don’t involve any state changes. Requiring these stateless methods to be called asynchronously via await introduces unnecessary overhead.</p><p>That’s where nonisolated comes into play. By marking a method or property as nonisolated, you inform the compiler that it doesn’t need to be isolated within the actor’s context. As a result, you can call it directly from outside the actor without requiring await.</p><p>Let’s extend our DataProcessor actor with an example:</p><h3>Example: Stateless Methods in DataProcessor</h3><pre>actor DataProcessor {<br>    var processedData: [String] = []<br>// This method modifies the actor&#39;s state, so it must remain isolated<br>    func process(data: String) {<br>        processedData.append(data)<br>    }<br>    // This method is stateless, so we mark it as nonisolated<br>    nonisolated func description() -&gt; String {<br>        return &quot;DataProcessor is responsible for processing data.&quot;<br>    }<br>    // This property is also stateless, so it can be nonisolated<br>    nonisolated var author: String {<br>        return &quot;Swift Developer&quot;<br>    }<br>}</pre><h3>What Happens with nonisolated?</h3><p>In this example, both description() and author are marked as nonisolated. These methods do not interact with any mutable state inside the actor, which means they can be called synchronously, without await:</p><pre>let processor = DataProcessor()<br>// Direct synchronous access to nonisolated methods<br>print(processor.description()) // Prints: DataProcessor is responsible for processing data.<br>print(processor.author)        // Prints: Swift Developer</pre><p>Unlike the process(data:) method, which modifies the processedData array and requires asynchronous access, the description() and author methods are stateless. Therefore, Swift allows them to be accessed without isolation.</p><h3>Why Use nonisolated?</h3><p>The nonisolated keyword brings several advantages:</p><ol><li><strong>Performance Optimization</strong>: When you use nonisolated, you avoid the performance overhead of actor isolation. Since these methods don’t require the actor’s state to be thread-safe, there’s no need to switch to the actor’s internal queue. This can lead to performance gains, especially when dealing with frequently accessed methods or properties.</li><li><strong>Improved Readability</strong>: Marking methods that don’t need isolation as nonisolated improves code clarity. It signals to other developers that these methods can be safely accessed outside the actor without worrying about concurrency or async overhead.</li><li><strong>Avoiding Unnecessary </strong><strong>await</strong>: For methods that are stateless or return constants, requiring await would add unnecessary complexity. nonisolated simplifies the call site by eliminating the need for await where it isn’t required.</li></ol><h3>When Not to Use nonisolated</h3><p>While nonisolated is useful, it’s important to recognize when <strong>not</strong> to use it. You should <strong>never</strong> mark methods or properties as nonisolated if they:</p><ul><li><strong>Access mutable state</strong>: Any method that reads or writes to properties that may change over time should remain isolated.</li><li><strong>Interact with the actor’s shared resources</strong>: If a method interacts with resources that are used by other methods, isolation is necessary to prevent data races.</li></ul><p>For example, in our DataProcessor actor, the process(data:) method modifies the processedData array. It must remain isolated:</p><pre>actor DataProcessor {<br>    var processedData: [String] = []<br>// This method modifies the actor&#39;s mutable state and needs to be isolated<br>    func process(data: String) {<br>        processedData.append(data)<br>    }<br>}</pre><p>Attempting to mark process(data:) as nonisolated would violate actor isolation and result in unsafe concurrent access to the actor’s state, potentially causing race conditions.</p><h3>Conclusion</h3><p>The nonisolated keyword in Swift offers a way to optimize and simplify actor-based code by relaxing the need for isolation when it’s unnecessary. It allows methods or properties that don’t interact with mutable state to be accessed synchronously, improving performance and code clarity.</p><p>When designing actors in your Swift code, it’s essential to understand the distinction between operations that require actor isolation and those that don’t. By judiciously applying nonisolated, you can make your actors more efficient while maintaining the concurrency guarantees that actors provide.</p><p>Remember:</p><ul><li>Use nonisolated for <strong>stateless methods</strong> and <strong>constant properties</strong>.</li><li>Keep methods that modify or read mutable state <strong>isolated</strong> to ensure thread safety.</li></ul><p>With nonisolated, you can strike a balance between performance and safety in your Swift concurrency code, making actors even more powerful in your toolkit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b8e2ef4ded6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/understanding-nonisolated-in-swift-actors-0b8e2ef4ded6">Understanding nonisolated in Swift actors?</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a web App from scratch]]></title>
            <link>https://medium.com/keka-engineering/building-a-web-app-from-scratch-aa1f67cf8bcd?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/aa1f67cf8bcd</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[dotnet]]></category>
            <dc:creator><![CDATA[Suyash Shukla]]></dc:creator>
            <pubDate>Sat, 02 Nov 2024 11:26:41 GMT</pubDate>
            <atom:updated>2024-11-02T11:29:50.996Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wxw83x3EgVsJrl7H-1ANiQ.png" /></figure><p>Hello Everyone,</p><p>Having spent a good amount of time in this vast arena of software engineering, we often reflect back to measure the depth of understanding we have in our domain. I also felt the same need and went ahead to write a .NET app from scratch from a single C# file. So, what you all are waiting for, join me in this exhilarating activity without delaying any further.</p><p>We’ll start with the very basic keeping our first milestone limited to building a console application. To do that, we just need a single file to get started, a CSPROJ file which follows the XML syntax. Let’s quickly create a project directory in whichever working directory you wish to perform this activity</p><pre>md AppFromScratch<br><br>cd AppFromScratch</pre><p>Next step would be to create a new file with a <strong><em>.csproj</em></strong> extension and keep the following content within it which will ensure that the project runs as a console application and under the scope of our desired(target) .NET runtime</p><pre>echo. &gt; AppFromScratch.csproj<br><br>notepad AppFromScratch.csproj</pre><pre>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;<br>  &lt;PropertyGroup&gt;<br>    &lt;OutputType&gt;Exe&lt;/OutputType&gt;<br>    &lt;TargetFramework&gt;net8.0&lt;/TargetFramework&gt;<br>  &lt;/PropertyGroup&gt;<br>&lt;/Project&gt;</pre><p>Once the project file is initialized, it can be readily accessed from visual studio to make additional changes. We’ll open the same project in Visual Studio Editor and add a new .cs file to it. (This can be done using command prompt as well). Once the <strong><em>Program.cs</em></strong> file is created, we’ll quickly add a Console Statement and run the code to see how it unfolds</p><pre>using System;<br><br>Console.WriteLine(&quot;Hello World!&quot;);</pre><pre>Hello World!</pre><p>Bingo! The console application is ready and already at par with the templates offered by the dotnet cli. But we’ll not stop here, we’ll travel an extra mile and convert this console app to a fully functional web app.</p><p>The first step to reach there would be the need of a <strong>WebApplication</strong>. We’ll be using the <strong>CreateBuilder </strong>static method to get a builder instance on top of which we’ll start to operate. To gain access to the <strong>WebApplication</strong> class, we need to update our project sdk to <strong>Microsoft.NET.Sdk.Web </strong>from the existing <strong>Microsoft.NET.Sdk. </strong>Once that’s done, our builder can be initialized in this manner</p><pre>using Microsoft.AspNetCore.Builder;<br><br>var builder = WebApplication.CreateBuilder(args);</pre><p>Next steps would be to get an instance of the app by invoking the Build function on builder and subsequently run the complete application by exposing a minimal API endpoint.</p><pre>using Microsoft.AspNetCore.Builder;<br><br>var builder = WebApplication.CreateBuilder(args);<br><br>var app = builder.Build();<br><br>app.MapGet(&quot;/&quot;, () =&gt; &quot;Hello World!&quot;);<br><br>app.Run();</pre><p>Boom! That’s done! You don’t need any additional line of code here to run this web app. Build the project and start the application and see this Hello World string printed on the web UI when accessed through the localhost address mentioned in the application console window.</p><p>Web APIs go a long way from this point covering functionalities ranging from controllers, authentication, authorization, open API specs, etc. amongst many but this code serves as the base for all those incremental changes which will be performed during further development.</p><p>I hope this article is able to provide the much-needed understanding about what goes behind the scenes when we setup an API project template. I’ll be back again with something more to discuss with an aim to make things simpler for the curious readers out there. Till then, keep investing time and efforts to learn and explore your domain and beyond!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa1f67cf8bcd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/building-a-web-app-from-scratch-aa1f67cf8bcd">Building a web App from scratch</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Web App to IIS]]></title>
            <link>https://medium.com/keka-engineering/deploy-web-app-to-iis-bb2b362f086b?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/bb2b362f086b</guid>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[Suyash Shukla]]></dc:creator>
            <pubDate>Fri, 01 Nov 2024 11:02:40 GMT</pubDate>
            <atom:updated>2024-11-01T11:10:46.442Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNZLCHWU3EF_BnwMsjJ1Fw.png" /></figure><p>Hello Everyone,</p><p>Since the advent of cloud computing and PaaS based cloud resources, a lot of configurations have been abstracted away by the cloud provider but still it acts as limiting factor when it comes to setting up your own web server.</p><p>Microsoft offers a powerful tool on windows platform which can be configured in an interactive manner to deploy web applications on Virtual Machines. In this article, we’ll be setting up our own web server using IIS.</p><p>To begin with, we need to start IIS Server and create a website under it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*anepk-OVo5lBIihYZiI4qw.png" /><figcaption>Add Website</figcaption></figure><p>In the website creation dialog, we are selecting a physical directory to which the server listens and renders the content.</p><p>Let’s quickly create a sample Dot Net Application which will eventually be deployed on Local IIS Server.</p><p>Once the application initialization is done, we’ll be creating a publish profile which would publish the built output of the code to the directory which is acting as the content source for our IIS Application.</p><blockquote>Note: In order to deploy DotNet Core application on IIS, we need to install the hosting bundle in our machine. You can download it from here: <a href="https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-3.1.2-windows-hosting-bundle-installer">Download ASP.NET Core 3.1 Runtime (v3.1.2) — Windows Hosting Bundle Installer (microsoft.com)</a></blockquote><p>To publish a .NET web application, we’ll be using the Visual Studio Publish Wizard which can be accessed from Application Porject Context Menu. As a quickstart, we’ll be opting for Folder based deployment for our use case and publish the complete output directory to our IIS website content path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*57iQo9A6mtR_c1TqjYtDqQ.png" /><figcaption>Publish Profile for Folder Based Deployment in IIS</figcaption></figure><p>Once the publish profile is created, we’ll hit publish and the complete website will start rendering on the configured domain name, i.e., <strong>mywebsite.com</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l11_YZHAcjMyjCvDjL0yYQ.png" /><figcaption>Web App Publish to Project</figcaption></figure><p>Please note that in order to access the web app server over the configured domain, we need to add a host binding in our local machine. The same can done at an Intranet level as well by overriding the DNS Settings and pointing the traffic to the server origin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*artLJeoyl0KM_wtGOwD8lw.png" /><figcaption>Web Application running on IIS Server</figcaption></figure><p>That’s all for the scope of this article, this folder based deployment to IIS Website directory can be leveraged for quickly deploying the test application instances in your organizations network and many such other use cases.</p><p>IIS is a diverse tool with a large set of configuration and deployment profiles. You can explore it at length and customize your IIS Instances to a farther more extent. I’ll back again with a new article and an altogether newer dimension of technology to explore. Till then, keep learning and keep exploring!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb2b362f086b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/deploy-web-app-to-iis-bb2b362f086b">Deploy Web App to IIS</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Web Job and Web App to Azure]]></title>
            <link>https://medium.com/keka-engineering/deploy-web-job-and-web-app-to-azure-8099f6c88fe?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/8099f6c88fe</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Suyash Shukla]]></dc:creator>
            <pubDate>Fri, 01 Nov 2024 11:02:25 GMT</pubDate>
            <atom:updated>2024-11-01T11:08:40.623Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kfm1EJo_XMPKKpXcnaWiUw.png" /></figure><p>Hi Everyone,</p><p>Since we are aware of setting up a web job using Azure SDK, the next step would be to deploy it to a cloud resource. Readers who are yeto to get accustomed to Azure Web Jobs can refer this article for a quick start: <a href="https://medium.com/keka-engineering/azure-timer-jobs-1ab01f88f5df">Azure Timer Jobs</a></p><p>In this article, we’ll be deploying Triggo Web Job along with a Web Application to the same Azure App Service resource. But before we go ahead with the deployment, we must know how the App Service Deployment Model. All application hosts reside within the <strong>site </strong>directory in App Services and from there on the bifurcation of WebJobs and WebApp happens as under:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*YzpLVasqaFyGT-YF5LGhNQ.png" /><figcaption>App Service File Structure</figcaption></figure><p>Considering this very path structure, we’ll be writing our build definitions which would push our web app and web job to an app service cloud resource. But before we do that, we need to update our solution to include a sample web app as well along with the existing Web Job. Once done, our solution will look something similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*5A38YMOQ2kfWUEggubJ2-w.png" /><figcaption>Triggo App File Structure</figcaption></figure><p>Now we’ll push this code to our version control system and link it with some automated CI/CD Tasks. I’ll be doing it using Azure DevOps. We’ll make use of the existing ASP NET Core Build Templates with an additional Task to publish the Web Job content to the desired job directory which is understandable by app service runtime.</p><p><strong><em>Note</em></strong><em>: We need to ensure that the content is not zipped since we are going forward to deploy a composite app with a single build artifact and cloud resource.</em></p><pre># For Web App<br>--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)<br><br># For Web Job<br>--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)/app_data/jobs/continuous/triggo.job</pre><p>Once this is done, we’ll quickly build our artifact and move ahead with app service deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irZx_QVkubMbnqb0ql4yYg.png" /><figcaption>Artifact Structure</figcaption></figure><p>Now, let’s quickly define our CD Tasks for deploying the code to Azure App Service and see our web and worker running simultaneously in a single unit of cloud resource.</p><p>I already have an app service provisioned in my azure subscription hence I’ll be making use of it to deploy my code. Please ensure if you are performing variable substitution, use the wildcard for locating all json files in the build artifact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*o9k084qva-KUsbvhXYSZuA.png" /><figcaption>JSON Variable Substituion</figcaption></figure><p>Along with this, we need to configure the deployment package to be picked from a directory rather than a zip file through a wildcard since all our output files are lying flat in the build artifact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*iifC1mz2NZtUjDhu9JtxEw.png" /><figcaption>Deployment Package Configuration</figcaption></figure><p>And that’s it! We are good to go with the deployment of this composite chunk of code which will power a web app and web job simultaneously through Azure App Service. To verify if everything is running as expected, we can access the web app over FQDN and check for the logs of Job Execution in our linked storage account as we have configured the same in the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*llYlMo-eLF1TH3sOxk38Ew.png" /></figure><p>This concludes our tutorial on running web and worker over a single cloud resource using Azure App Service and Web Jobs. It can be leveraged to serve even more technical requirements with ease. I’ll be back again with more immersive content on software development and cloud. Till then keep learning and exploring!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8099f6c88fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/deploy-web-job-and-web-app-to-azure-8099f6c88fe">Deploy Web Job and Web App to Azure</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handlebars: The ultimate templating engine!]]></title>
            <link>https://medium.com/keka-engineering/handlebars-the-ultimate-templating-engine-aefe4bfb0cc6?source=rss----a91bd7d31e72---4</link>
            <guid isPermaLink="false">https://medium.com/p/aefe4bfb0cc6</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[handlebars]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Suyash Shukla]]></dc:creator>
            <pubDate>Fri, 01 Nov 2024 08:39:14 GMT</pubDate>
            <atom:updated>2024-11-01T11:05:58.926Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H2DJCPKoshP5O48I05SR8g.png" /></figure><p>Hi Everyone,</p><p>While designing a system, notifications play a big role to ensure that the customers are notified of the relevant transactions happening within the scope of the application they are using. But designing dynamic templates is one problem which need to solve before building a notification engine.</p><p>In this article, we’ll focus on generating dynamic templates for different notification use cases for a variety of application notifications like Push, Email, etc.</p><p>When we talk about notification content, it is fundamentally a string, formatted or otherwise, where some dynamic fields must be replaced to finalize the refined content before dispatching it to end users.</p><pre>var templateString = Hi {{DisplayName}}, Your KYC for Credit Card is {{Status}}.</pre><p>This message can take multiple forms based on object binding which differs from user to user. Handlebars comes into the picture at this very juncture. String replacement might not be the best way to move forward because of performance constraints. What handlebars does different is a placeholder lookup instead of direct string substitution. This ensures that performance is not compromised in pursuit of a dynamic template generation. Let’s move ahead and explore how we can leverage the power of Handlebars in C# using it’s .NET variant. You can install the nuget package from here: <a href="https://www.nuget.org/packages/Handlebars.Net">NuGet Gallery | Handlebars.Net 2.1.6</a></p><p>The first step towards working with Handlebars is to create an instance. Here’s a catch, you need not to define one since the basic functionalities are offered as a static function itself. So, we’ll compile a dynamic first to make it accessible further operations</p><pre>var template = HandlebarsDotNet.Handlebars.Compile(templateString);</pre><p>Now, the next step would be to bind dynamic objects to generate different variants. Let’s create a class to maintain the possible values for user KYC details which will be further substituted to our template to derive the dynamic content.</p><pre>public class UserKycDetails<br>{<br>    public string DisplayName { get; set; }<br><br>    public string Status { get; set; }<br><br>    public static UserKycDetails Create(string displayName, string status)<br>    {<br>        return new UserKycDetails()<br>        {<br>            DisplayName = displayName,<br>            Status = status<br>        };<br>    }<br>}</pre><p>The class is defined. Let’s go ahead and build a list with some probable values which we would like to replace in the template prepared in the previous step.</p><pre>List&lt;UserKycDetails&gt; userKycDetails = [<br>    UserKycDetails.Create(&quot;Suyash Shukla&quot;, &quot;Approved&quot;),<br>    UserKycDetails.Create(&quot;Gulshan Grover&quot;, &quot;Rejected&quot;),<br>    UserKycDetails.Create(&quot;Ramesh Sippi&quot;, &quot;Pending&quot;)<br>]</pre><p>Now, we’ll be iterating over this list to generate the dynamic template strings using handlebars</p><pre>foreach (var kyc in userKycDetails) {<br>    Console.WriteLine(template.Invoke(kyc));<br>}</pre><p>Once this complete code is executed, the console output will be something like this,</p><pre>Hi Suyash Shukla, Your KYC for Credit Card is Approved.<br>Hi Gulshan Grover, Your KYC for Credit Card is Rejected.<br>Hi Ramesh Sippi, Your KYC for Credit Card is Pending.</pre><p>This is a very basic usage explanation of handlebars. The kind of benefits it provides are way beyond regular placeholder replacement. Let’s see, how we can loop over a list to populate statements through a single template invocation. To do this, we’ll introduce another property called approval logs in the KYC object and change the template string to facilitate printing those logs during invocation. Now, the final code will look similar to the following gist.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd85e2697c076251eaeee9e776d5cfbd/href">https://medium.com/media/cd85e2697c076251eaeee9e776d5cfbd/href</a></iframe><p>As evident from the code, we have used <strong><em>{{#each}}</em></strong><em> </em>helper to iterate over the approval logs list and print the individual element separately. For the sake of simplicity, we kept the type of the element as string, but it is extensible enough to allow any form of custom objects. The output of this code execution will be as under</p><pre>Hi Suyash Shukla, Your KYC for Credit Card is Approved.<br>&gt; Initiated on 1st October<br>&gt; Sent for review on 15th October<br>&gt; Approved on 23rd October<br>Hi Gulshan Grover, Your KYC for Credit Card is Rejected.<br>Hi Ramesh Sippi, Your KYC for Credit Card is Pending.</pre><p>In the code attached above, we are accessing the loop element using <strong>this </strong>keyword. This behavior stays the same for all loop elements, no matter you are iterating over a list of primitives like string or over a list of objects.</p><p>One more exciting helper which handlebar offers is <strong>{{#if}}.</strong> Yes, we can dynamically take the decisions to toggle the visibility of a string segment based on this helper evaluation. Let’s expose another property to our kyc object based on which, a congratulatory message must be printed to the console. The gist with these code changes is as under</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06ff2bb298258611f3fb27a43e945cef/href">https://medium.com/media/06ff2bb298258611f3fb27a43e945cef/href</a></iframe><p>As you can observe, we are only printing one additional sentence when the CanTransact flag is set to true. This is achieved by simply enclosing the conditional statement withing the scope of a <strong>{{#if}}</strong> helper.</p><p>Handlebar helpers are not limited to the pre-defined structs and syntaxes, we can define custom helpers and render it in the way we want. Handlebars are extensively as an email template engine which increases it utility even more. It is a pretty rich library which has a lot to offer for different application needs. Sit back and explore it to as much extent as possible.</p><p>I’ll wrap it here keeping this article open for suggestions or feedback. I’ll be back again with something new to dive deep into. Till then, keep learning and exploring!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aefe4bfb0cc6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/keka-engineering/handlebars-the-ultimate-templating-engine-aefe4bfb0cc6">Handlebars: The ultimate templating engine!</a> was originally published in <a href="https://medium.com/keka-engineering">Keka Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>