<?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[Stories by Tarun Chawla on Medium]]></title>
        <description><![CDATA[Stories by Tarun Chawla on Medium]]></description>
        <link>https://medium.com/@tarunengineer?source=rss-16775742903d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SCMmOjBOXHYsRBIE.</url>
            <title>Stories by Tarun Chawla on Medium</title>
            <link>https://medium.com/@tarunengineer?source=rss-16775742903d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 10 Nov 2026 06:05:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tarunengineer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Publishing a Flutter android app on the google play store]]></title>
            <link>https://tarunengineer.medium.com/publishing-an-flutter-android-app-on-the-google-play-store-58be1855bea9?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/58be1855bea9</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android-app-publishing]]></category>
            <category><![CDATA[android-app-bundle]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[google-play-store]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Fri, 05 Aug 2022 09:44:46 GMT</pubDate>
            <atom:updated>2023-04-18T10:18:25.210Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nnSQN8t7ZLUPdxjL9keiXw.png" /><figcaption>Release process in brief.</figcaption></figure><h4>Prerequisite:</h4><ol><li>You have a working Android studio project for an application you are building.</li><li>The project you have could be a flutter application written in dart or react native application written in JS or a native application written in Java/Kotlin.</li><li>You have a google play <a href="https://play.google.com/console/u/0/developers">console</a> account.</li><li>You have 3–4 screenshots of your application.</li><li>You have a 1024x1024 size icon image using which we will create an icon set for different screen sizes.</li></ol><h4>Steps at a high level</h4><ol><li>Create the application icons using an icon <a href="https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html#foreground.type=clipart&amp;foreground.clipart=android&amp;foreground.space.trim=1&amp;foreground.space.pad=0.25&amp;foreColor=rgba(96%2C%20125%2C%20139%2C%200)&amp;backColor=rgb(68%2C%20138%2C%20255)&amp;crop=0&amp;backgroundShape=circle&amp;effects=none&amp;name=ic_launcher">generator</a>.</li><li>Create a key pair which will be stored in a key store and that key store will be used to sign the archive before we upload it to the google play store.</li><li>Setup google play console for a new application.</li><li>Use the archive in step 1 to upload it on the google play console and wait for google to approve it.</li></ol><h4>Create the application icons using an icon <a href="https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html#foreground.type=clipart&amp;foreground.clipart=android&amp;foreground.space.trim=1&amp;foreground.space.pad=0.25&amp;foreColor=rgba(96%2C%20125%2C%20139%2C%200)&amp;backColor=rgb(68%2C%20138%2C%20255)&amp;crop=0&amp;backgroundShape=circle&amp;effects=none&amp;name=ic_launcher">generator</a>.</h4><ol><li>Get the logo image of 1024x1024 pixels. I generated a simple logo from the canva website.</li><li>Use the icon generator <a href="https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html#foreground.type=clipart&amp;foreground.clipart=android&amp;foreground.space.trim=1&amp;foreground.space.pad=0.25&amp;foreColor=rgba(96%2C%20125%2C%20139%2C%200)&amp;backColor=rgb(68%2C%20138%2C%20255)&amp;crop=0&amp;backgroundShape=circle&amp;effects=none&amp;name=ic_launcher">link</a> to open the website.</li><li>Upload the logo.</li><li>Set the right padding and background.</li><li>Download the image folder.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*01nAXFD-gZ3QMFlZbwUPSw.gif" /><figcaption>Gif for a step-by-step guide to generating logo images for different screen resolutions</figcaption></figure><p>6. Unzip the folder and you will see logos for different screen sizes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*W7R1-k9JvZL3CbxqmRXBmQ.png" /><figcaption>Icons for android for different screen sizes.</figcaption></figure><p>7. Copy and paste the images from the downloaded folder at the exact location inside your android project. Here is the folder structure for my project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HcaKDeLqyScM6jZh0twGNQ.png" /><figcaption>Android resource folder structure.</figcaption></figure><h4>Create a key pair which will be stored in a key store and that key store will be used to sign the archive before we upload it to the google play store.</h4><ol><li>Follow the steps mentioned in this <a href="https://docs.flutter.dev/deployment/android#create-an-upload-keystore">link</a> to generate upload key pair.</li><li>Create a key.properties file so that Gradle can read the Keystore generated from the right place and open it. Please follow this <a href="https://docs.flutter.dev/deployment/android#reference-the-keystore-from-the-app">link</a>.</li><li>Configure Gradle so that for release builds it picks up the key.properties file and does the signing. Please follow this <a href="https://docs.flutter.dev/deployment/android#reference-the-keystore-from-the-app">link</a>.</li></ol><h4>Creating Android app bundle (aab)</h4><p>Please follow this <a href="https://docs.flutter.dev/deployment/android#build-an-app-bundle">link</a>.</p><h4>Create an application and upload it on your google play console account</h4><ol><li>Open google play <a href="https://accounts.google.com/ServiceLogin?service=androiddeveloper&amp;passive=true&amp;continue=https%3A%2F%2Fplay.google.com%2Fconsole%2Fdeveloper%2F&amp;_ga=2.57361706.1087299882.1659691084-1214229760.1654322215&amp;_gac=1.181728725.1659691084.Cj0KCQjw_7KXBhCoARIsAPdPTfj_2Z4PkCh03qgNmqgHKV12oyykKj-W5Ji9colU66XIy80mz4RlSRsaAjyzEALw_wcB">console</a>.</li><li>Create a new app using create app button.</li><li>Create a new release and upload the aab generated by the previous step.</li><li>You can explore the google play console a little bit to get comfortable.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a7zE6i0fewX_pCUDrsaRxg.gif" /><figcaption>Google play console aab upload process in brief.</figcaption></figure><h4>More about release philosophy can be read here.</h4><ol><li>Detailed instructions on the flutter <a href="https://docs.flutter.dev/deployment/android">website</a>.</li><li>Google play console <a href="https://play.google.com/console/about/guides/releasewithconfidence/">instructions</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58be1855bea9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Privacy Policy]]></title>
            <link>https://tarunengineer.medium.com/privacy-policy-5909f4ed056a?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5909f4ed056a</guid>
            <category><![CDATA[privacy-policy]]></category>
            <category><![CDATA[personal]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Sat, 16 Jul 2022 10:39:24 GMT</pubDate>
            <atom:updated>2022-07-16T10:39:24.394Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>We don’t create user profiles which depict your behaviour based on your usage but we do save your preferences.</li><li>We use firebase to store news source image URLs and news articles themselves.</li><li>We use various RSS Feed sources to curate news for you.</li><li>Currently, we don’t have any authentication mechanism but in future, we will add social logins and username/password logins to save your preferences. Before using social login please do read their privacy policies as we are just using it for authentication.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5909f4ed056a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Soundness & Generics in Dart — Part II]]></title>
            <link>https://tarunengineer.medium.com/soundness-generics-in-dart-part-ii-56259a20fb2c?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/56259a20fb2c</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[generics-programming]]></category>
            <category><![CDATA[soundness]]></category>
            <category><![CDATA[generics]]></category>
            <category><![CDATA[subtyping]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Sat, 07 May 2022 09:57:39 GMT</pubDate>
            <atom:updated>2022-05-07T10:07:43.170Z</atom:updated>
            <content:encoded><![CDATA[<h3>Soundness &amp; Subtyping in Dart Generics— Part II</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*obSehS9r9FaGyyPu3X8Jag.png" /></figure><h4>What is Soundness in Dart?</h4><p>In languages like Dart, C++, Kotlin, Swift etc, the type of expression is known at compile-time and we are calling it a static type. These languages are also called statically typed languages.</p><p>Soundness means ensuring your program does not get into certain invalid states. A sound system makes sure that the expression evaluates to a value and that its type is the same as the expression&#39;s static type.</p><p>Benefits of Soundness:</p><ol><li>Catching type errors even before compiling it with the aid of IDEs like Intellij, Visual Studio code etc.</li><li>Readable code.</li><li>Maintainable code: If you are creating type related issues somewhere else, IDE will catch it for you.</li><li>Better ahead of time compilation(AOT) as it leads to efficient generation of low-level code before your code is executed.</li></ol><h4>How does overriding work in Dart while returning a type in a function?</h4><p>Please bear with me, I promise this will be critical for your generics understanding.</p><p>Here is a class:</p><pre>class Animal {<br>    Animal get parent =&gt; ...<br>    void chase(Animal a){ ... }<br>}</pre><p>Now let&#39;s say you want to extend this you created below class:</p><pre>class Cat extends Animal {<br>    @override<br>    Animal get parent =&gt; ...<br>}</pre><p>You can see that you are trying to override the parent <strong>getter</strong>. Dart allows any subtype of Animal (base class getter return type) in the overridden method. In this case, you could have returned Cat, Lion etc.</p><pre>class Cat extends Animal {<br>    @override<br>    Cat get parent =&gt; ...<br>}</pre><p>Dart is okay with any subtype as it does not bother as long as it has the essence of an Animal. If you try to return Object, it will complain as Dart wants to return Animal in some form otherwise it is not an override.</p><blockquote>Tip: Always return the same type or subtype of the return type while overriding.</blockquote><h4>How does overriding work in Dart in parameter type in a function?</h4><p>Let&#39;s look at the chase function now. It says I accept an Animal to chase it and hunt it down.</p><pre>class Animal {<br>    Animal get parent =&gt; ...<br>    void chase(Animal a){ ... }<br>}</pre><p>If you try to override with any subtype then basically you are tightening the scope further by saying now I won’t accept anything other than the new subtype.</p><pre>class Cat {<br>    Cat get parent =&gt; ...<br>    @override<br>    void chase(Cat a) { ... } //Here dart will complain as it is not a valid override.<br>}</pre><p>Here, Dart is saying bro/sis I don’t want you to tighten this as it defeats the purpose of overriding, I want Animal to be allowed in the <strong>chase </strong>function, not its subtype. Now you will be wondering why it allows supertype, it will get more clear when you understand the concept of consumer and producer further in the article.</p><blockquote>Tip: Always use the same type or its supertype in the parameter of the function you are overriding.</blockquote><h4>Substituting types</h4><p>Ok for overriding we understand now what type we can choose. But what about assignments and passing arguments to functions. Dart allows certain sub and supertypes. It&#39;s easier to think in terms of producers and consumers. A consumer absorbs a type and a producer generates a type.</p><pre>Animal animal = Cat();</pre><p>Here left-hand side(LHS) is the consumer and the right-hand side(RHS) is the producer. Logically any supertype as a consumer will make sense as the producer will always have supertype behaviour (even if it&#39;s overridden). In programming terms, you can call all Animal methods and properties in the above example without any runtime or compile-time issues. Dart says consumers can have the same type as producers or any supertype will work.</p><blockquote>Tip: Consumers can have the same or super type of producer.</blockquote><p>For producers, it is the reverse. Any subtype can be used for producers.</p><pre>Animal animal = Cat()<br>Animal animal = Lion()</pre><p>See, <strong>Cat</strong> and <strong>Lion</strong> both fit as a producer as they both are supertypes and the same logic which I shared above explains why this is allowed.</p><h4>Now the question is, are the rules we discussed above fit for generic type?</h4><p>And the answer is <strong>yes</strong>.</p><p>In Dart types are not erased for Generic types, it is much easier to work in Dart with generics. What this means is that, if you have a list of integers in Java and Dart then in Dart you can check if the type is <strong>List&lt;int&gt;</strong> but in Java type gets erased at run time and therefore you can’t tell what is the underlying type of the list. In Java, you can only tell if this is a list or not.</p><p>In Dart, this is absolutely fine.</p><pre>List&lt;Animal&gt; animalList = &lt;Cat&gt;[];</pre><p>I think with this article you will build a strong foundation of Generics in Dart.</p><h4>References:</h4><ol><li>Part-I : <a href="https://tarunengineer.medium.com/generics-in-dart-part-i-bd2ca66e0e57">https://tarunengineer.medium.com/generics-in-dart-part-i-bd2ca66e0e57</a></li><li><a href="https://dart.dev/guides/language/type-system#generic-type-assignment">https://dart.dev/guides/language/type-system#generic-type-assignment</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56259a20fb2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generics in Dart — Part I]]></title>
            <link>https://tarunengineer.medium.com/generics-in-dart-part-i-bd2ca66e0e57?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd2ca66e0e57</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[generic-programming]]></category>
            <category><![CDATA[generics]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Sat, 07 May 2022 07:59:31 GMT</pubDate>
            <atom:updated>2022-05-07T09:59:30.834Z</atom:updated>
            <content:encoded><![CDATA[<h3>Generics in Dart — Part I</h3><h4>Intro to generics in Dart.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*obSehS9r9FaGyyPu3X8Jag.png" /></figure><h4>We will discuss the below topics in two parts:</h4><ol><li>Intro to Generics for creating generic classes and functions.</li><li>How does it fit in the Dart type system (you can read it as Subtyping in Dart if you are coming from the Java world)?</li></ol><p><strong>In this, we will solely focus on 1.</strong></p><p><strong>Generics are often used for primarily two purposes:</strong></p><ol><li>To reduce code duplication.</li><li>Better generated code.</li></ol><h4>How to create a Generic class?</h4><p>Let us suppose there are no generics in Dart and you need to create an interface for a cache which simply stores a value for a key. Either you will use dynamic or spend all day creating abstract classes for different types e.g <strong>ObjectCache</strong> &amp; <strong>StringCache</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13827ff19d88b24e7bde1c9797a6825d/href">https://medium.com/media/13827ff19d88b24e7bde1c9797a6825d/href</a></iframe><p>Now let’s see how we will use generics here. The annotation <strong>&lt;..&gt; </strong>marks a class as a generic type. By convention, most type variables have single-letter names such as E, K &amp; T etc.</p><p>Replacing concrete type with type variable T we are able to create a <strong>Cache</strong> class via which we can create Cache for any type without rewriting the interface again and again for different types. Below is an example of how you create <strong>StringCache</strong> which extends the generic <strong>Cache</strong> interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/090fed7bfc35299e0cc65ad7fb03cac4/href">https://medium.com/media/090fed7bfc35299e0cc65ad7fb03cac4/href</a></iframe><p>Similarly we can implement concrete generic class, lets take example of Stack.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fad1c475604412a69486c1683954c66/href">https://medium.com/media/1fad1c475604412a69486c1683954c66/href</a></iframe><h4>How to create generic methods?</h4><p>Earlier Dart used to support only class generics but now it supports generic methods as well. Below is one example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca070220627094367bde4e6bf0f097a8/href">https://medium.com/media/ca070220627094367bde4e6bf0f097a8/href</a></iframe><h4>Restricting the parameterized type</h4><p>Sometimes you might want to restrict the type user of your generic type can provide.</p><p>A common use case is to prevent nullable type from being passed as a type parameter by making it a subtype of Object. Here are a few examples:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1042de1b68237dfd8bb7baecd2cf56b/href">https://medium.com/media/e1042de1b68237dfd8bb7baecd2cf56b/href</a></iframe><h4>References:</h4><ol><li>Part-II : <a href="https://tarunengineer.medium.com/soundness-generics-in-dart-part-ii-56259a20fb2c">https://tarunengineer.medium.com/soundness-generics-in-dart-part-ii-56259a20fb2c</a></li><li><a href="https://dart.dev/guides/language/language-tour#generics">https://dart.dev/guides/language/language-tour#generics</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd2ca66e0e57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My take on the base model of the latest MacBook pro 14 in 2022]]></title>
            <link>https://tarunengineer.medium.com/my-take-on-the-base-model-of-the-latest-macbook-pro-14-fec3eafaa71b?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fec3eafaa71b</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[macbook-pro]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Sun, 10 Apr 2022 15:35:24 GMT</pubDate>
            <atom:updated>2022-04-10T15:36:43.487Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5o92iRAYETUIGlIJSVwcLA.jpeg" /><figcaption>My new MacBook pro 14 base model.</figcaption></figure><p><strong>Target audience:</strong></p><ol><li>People who are looking to buy a MacBook pro that is portable, powerful and efficient and has budget constraints.</li><li>People who have already set their eye on the Macbook pro 14 base model and are just looking for an external reasonable voice.</li><li>Budget under $2000/INR 1.7 lakhs.</li><li>You are a Software Developer.</li></ol><h4>Why not buy Macbook Pro 13?</h4><ol><li>If you need 16 Gb ram then you need to customize it and it will cost you $1499. Even then you will get only 256GB SSD. Further, if you upgrade SSD to 512 GB it will cost you $1699.</li><li>MacBook Pro 14 base model has 16 GB ram, 512 GB SSD, upgraded chassis with better and more ports and heat management, better processor, upgraded display, FHD webcam etc. It will cost you $1999.</li><li>SSD speed of Macbook Pro 14 is 3X that of the 13-inch version.</li><li>MacBook Pro 14 Ram speed, Display, speakers and ports are superior in every sense when compared to Macbook Pro 13.</li><li>Just for $200, you are getting a much much better deal if you go for Macbook pro 14.</li></ol><h4>My Observations:</h4><ol><li>Awesome battery life of around 15 hours.</li><li>No fan noise. Actually, I have not heard a fan spinning for a single time even while running two simulators (one android and one iOS), Android Studio, Xcode and other applications in parallel.</li><li>It&#39;s portable (it&#39;s big deal). Now I can switch between working with an external monitor and directly on the laptop with ease.</li><li>Awesome speakers.</li><li>I can keep it on my lap the whole day without worrying about my fertility.</li><li>It feels like a major upgrade from the intel i7 MacBook pro 16 version (my office laptop). Office laptop spins like crazy when connected to an external monitor but my new laptop is super silent.</li><li>The MagSafe charger is awesome.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fec3eafaa71b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concurrency in Dart -Part III]]></title>
            <link>https://tarunengineer.medium.com/concurrency-in-dart-part-iii-2086329d82a2?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2086329d82a2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 12:17:45 GMT</pubDate>
            <atom:updated>2022-03-30T13:21:34.601Z</atom:updated>
            <content:encoded><![CDATA[<p>Concurrency in Action</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4oNAKrXibZCL4ShHJjhsVw.png" /><figcaption>Concurrency in dart.</figcaption></figure><p>This article handles a scenario where there is an async function called foo() and it calls another async function bar() multiple times and awaits on it. Now what we want is if I call foo() multiple times then each foo() execution should take place one after the other.</p><p>Code snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8626b14cc985ddec3398b546407b0316/href">https://medium.com/media/8626b14cc985ddec3398b546407b0316/href</a></iframe><p>Output:</p><pre>entering foo function for value 5</pre><pre>Before first bar await for value 5</pre><pre>entering foo function for value 10</pre><pre>Before first bar await for value 10</pre><pre>entering foo function for value 15</pre><pre>Before first bar await for value 15</pre><pre>entering foo function for value 29</pre><pre>Before first bar await for value 29</pre><pre>Before second bar await for value 5</pre><pre>Before second bar await for value 10</pre><pre>Before second bar await for value 15</pre><pre>Before second bar await for value 29</pre><pre>Before third bar await for value 5</pre><pre>Before third bar await for value 10</pre><pre>Before third bar await for value 15</pre><pre>Before third bar await for value 29</pre><pre>Before last bar await for value 5</pre><pre>Before last bar await for value 10</pre><pre>Before last bar await for value 15</pre><pre>Before last bar await for value 29</pre><pre>29</pre><p><strong>Problem</strong>: As a programmer, I want that foo() should complete itself before any other foo() calls the first bar() function.</p><p><strong>Solution</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32c7fa2c3c5ae8a1644945a05bc6ba43/href">https://medium.com/media/32c7fa2c3c5ae8a1644945a05bc6ba43/href</a></iframe><p><strong>Output:</strong></p><pre>entering foo function for value 1</pre><pre>go for value 1</pre><pre>Before first bar await for value 1</pre><pre>entering foo function for value 2</pre><pre>waiting for value 2</pre><pre>entering foo function for value 3</pre><pre>waiting for value 3</pre><pre>entering foo function for value 4</pre><pre>waiting for value 4</pre><pre>Before second bar await for value 1</pre><pre>Before third bar await for value 1</pre><pre>Before last bar await for value 1</pre><pre>completed foo for value 1</pre><pre>unlocked for 2</pre><pre>entering foo function for value 2</pre><pre>go for value 2</pre><pre>Before first bar await for value 2</pre><pre>unlocked for 3</pre><pre>entering foo function for value 3</pre><pre>waiting for value 3</pre><pre>unlocked for 4</pre><pre>entering foo function for value 4</pre><pre>waiting for value 4</pre><pre>Before second bar await for value 2</pre><pre>Before third bar await for value 2</pre><pre>Before last bar await for value 2</pre><pre>completed foo for value 2</pre><pre>unlocked for 3</pre><pre>entering foo function for value 3</pre><pre>go for value 3</pre><pre>Before first bar await for value 3</pre><pre>unlocked for 4</pre><pre>entering foo function for value 4</pre><pre>waiting for value 4</pre><pre>Before second bar await for value 3</pre><pre>Before third bar await for value 3</pre><pre>Before last bar await for value 3</pre><pre>completed foo for value 3</pre><pre>unlocked for 4</pre><pre>entering foo function for value 4</pre><pre>go for value 4</pre><pre>Before first bar await for value 4</pre><pre>Before second bar await for value 4</pre><pre>Before third bar await for value 4</pre><pre>Before last bar await for value 4</pre><pre>completed foo for value 4</pre><pre>4</pre><h4>Explanation</h4><p>We are using a <em>Future&lt;void&gt; isWorking</em> here which only completes at the end of foo(). Any other call to foo() while foo() is working is awaited on <em>isWorking</em> future. To complete the isWorking future we are using Completer which gives us a way to complete the future, once Completer says it is completed, the event queue picks up the first awaited foo() function at line no 9.</p><p>Further readings:</p><ol><li><a href="https://tarunengineer.medium.com/concurrency-in-dart-part-i-d20bf5fcb250"><em>Concurrency in Dart — Part I</em></a></li><li><a href="https://tarunengineer.medium.com/concurrency-in-dart-part-ii-e67ec0f110c4"><em>Concurrency in Dart — Part II</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2086329d82a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concurrency in Dart — Part II]]></title>
            <link>https://medium.com/codex/concurrency-in-dart-part-ii-e67ec0f110c4?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e67ec0f110c4</guid>
            <category><![CDATA[completer]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 12:12:44 GMT</pubDate>
            <atom:updated>2022-05-14T17:19:56.865Z</atom:updated>
            <content:encoded><![CDATA[<h3>Concurrency in Dart — Part II</h3><p>async, future, await and completer in dart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*G5KvDKNESwTYrbALGN_K2Q.png" /></figure><h3>Future</h3><p>Dart has a type Future which is a promise to return a value of a certain type later.</p><pre>Future&lt;int&gt; countTheStars();</pre><p>Future itself is generic and can provide any type. If you call this function then it will immediately return a <em>Future&lt;int&gt;</em>. This future can be listened to or waited upon. In the background, it will call ISRO/NASA HTTP APIs (If any of these are available) and returns several stars or error (due to some issue). Assuming that you were listening to the future and therefore the result will be passed to you then.</p><p>Once the star counting machine returns from NASA/ISRO then it comes to Dart and tells it to put it back on the <strong>event queue</strong>. As we know <strong>event loop</strong> process the tasks in the event queue and eventually Future who was listening to the result will be notified once the results are picked from the event queue.</p><p><strong>Future can be in any of these states</strong></p><ol><li>Uncompleted.</li><li>Completed with a value.</li><li>Completed with an error.</li></ol><p>Ex:</p><pre>final myFuture = Future&lt;int&gt;.delayed(<br>  Duration(milliseconds:1),<br>  () =&gt; 42,<br>);</pre><p><strong>Future.delayed</strong> is a function that returns a future. It accepts a <strong>Duration</strong> object and a function that returns a value (based on future type, here is int). Dart runs this function after the duration mentioned by the Duration object.</p><h3>Getting value from a Future</h3><p>If you try to print myFuture then you will get this result:</p><pre>print(myFuture)<br><strong>Result:<br></strong>Instance of &#39;Future&lt;int&gt;&#39;</pre><h4>Getting results with callback</h4><p>There are three callbacks: <strong>then</strong>, <strong>catchError</strong> and <strong>whenComplete</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f09d91adbef97db2c63144c9ada3be9/href">https://medium.com/media/7f09d91adbef97db2c63144c9ada3be9/href</a></iframe><pre><strong>Output</strong><br>After the future<br>32<br>Future completed</pre><p>If you read the last <a href="https://tarunengineer.medium.com/concurrency-in-dart-part-i-d20bf5fcb250">article</a> then you would know why this is the order of print statements. print() is a synchronous function and <strong>Future.delayed</strong> is an asynchronous function.</p><blockquote>The interesting thing to note here is that even if the duration was 0 milliseconds then also future code would have been pushed to the event queue and synchronous code would run first.</blockquote><h4>Getting the result with async-await</h4><p>Callbacks are pretty easy to understand but they can be hard to read and implement. Our mind thinks better sequentially I believe. Also if you nest them then it is even more difficult. Just search <strong>callback hell</strong> in google once you will get the answers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/716dc21e102d575c9a93e02fbc9ae662/href">https://medium.com/media/716dc21e102d575c9a93e02fbc9ae662/href</a></iframe><p><strong>await</strong> works as syntactic sugar on top of then &amp; catchError. Here the whole async function gets to be treated like a <strong>Future</strong>. Any function which uses await has to be an <strong>async</strong> function. When the called future function on which you are waiting is completed then it tells dart to put it back on the event queue and then it is picked like earlier. This happens for each awaits invocation. Using try-catch you see how you can catch errors as well as get to know when the future is completed.</p><p>Here as the await makes the flow synchronous logically, “after the future” is printed only after the future is completed.</p><pre><strong>Output</strong><br>32<br>future is complete<br>after the future</pre><h3>Completer</h3><p>Ok, now you understand Future &amp; async-await. Now you are using an HTTP library for the rest APIs which is purely based on callbacks(non Future dart API) and you want to use present a Dart facade to your consumers. In this case, <strong>Completer </strong>comes to the rescue.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc17c0a5e4f7d09dd088c88879a76f80/href">https://medium.com/media/fc17c0a5e4f7d09dd088c88879a76f80/href</a></iframe><p>In line number 4 we create a <strong>Completer</strong> that returns a String when it completes. Completer has a future property which has a type of Future and you can normally use different ways as discussed above to get a value from it. If you see getHttpData receives two anonymous functions: onComplete and onError. In those anonymous functions, we can use our completer instance to complete it and the listener to the future will either receives the value or error based on the results from the HTTP library.</p><p><strong>Further readings:</strong></p><ol><li><a href="https://tarunengineer.medium.com/concurrency-in-dart-part-i-d20bf5fcb250"><em>Concurrency in Dart: Part — I.</em></a></li><li><a href="https://tarunengineer.medium.com/concurrency-in-dart-part-iii-2086329d82a2"><em>Concurrency in Dart: Part — III.</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e67ec0f110c4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/concurrency-in-dart-part-ii-e67ec0f110c4">Concurrency in Dart — Part II</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concurrency in Dart — Part I]]></title>
            <link>https://medium.com/codex/concurrency-in-dart-part-i-d20bf5fcb250?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d20bf5fcb250</guid>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[parallel-processing]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 08:09:15 GMT</pubDate>
            <atom:updated>2022-05-14T17:19:22.518Z</atom:updated>
            <content:encoded><![CDATA[<h3>Concurrency in Dart — Part I</h3><p>An introduction to concurrency in dart and in general.</p><p>If you are coming from a world of the language of parallel processes or threads like Java/C++/Kotlin etc then at the start it might be difficult to wrap your head around JS/Dart single-threaded approach. You might have heard that Javascript and Dart are single-threaded, let&#39;s deep dive into this approach. I will help you to create a good understanding of underlying concepts here.</p><h4>Parallelism and Concurrency</h4><p>When multiple tasks are executed on multiple cores on a machine it is called parallelism. It can be done via threads or processes on an operating system.</p><p>Concurrency on the other hand talks about where tasks take their turns to get executed on a single core. It&#39;s like a single person taking orders from a people queue.</p><p>Important points:</p><ol><li>No race conditions can happen between asynchronous tasks in a single-threaded environment like Dart as there is only one task running at any point in time.</li><li>You will still need a way to enforce serialization at places where you want to enter an async function only once and others have to wait for the previous invocation to complete. We will discuss this with an <a href="https://tarunengineer.medium.com/concurrency-in-dart-part-iii-2086329d82a2">example</a> later.</li><li>Multiple threads can have simultaneous access to memory in case of parallelism and for managing race conditions we have to use systems like mutexes which enforce atomicity of instructions.</li><li>Dart has a way to create threads via Isolates but they don’t share a memory with other Isolates and communication can happen only via messaging.</li></ol><h4>Synchronous vs Asynchronous code</h4><p>Synchronous means execution of code in step by step manner. In asynchronous execution is out of order, here certain tasks are rescheduled to be run in future. If you see in the below example, in the case of the asynchronous actual order of output is different from the written order.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb0d671c604a52513df1665d4b2beb33/href">https://medium.com/media/bb0d671c604a52513df1665d4b2beb33/href</a></iframe><p>Output:</p><pre>First<br>Second<br>third</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5f8ee7d4462bcee879f03e2b3f2f9cb/href">https://medium.com/media/f5f8ee7d4462bcee879f03e2b3f2f9cb/href</a></iframe><p>Output</p><pre>Third<br>Second<br>First</pre><h4>The event loop</h4><p>In dart single thread runs in what is called <strong>isolate</strong>. The isolate used by the dart itself is called the <strong>main isolate</strong>. It has its allocated memory area and no other dart isolate can access this memory. Dart uses an <strong>event loop</strong> to execute tasks that had previously been postponed. The dart has two queues: a <strong>microtask queue</strong> and an <strong>event queue</strong>. The microtask queue is mostly used internally by Dart. The event queue is for events like user touching screen, keystroke, data coming from database, file or remote server etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2bpQVU69mmoOovKtNWS2A.png" /></figure><ul><li>Synchronous tasks in the main isolate always run immediately. You cannot interrupt them.</li><li>If any long-running task needs to be postponed then Dart puts them in the event queue.</li><li>Once synchronous tasks are finished then the event loops check tasks in the microtask queue and puts them on the main isolate for execution. This is continuous until the microtask queue is empty.</li><li>If the microtask queue and synchronous tasks queue are empty then the event loop starts picking up tasks from the event queue.</li><li>If any new tasks enter the microtask queue then event loops pick them up before picking up any further tasks from the event queue.</li><li>This process continues until all of the queues are empty.</li></ul><h4>An important point before we conclude this Part I</h4><p>Although the dart is single-threaded it does not mean you cannot have tasks running on another thread.</p><ol><li>One example is when we request to read a file then that work actually happens on its own process in the system and once the work is finished it passes the result back to dart via event queue. A lot of dart I/O work from <em>dart: io</em> library happens this way.</li><li>Another way to perform work on other threads is to create a new Dart isolate. Different isolates can talk to each other via messaging. Internally isolates are implemented via operating system methods such as thread and processes but internal implementation details are hidden from the application programmer.</li></ol><p>Further readings:</p><ol><li><a href="https://tarunengineer.medium.com/concurrency-in-dart-part-ii-e67ec0f110c4"><em>Concurrency in Dart: Part — II</em></a></li><li><a href="https://tarunengineer.medium.com/concurrency-in-dart-part-iii-2086329d82a2"><em>Concurrency in Dart: Part — III</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d20bf5fcb250" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/concurrency-in-dart-part-i-d20bf5fcb250">Concurrency in Dart — Part I</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Outline of mathematics of asymmetric(public/private) cryptography or RSA algorithm]]></title>
            <link>https://tarunengineer.medium.com/outline-of-mathematics-of-asymmetric-public-private-cryptography-or-rsa-algorithm-892d8f0e5ad8?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/892d8f0e5ad8</guid>
            <category><![CDATA[asymmetric-cryptography]]></category>
            <category><![CDATA[diffie-hellman]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[rsa]]></category>
            <category><![CDATA[encryption]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Thu, 03 Mar 2022 07:51:45 GMT</pubDate>
            <atom:updated>2022-03-03T07:51:45.085Z</atom:updated>
            <content:encoded><![CDATA[<p>Public/private cryptography is complex in detail but simple in outline. This article is an outline that will prep you to deep dive further if you want to.</p><h4>How it works at a high level:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*72ShKJuQ2PF3dK5xRVGtkg.png" /><figcaption>Asymmetric cryptography</figcaption></figure><p>Alice wants to receive a secret message from Bob. Alice has two keys, a public, and a private key. The public key as the name suggests is shared on Alice&#39;s website. Alice&#39;s private key is not shared with anyone.</p><p>Bob encrypts the message with Alice&#39;s public key — sends it to Alice → Alice decrypts the message with its private key.</p><p>No one can decrypt once the message is encoded with the public key, only the private key can be used to decrypt.</p><p><strong>What are the factors of a number?</strong></p><p><strong>Factor:</strong> It is a number that divides another number evenly i.e with no remainder e.g for 20, 5 is a factor as 5*4 = 20, and similarly 2 is also a factor of 20 as 2x10 = 20.</p><p>Here we are talking about all the factors of a number.</p><h4>What are prime numbers?</h4><p>Prime numbers are numbers that have only two factors including 1 and themselves e.g 2, 3, 5, 7, 11, 13, 17, etc.</p><h4>The math of this solution</h4><p>It is very easy to multiply two numbers but very difficult and time-consuming to find the factors of a number e.g for 1459160519 can you tell me what are the factors of this number given that I got this number by multiplying two numbers? Modern computers can tell you a little faster but it also has to try the most possible combinations. For any number, the computer has to check something that is the order of size of the square root of the number to be factored. The square root of 1459160519 is roughly 38000 so there are 38000 possibilities to try for a computer to find its factors.</p><p>Not let us understand the enormity of complexity here. The universe life is supposed to be 10¹⁸ seconds. Assuming a decent modern computer can check about a million(10⁶) factors per second that means in the lifetime of the universe, the computer can check approximately 10²⁴ factors. For a 100 digit number, the number of digits in the square root will be 50. The number of factors a computer has to try in this case is 10⁵⁰. That means a computer will need more than two lifetimes of a universe to find the factors of a number having 100 digits.</p><p>In the RSA algorithm, two big prime numbers p and q are chosen. A number N is calculated by p x q. This N becomes a public key that can be shared with the public (you see it is almost impossible to find p and q for fairly large N say 1000 digits by any modern computer). Logic is to encode using p and q and decode using N or vice versa. If someone wants to send you some information securely then they can encode the information using public number N, the owner who has p &amp; q can easily decode the information. No one in the world can decode until they have p &amp; q.</p><p>On a little low level this is how it goes if you are interested:</p><ol><li>Person A selects two prime numbers p &amp; q.</li><li>Person A gets the public key N by multiplying p &amp; q i.e p x q</li><li>Person A also chooses e which should be relatively prime to (p-1)x(q-1). This also is shared along with N.</li><li>Assuming they have both decided to assume the messages are represented in numbers, Person B has enough details to encode a message. If message to be sent is M = 35, then encode message C = M^e(mode N).</li><li>To decode the message Person A has to find a number d such that e x d = 1(mod(p-1)(q-1)).</li><li>Decoded message D = C^d(mode N).</li></ol><h4>Uses of RSA Algorithm</h4><ol><li>Diffie Hellman key exchange — used for sharing secret keys.</li><li>Digital signatures — Provides a way to digitally sign your documents.</li><li>Web security — SSL.</li><li>Email security — PGP</li></ol><p><strong>References:</strong></p><ol><li><a href="https://en.wikipedia.org/wiki/RSA_(cryptosystem)">https://en.wikipedia.org/wiki/RSA_(cryptosystem)</a></li><li><a href="https://math.berkeley.edu/~kpmann/encryption.pdf">https://math.berkeley.edu/~kpmann/encryption.pdf</a></li><li><a href="https://www.geeksforgeeks.org/rsa-algorithm-cryptography/">https://www.geeksforgeeks.org/rsa-algorithm-cryptography/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=892d8f0e5ad8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apple spring event confirmed for 8th March 2022]]></title>
            <link>https://tarunengineer.medium.com/apple-spring-event-confirmed-for-8th-march-2022-9282fc45fe99?source=rss-16775742903d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9282fc45fe99</guid>
            <category><![CDATA[ｍac]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[new-launch]]></category>
            <category><![CDATA[events]]></category>
            <category><![CDATA[8th-march]]></category>
            <dc:creator><![CDATA[Tarun Chawla]]></dc:creator>
            <pubDate>Thu, 03 Mar 2022 07:49:32 GMT</pubDate>
            <atom:updated>2022-03-03T07:49:32.951Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94VQeuQdEfvYnqodD3VUpw.png" /><figcaption>Apple spring event on 8th March, Courtesy Apple Inc.</figcaption></figure><p>Finally, we got the confirmation that the Apple spring event 2022 has been confirmed for 8th March 2022.</p><p>Products am looking forward to being launched at this event are:</p><ol><li><strong>Mac mini 2022</strong><br>For someone with a low budget, the Mac mini is no less than a boon. Be it performance, efficiency, or versatility mac mini has it all. Am hoping that the Mac mini with M1 pro, max chips will be launched. This mac mini could have a new design and more ports. The previous Mac mini comes with a max of 16GB ram which might be not enough for heavy workloads and future-proofing, this new Mac mini will have more options in terms of upgradability.<br>Also, SSD speeds and memory bandwidth will be higher than the previous mac mini.</li><li><strong>iMac 27 or iMac Pro</strong><br>With the launch of the iMac 24, it was speculated that soon Apple will upgrade and redesign 27 inch iMac with more powerful chips and configurations. This iMac might come with a pro-motion display, a bigger screen, more ram configurations, and more CPU configurations on par with MacBook pro.</li><li><strong>iPad Air 5th gen</strong><br>Apple is expected to launch the next version of its popular iPad Air. The fifth-generation iPad Air might include an A15 Bionic chip, a 12-megapixel Ultra Wide front camera with Center Stage support, 5G support for cellular models, and Quad-LED True Tone flash. The iPad Air falls between the iPad mini and iPad Pro range.</li><li><strong>MacBook Pro 13 (upgraded with M2 or M1Pro chips)</strong><br>I would like to see more CPU options in the current Macbook Pro 13. Right now we only have the option to choose the M1 chip with a max of 16GB ram. I am ok if the design is kept old as that will keep the cost lower for price-conscious consumers who are good with hanging with old designs longer but want to keep up with performance.</li><li><strong>iPhone SE 2022</strong><br>iPhone SE has been a great value for money for iPhone buyers. It has all the bells and whistles for a customer who wants the best performance of hardware and software both but is fine with less powerful cameras and happy to use old design for various reasons. This iPhone might come with an A15 bionic chip, a 5G modem and we might see design changes to improve screen body ratio.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9282fc45fe99" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>