<?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 Reyhan Dağcı on Medium]]></title>
        <description><![CDATA[Stories by Reyhan Dağcı on Medium]]></description>
        <link>https://medium.com/@reyhandagci?source=rss-414b2954a2ba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4PiSC5HWE6fZe_HOV43tEQ.jpeg</url>
            <title>Stories by Reyhan Dağcı on Medium</title>
            <link>https://medium.com/@reyhandagci?source=rss-414b2954a2ba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:40:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@reyhandagci/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[Angular Usefull New Features Comes with 16 and 17]]></title>
            <link>https://medium.com/@reyhandagci/angular-usefull-new-features-comes-with-16-and-17-5f1cc5b69e42?source=rss-414b2954a2ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f1cc5b69e42</guid>
            <category><![CDATA[angularfeatures]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[angular-signals]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[framework]]></category>
            <dc:creator><![CDATA[Reyhan Dağcı]]></dc:creator>
            <pubDate>Sun, 31 Dec 2023 09:55:25 GMT</pubDate>
            <atom:updated>2024-01-16T13:55:47.979Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SnlquTHgAvejwvQhbmX1YA.png" /></figure><h3><strong>1- @for @if , @empty and @switch</strong></h3><p>Angular provides these new features to replace *ngFor, and *ngIf directives. let’s say you have courses and you want to display them on the screen. All you have to do is use <a href="http://twitter.com/for">@for</a> <a href="http://twitter.com/if">@if</a> like you use *ngFor and *ngIf directives but with a slightly different syntax. The logic is the same.</p><p>@for , @empty</p><pre>&lt;div&gt; <br>@for (course of courses; track course.id; let index = $index; <br>let count = $count; let first = $first; let last = $last) {<br> &lt;yourComponent <br>    [course] = “course”<br>    [index] = “index”<br>    [class.is-first]= &quot;first&quot;<br>    [class.is-last]= &quot;last&quot;<br>    (courseSelected) = “onCourseSelected($event)” /&gt;<br>}<br>@empty {<br>   &lt;h1&gt; No courses Found ! &lt;/h1&gt; <br>}<br>&lt;/div&gt;</pre><p>The above is your html file, general component that you want to render your courses using child component, I called it “yourComponent”. You can use other variables: first means first element of your array. Count means length of array, track means for loop is tracking the loop using id like an identifier. Index is index of the current element. For the styling purposes you can also use first ,last, even, odd properties like I bind with class.is-last. Usage is the same.</p><p>@empty here provides to render your code in case of the data is empty array or empty iterable.</p><p>Track property is mandatory. It is a tracking function. It optimized the way in which the DOM gets rendered. the value that you give to track property has to be unique to each element so that angular can understand the elements in the array while re-rendering. You can also write your own tracking options in the component then you can give the value to the track property. You can simple to this too: <strong><em>track $index </em></strong>if you don’t wanna give id but still wanna avoid the compilation error.</p><p>@if</p><pre>&lt;div&gt; <br>  {{course.title}}<br>&lt;/div&gt;<br>@if (course.id === 1) {<br>  &lt;h2&gt; Course with ID 1&lt;/h2&gt;<br>}<br>@else if (course.iconUrl) {<br>  &lt;img [src] = &quot;course.iconUrl&quot; alt = &quot;logo&quot; width = &quot;300&quot;&gt;<br>}<br>@else {<br>  No image available<br>}<br>&lt;div&gt; <br>  {{course.description}}<br>&lt;/div&gt;</pre><p>For @if, usage is like above. This is kind of simplified version ,as your case gets complicated this syntax is very usefull for reading code, it clarifies the code. Also it supports else if case , you can use else if limiteless the *ngIf directive is a bit limited else if cases.</p><p>@switch</p><p>Imagine that your courses has the categories and you wanna seperate them into 4 or 5 categories ans show user on the screen. Here comes @switch. Is a good solution in which cases and it increases the code readibility. The logic is the same with <strong>ngSwitch</strong> directive.</p><pre>// your html file where you write your code that <br>// shows details of each course.<br>&lt;div class= &quot;course-category&quot;&gt; <br>  @switch(course.category) {<br>    @case (&quot;BEGINNER&quot;) {<br>      &lt;div class= &quot;category&quot;&gt; Beginner &lt;/div&gt;<br>  }<br>    @case (&quot;INTERMEDIATE&quot;) {<br>      &lt;div class= &quot;category&quot;&gt; Intermediate&lt;/div&gt;<br>  }  <br>    @case (&quot;ADVANCED&quot;) {<br>      &lt;div class= &quot;category&quot;&gt; Advanced &lt;/div&gt;<br>  }<br>    @default {<br>    &lt;div class= &quot;category&quot;&gt; Unknown &lt;/div&gt;<br>  }  <br>}<br>&lt;/div&gt;</pre><h3><strong>2- @Defer Partial Template Loading Syntax</strong></h3><p>It is used for the performance problems so it is not always necesarry to use this feature in angular applications. Scenarios would be in which the component that you wanna use @defer is used rarely. When functionality not always visible to the user and we are not sure about that functionality will be used or not then the question is why would we load the code that we need for rare cases ? To be more clear, here are the common scenarios:</p><ul><li>only load a large component after the user scrolls down the page after a certain point</li><li>only load a large component after the user clicks on a button</li><li>preload a large component on the background while the user is reading the page, so that it is ready by the time the user clicks on a button</li></ul><p>Here comes the @defer Partial template loading syntax. Imagine that your component has some code that will always be displayed, but then there is a part of the page that is only needed in certain scenarios. That unnecassary part contains a large component, that we want to load on the background.</p><pre>@Component({<br>  selector: &quot;huge-component&quot;,<br>  template: ` &lt;h1&gt;huge-component is displayed...&lt;/h1&gt; `,<br>})<br>export class ExampleComponent {}</pre><p>Just imagine that this is a massive component, that internally uses huge libraries and other heavy dependencies. We want to delay the loading of this large component until we are 100% sure that the user needs it. To control this behavior, wrap the component with <strong>@defer</strong> block. <em>This will tell Angular that the </em><em>@defer section of the page should be packaged into a separate Javascript bundle, and loaded separately. (please look at the Angular CLI build output to see this behavior)</em></p><pre>@Component({<br>  selector: &quot;app&quot;,<br>  template: `<br>    &lt;h2&gt;Some content...&lt;/h2&gt;<br><br>    @defer {<br>    &lt;huge-component /&gt; // our huge component that we created above. <br>    }<br>  `,<br>})<br>export class AppComponent {}</pre><p>@defer will be creating an extra bundle, that contains the code for the huge-component element. This will help the angular applicaton to be loaded fastly because defer seperated the bundles and application only loads the huge-component if defer block gets triggered. <strong>So how we trigger the defer ? To answer this let’s talk about @placeholder , @loading and @error blocks.</strong></p><p><strong>@defer with </strong><strong>@placeholder</strong></p><pre>@defer {<br>  &lt;huge-component /&gt;<br>} <br>@placeholder {<br>  &lt;initial-content /&gt;<br>}</pre><p>Usage is very simle. Just write this code above and the application will show initial content until the huge component gets loaded. Then this initial-content code will be replaced by the code loaded via @defer block. So first initial-content will be rendered in the place of the defer, then if defer block gets loaded and rendered initial-content will be replaced with our huge-component. The initial-content should be just a visual indicator that something will be placed in that space soon, if you use directives, pipes, etc.in initial-component those thing will be part of the main bundle.</p><p>@placeholder has “minimum” parameter that is used to set min amount of time for which the placeholder block will be shown to the user. The application will render placeholder content until given minumum time finishes.</p><p><strong>@defer with </strong><strong>@loading</strong></p><p>The @loading block is used to show some content while the @defer block is <strong>still loading</strong> its Javascript bundle in the background. The @loading block accepts two optional parameters:minimum and after:</p><ul><li>minimum is used to give the minimum amount of time (seconds or miliseconds ) that the @loading block will be shown to the user.</li><li>after is used to specify the amount of time application should wait before showing the @loading indicator after the loading process is started.</li></ul><p>@placeholder wrapped content will be there before bundle gets started but @loading will be rendered when bundle gets started to loaded, this is the difference between two blocks.</p><p><strong>@defer with </strong><strong>@error</strong></p><p>If something goes wrong when bundle gets loaded then we can use @error content to show some error to the user with @error block. Usage is below as same the other blocks:</p><pre>@defer {<br>&lt;huge-component /&gt;<br>} @error {<br>&lt;error-message /&gt;<br>}</pre><p>Now we are wondering how @defer triggers work ?</p><p>There is two levels of control this situation: Prefetch trigger which controls when bundle gets loaded from Backend side, @defer trigger when @defer block gets displayed to user. So we have to options.</p><ul><li>we can use predefined triggers</li><li>we can write our custom triggers</li></ul><p>1- Predefined Triggers:</p><p><strong><em>idle, viewport, interaction, hover, immediate, timer.</em></strong> Those are the predefined triggers. We can apply those as prefetch triggers also as @defer triggers. To see the usage of these please look at <a href="https://angular.io/guide/defer">https://angular.io/guide/defer</a></p><h3>3- Signals</h3><p>Without signals in angular imagine you have input that you show to user in html and you are changing this input variable by mutating the object or array or even primitive. Like counter variable below.</p><pre>@Component({<br>  selector: &quot;app&quot;,<br>  template: `<br>      &lt;h1&gt; Counter value : {{ counter}} &lt;/h1&gt;<br>      &lt;button (click)=&quot;increment()&quot;&gt;Increment&lt;/button&gt;<br>  `,<br>})<br>export class AppComponent {<br>  counter: number = 0 ; <br>  <br>increment() {<br>  this.counter++;<br>}<br>}</pre><p>Here angular understands that variable changed by comparing whole code. If our component was big then it is really bad calculation for optimizization of our application. Here comes signals.</p><p>Signals have an API for reporting data changes to Angular, allowing the framework to optimize change detection and re-rendering in a way that so far was just not possible. (actually possible with change detection system but this systems comes problems if you have big and nested components, when component tree gets complicated change detection comes with problems). <strong><em>With Signals, Angular will be able to determine exactly what parts of the page need to be re-rendered and render only that part. We can say that signals are all about increasing the runtime performance by getting rid of Zone.js.</em></strong></p><p>The signal version of the example above would be like :</p><pre>@Component({<br>  selector: &quot;app&quot;,<br>  template: `<br>      &lt;h1&gt; Counter value : {{ counter}} &lt;/h1&gt;<br>      &lt;button (click)=&quot;increment()&quot;&gt;Increment&lt;/button&gt;<br>  `,<br>})<br>export class AppComponent {<br>  counter= signal(0); <br>  <br>increment() {<br>  this.counter.set(this.counter()+1);<br>}<br>}</pre><p>Signals represents the value of counter beginning with 0. We can get signal value just calling it as funtion like : this.counter(); Set() here for modifiying the variable. Also we can write this to update the value:</p><pre>increment() {<br>  this.counter.update(counter =&gt; counter + 1);<br>}</pre><p>this is the same. this.counter() is a function. counter =&gt; counter + 1 is an arraw function. <strong><em>The main advantage is that we can get notified when the signal value changes, and then do something in response to the new signal value.</em></strong></p><p>Also signals can be derived from other signals like observables in rxjs. Use <em>“computed” to achieve this.</em></p><pre>export class AppComponent {<br>  counter= signal(0); <br>  derivedCounter = computed(() =&gt; {<br>    return this.counter() * 2;<br>    })<br>  <br>increment() {<br>  this.counter.set(this.counter()+1);<br>}<br>}</pre><p>Now, whenever the counter source signal has a new value, the derived signal also gets updated automatically. Angular now knows that there is a dependency between the two signals.</p><p><strong>Signals with array and object values</strong></p><p>Arrays and objects work mostly the same way as primitive types, but there are the things that we should take into consideration.</p><pre>@Component(<br>    selector: &quot;app&quot;,<br>    template: `<br><br>  &lt;h3&gt;List value: {{list()}}&lt;/h3&gt;<br><br>  &lt;h3&gt;Object title: {{object().title}}&lt;/h3&gt;<br><br>`)<br>export class AppComponent {<br><br>    list = signal([<br>        &quot;a&quot;,<br>        &quot;b&quot;<br>    ]);<br><br>    object = signal({<br>       id: 1,<br>       title: &quot;Title&quot;<br>    });<br><br>    constructor() {<br><br>        this.list().push(&quot;c&quot;);<br><br>        this.object().title = &quot;overwriting title&quot;;<br>    }<br><br>}</pre><p>here we used push and changed title by hand. The key thing to notice is that unlike a primitive value, <strong>nothing prevents us from mutating the content</strong> of the array directly by calling push on it, or from mutating an object property. We should not do that. <strong>We have to always use set or update to update signals value. </strong><em>By doing so, we provided to signals a chance to all the derived signals for updating themselves and have those changes reflected on the screen.By directly accessing the signal value and mutating its value directly overrides whole signal strategie and that’s now wanted.</em></p><p>Here I talked about these new fatures topics very shortly. There is more to them. Please check official documentation and other resources to learn more. <a href="https://angular.io/guide/signals">https://angular.io/guide/signals</a>. Also many thanks to Angular University <a href="https://angular-university.io/">https://angular-university.io/</a> you can check here too.</p><p><em>I Appreciate the time and attention, as well as your prompt comment.</em></p><p><em>Reyhan Dağcı</em></p><p><em>Frontend Developer</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f1cc5b69e42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linked Lists With Java Part 1]]></title>
            <link>https://medium.com/@reyhandagci/linked-lists-with-java-part-1-2f8d3b50d7b2?source=rss-414b2954a2ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f8d3b50d7b2</guid>
            <category><![CDATA[datastrucutre]]></category>
            <category><![CDATA[asymptotic-notation]]></category>
            <category><![CDATA[linkedlist-in-java]]></category>
            <category><![CDATA[big-o-notation]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Reyhan Dağcı]]></dc:creator>
            <pubDate>Sat, 05 Aug 2023 13:34:58 GMT</pubDate>
            <atom:updated>2023-08-05T13:34:58.528Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*w6xl5MICwM7zAhRg8yR7oQ.png" /></figure><p>Hello everybody, in this article I will talk about linked lists and some methods of writing the code with Java. I am not a Java expert or a data structures expert, but at the same time, I know DSA (data structures and algorithms) is a bit crucial while learning it, especially in Java :) because of that, I would like to explain DSA from my learning perspective and my explanations. I hope I can help! First of all, this article will be a serial following by other data structures, Stacks, queues, and others with some detailed explanations so don’t worry I will come back after linked lists. Okay now, let’s go! <br>As per my experiences with learning DSA (in this case linked lists), first, you need to learn about Big O, Big Theta, and Big Omega. I will explain linked lists in Java but you need to a bit know about OOP such as classes etc.</p><p><strong>Asymptotic Notations</strong></p><p>When we try to solve a problem by writing code we have restricted resources like memory or time. We know that when we solve a problem we have to be fast, and at the same time we have to use our resources wisely. In the programming approach, these resources are time and memory. To use these resources wisely, people invented some algorithms and data structures to solve particular problems. For example, for sorting an array there are several algorithms like merge sort, bubble sort, quick sort, etc (concerning input number n) and these algorithms differ from each other according to the usage of these resources that I mentioned. All these DSAs and algorithms are calculated according to two things: Time complexity and space complexity and we calculate those things by using asymptotic notations like Big O, Big Theta (<a href="https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-big-theta-notation">Big-θ</a>), and Big omega (<a href="https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-big-omega-notation">Big-Ω</a>).</p><p>An important note here, time complexity is not a mesure of time under different conditions because assume that you have one algorithm and 2 computers, one of the computers is 2x faster than other. In this case same algorithm runs 2x faster in other computer that does not mean your algorithm got faster. Actually time complexity is defined as the amount of time taken by an algortihm to run as a function of the length of the input n under same conditions.</p><p>Without getting into the math part, I can breifly say that Big O represents worst case, Big Theta represents average case and Big Omega represents the best case scenario of an algorithm. For example you have and array [1,2,3,4,5] here if you find 1 by looping thr array you will find after one operation , this is the best case <a href="https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-big-omega-notation">Big-Ω</a> , if you wanna find 3 this is average case <a href="https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-big-theta-notation">Big-θ</a> , here the worst case is finding last value of an array by looping that array so it is Big O . You might encounter that the interviewers say it like “what is the best case of Big O” , but the point is normally there is no such a thing best case of Big O, it is Big Omega actually so be aware of it.</p><p>From the perspective of an algorithm, you can think of Big O is ≤ it is an upper bound of time an algorithm might take. Also, <a href="https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-big-omega-notation">Big-Ω</a> is lower bond ≥ and here <a href="https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-big-theta-notation">Big-θ</a> is ==. For example, assume that you have an algorithm that takes n input and has one for loop in code, in this case, this algorithm has to make at least n operations when running. So that means the upper bond of this algorithm is O(n), worst case. So we can say that the time complexity of this algorithm is O(n). Now assume that you have code that adds n input numbers. So here even if n is 1000000 code will make just one operation which is adding. We can say that here the input number is not changing the number of operations that will be made. So the time complexity of this code is Big (1). It is constant.</p><p>The last example, imagine a code that takes n input and has 2 nested for loops. This might be creating a matrix with rows and columns, in other words, 2 dimensional arrays. Here, for each 1st for loop value, n operations will be performed for the 2nd for loop. If we print the values (let’s say n = 5), this might be like :</p><pre>public class Main {<br><br>    public static void main(String[] args) {<br>        MyForLoop(5);<br><br>    }<br><br>    static void MyForLoop(int n) {<br>        for (int i = 0; i &lt; n; i++) {<br>            for (int j = 0; j &lt; n; j++) {<br>                System.out.println(i + &quot;, &quot; + j);<br>            }<br>        }<br>    }<br><br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/147/1*0dCaXfPtvcFXUWRxktIBAw.png" /><figcaption>output</figcaption></figure><p>For 0 (first i value) the program runs n time in this case 5 time. For 1 is same 2, 3, 4 ,5 thr program runs 5 time. So we can say 5 + 5+ 5+ 5+ 5 = 25 times this program runs in other words it is n^2 (n* n). So the time complexity of this code is O(n^2) (a bit bad :) ).</p><p>Now I want to customize things a little more and talk about Big O concept over arrays. Let’s say you have [1,2,3,4] array and you want add a new member at the end of the array. What is the time complexity for this action ?</p><p>Since we will add this new member at the end, the number of operations is just 1. We don’t have to worry about or do some operations on other elements of the array or on indexes, we just add new elements with index and raise lenght 1 more. Because of that the time complexity is O(1).</p><p>What about removing an elements at start of the array , for example at index = 0 ? If our array become from this [1,2,3,4] to this [2,3,4] we have to change all indexes while removing the element. While index = 0 value = 1 , now index = 0 value = 2. We have to do n number of operations in this case 4. So because of we are touching every element of that array while removing an element from the beginning, the time complexity of this oepration is O(n). If we compare this time complexities we can say that best is O(1), worst is O(n^2) because when n grows fast, O(n^2) become more than O(n) and this become more than O(1). O(1) is not dependent on n input size. I wanna show this by showing a graph :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHl9KoPe-DZdcvNbIlMsPg.png" /><figcaption><a href="https://www.freecodecamp.org/news/big-o-cheat-sheet-time-complexity-chart/">https://www.freecodecamp.org/news/big-o-cheat-sheet-time-complexity-chart/</a></figcaption></figure><p>Classes in Java and Pointers</p><p>Classes are the blueprint of object as you may know from javascript. What is a blueprint ? For example, you want to make a cookie and you go to the market and buy its mold. You also have different types of food coloring . The colors of the cookies will be different, but since you only have one mold, you will only have the same cookie. Here the mold is your cookie class that you make cookies by using it , constructor is where you give the color and it creates the new instance of that class.</p><pre>public class Cookie {<br>    private String color;<br><br>    public Cookie(String color) {<br>        this.color = color;<br>    }<br>}<br><br>// here Cookie is my constructor where I take the color argument and set it<br>// to a particular Cookie instance. Constructor has to be same with class name, <br>// and has to be uppercase.</pre><pre>public class Main {<br><br>    public static void main(String[] args) {<br>        // type is Cookie.     from Cookie class with color green.   <br>        Cookie greenCookie = new Cookie(&quot;green&quot;); // new keyword runs the constructor. <br>        Cookie blueCookie = new Cookie(&quot;Blue&quot;);<br><br>        System.out.println(greenCookie);<br>        System.out.println(blueCookie);<br>    }<br><br>}<br><br>// here is my public class where I create my Cookie instances.</pre><p>We explained classses now what is a pointer ?</p><p>In simpler terms, a pointer points to the location in memory where a value is stored rather than directly containing the value itself. Pointers are commonly used in programming languages that support direct memory manipulation, such as C, C++, and some assembly languages. In C they are represented by using *. A pointer points some address in the memory. To be more clear :</p><pre>#include &lt;stdio.h&gt;<br><br>int main() {<br>    int a = 3;<br>    int *p = &amp;a;  // &amp; this gives address in C in the memory.<br><br>    *p = a; // Assign the value of a to the memory location pointed to by p<br><br>    printf(&quot;Value pointed to by p: %d\n&quot;, *p);<br>    printf(&quot;Value of p: %p\n&quot;, p);<br><br>    return 0;<br>}<br><br>//output : <br>//Value pointed to by p: 3<br>//Value of p: &lt;memory-address&gt;<br></pre><p>In this example:</p><ol><li>int a = 3;: Declare an integer variable a and assign the value 3 to it.</li><li>int *p = &amp;a;: Declare an integer pointer p and initialize it with the memory address of a.</li><li>*p = a;: Assign the value of a (which is 3) to the memory location pointed to by p. This changes the value stored at the memory address pointed to by p.</li><li>printf(&quot;Value pointed to by p: %d\n&quot;, *p);: Prints the value pointed to by p, which is 3.</li><li>printf(&quot;Value of p: %p\n&quot;, p);: Prints the value of the pointer p, which is the memory address of a.</li></ol><p>So, *p = a modifies the value of the memory location pointed to by p to be 3, and then when you print *p, it shows 3, and when you print p, it shows the memory address where the value 3 is stored. The exact memory address value will depend on your system and compiler.</p><p>Note that the * sign can be confusing here, as it does two different things in our code:</p><ul><li>When used in declaration (int* ptr), it creates a <strong>pointer variable because of that first we assign an address to it in second row in the int main function.</strong></li><li>When not used in declaration, it act as a <strong>dereference operator</strong>.</li></ul><p>Why I explained pointers ? Because when we create linked list there will be nodes that containes value and next pointer in it. Next pointer there will point another node in the linked list. Because of that what pointers do subjet must be clear.</p><h3>Linked Lists</h3><p>A linked list is like image below. A linked list some serial of values which points each other until the tail point null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9li1d9LQ_fxqt4oLxSItow.png" /></figure><p>What is a node ? Node is a type that contains value and next pointer in it. You can think of it as it is a map. Node is like { “value” : 23, “next” : {some other node} } . 23 4 7 and 12 is the values of that nodes, and the arrows you can think as it is next pointer of that node. For example below, 23 is a value of that node (circle) and the arrow point 23 is a next pointer of head and the other arrow is next pointer that points next node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*fksAtW4LrLr_gVMkaoWbDw.png" /></figure><p>Here the tail and head aren’t nodes. They are just a pointer that just points at first value and last value of a linked list. They don’t contain a value they just point to a node. To be more clear, I can represent the linked list above like it is hashmap :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DPJjV_6DuF030e5j7zI3Zw.png" /></figure><p>Here every next points other node until tail.next = null , in other words until tail points at null.</p><p>Now, if it is clear what the linked list is , we can move on to compare linked lists and arrays.</p><p>Linked lists and arrays are both fundamental data structures used in programming to store and manage collections of elements. However, they have different characteristics and use cases. Elements in an array are stored in contiguous memory locations, meaning they are placed one after another in memory because of that we can easly reach an element using index like A[1] for example where A is my array. However elements in a linked list can be scattered in different memory locations because they have access to each other via pointers, they don’t have to be next each other in the memory.</p><p>Arrays have a fixed size that needs to be defined when the array is declared. Expanding or shrinking an array typically requires creating a new array and copying elements. Linked Lists can dynamically grow or shrink by adding or removing nodes. They can adapt to changing data sizes more efficiently than arrays. We will look at it soon using time compelxity.</p><p>Directly accessing elements in an array is fast and constant time (O(1)) because elements are stored in contiguous memory locations. But access time in linked lists is slower, especially for large lists, since you need to traverse the list sequentially to reach a specific element (O(n) time complexity for access).</p><p>Lastly arrays are managed automatically by most programming languages, with automatic memory allocation and deallocation. For Linked Lists memory management is more manual, and you need to explicitly allocate and deallocate memory for each node. (ie: in C, malloc and calloc).</p><h3>Linked Lists and Big O</h3><p>I wanna try to explain time complexity according to linked list operations. There are several operations which we can do in a linked list. Those are <strong>prepend (add element to start), append (add element to the end), remove last (remove last element), remove first (remove first element) , get, set, insert (insert element to somewhere), remove (remove an element from somewhere), reverse.</strong></p><p><strong>1- Append</strong></p><p>This operation is really straightforward in linked lists, because we will do just operation. We have tail that points null and tail is the last node actually. When we add new node, new tail become this new node , and this new node has to point null value since it is now the last node. I’ll try to explain it with this diagrams below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CNgMIRQPhWSii2lK5O4zwQ.png" /><figcaption>this is my initial linked list and I wanna add 8</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0sJrUDciu34dSRQWxL75Q.png" /><figcaption>Tail become node(8) , node(12).next will be node(8) , and new node(8).next will be null since this is the last node.</figcaption></figure><p>Since we only do just one operation, we can say that time complexity is O(1).</p><p><strong>2- Prepend</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q2TTF22pUkWyx-O8BnHXAw.png" /></figure><p>For adding an element to the beginning, new node(8) has to first be equal to head for new node to point 23 like head do. Second, head has to points to new node. (from yellow to green) thus, we add an element to the beginning. Since we only do just one operation, we can say that time complexity is O(1).</p><p><strong>3- Remove First</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zBDAL4ptm-rJmijvB0XR6g.png" /></figure><p>In first step we have our initial previously added new linked list. Step 2, we have to equalize our head to head.next to remove node(8) from the list. Then in step 3 we have to set node(8).next to null. Node(8) will still keep memory but after some time some thing called garbage collector will remove unused items from memory , so don’t worry about it. Since we only do just one operation, we can say that time complexity is O(1).</p><p><strong>4- Remove Last</strong></p><p>This is a bit complicated than others that I mentioned earlier. Time complexity of this action is O(n). I will explain why.</p><p>So far we are examining single linked list meaning that we have only one direction in our linked list from head to tail. Because of this we can’t go the reverse of the arrows because we don’t have pointers pointing backwards at our nodes. But when it comes to removing last item from list, we need some backward action because we need previous node before last node which is 7 in the diagram. In this situation, rather than going backwards , we need to start at the head and iterate through the list until we get to previous node before last node which is 7. Because at the end of the day for removing last item, first we need to equalize the tail to node(7) then we need to do node(7).next = null meaning that node(7) points to null to be last node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jdpJU7xMkWGIEVeveeBa0w.png" /><figcaption>our initial linked list.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vjRbnsnNVxFCt5aWoQFxWg.png" /></figure><p>Here in step 1, the purpose is removing node(12). In step to, we loop through the list to equalize the tail to the pointer which point at node(7). Pay attention to the pink arrows. When we come to the next arrow which points node(7), we equalize tail to this node , then we equalize node(7).next to null , and voila we removed node(12) by iterating the whole list. Because of that iteration we say the time comlexity here is O(n) because it is dependent on input size.</p><p>So far we covered asymptotic notations, pointer, classes in java, comparaison of array and linked list and the time complexity of some linked list operations. In part 2 of this article, I will represent those operations deeply by showing their code in java. See you in part 2 :)</p><p><em>I Appreciate the time and attention, as well as your prompt comment.</em></p><p><em>Reyhan Dağcı</em></p><p><em>Frontend Developer</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f8d3b50d7b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The hints you should know when using Angular]]></title>
            <link>https://medium.com/@reyhandagci/the-hints-you-should-know-when-using-angular-11135227ac39?source=rss-414b2954a2ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/11135227ac39</guid>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Reyhan Dağcı]]></dc:creator>
            <pubDate>Thu, 29 Dec 2022 11:51:27 GMT</pubDate>
            <atom:updated>2022-12-29T11:52:16.807Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NIxavPln2IAyTTfXROxq9A.png" /></figure><p><strong>1- Don’t map or transform your data in your subscribe method</strong></p><p>It’s not recommended because, if you have many subscribers who need the same conversion, you will have to repeat a lot of code, so you have to make this change every time you subscribe. Although you can handle this with a function that you write in a separate helper file, but still ,there will be places where you cannot solve the problem with a helper. Instead of manipulating data with javascript methods in Subscribe, use Rxjs library operators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*oVkJMNyzzeAoKXSTo5i2Lg.png" /></figure><p><strong>Code Example:</strong></p><pre>this.http.get(&quot;https://fakestoreapi.com/products/1&quot;)<br>    .subscribe(response =&gt; {{<br>        name: response.name,<br>        title: response.title,<br>        price: Number(response.price),<br>        category: Number(response.category),<br>    }</pre><p>Use Rxjs map operator instead of editing while subscribing.</p><pre>this.http.get(&quot;https://fakestoreapi.com/products/1&quot;)<br>    .pipe(map(response =&gt; ({<br>        name: response.name,<br>        title: response.title,<br>        price: Number(response.price),<br>        category: Number(response.category),<br>    })))<br>    .subscribe(item =&gt; console.log(item));</pre><p><strong>2- Don’t forget to unsubscribe when the component is destroyed</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*d8WOJYWx1Ix_It3f-1dblQ.gif" /></figure><p>If we subscribe to an observable and we don’t unsubscribe when the component gets destroyed, the subscription process continues and it causes a memory leak because every time we return to the component that we forget to unsubscribe, another subscription process starts. There are several methods you can use for unsubscribing from observables.</p><p><strong>Code Example:</strong></p><pre>import { interval, Subscription } from &#39;rxjs&#39;;<br><br>@Component({...})<br>export class AppComponent implements OnInit, OnDestroy {<br>    subscription: Subscription;<br>    ngOnInit () {<br>        const observable = interval(1000);<br>        this.subscription = observable.subscribe(x =&gt; console.log(x));<br>    }<br>    ngOnDestroy() {<br>        this.subscription.unsubscribe();<br>    }<br>}</pre><p>We added ngOnDestroy to our AppCompoennt and called the unsubscribe method on “this.subscription” observable. When the AppComponent gets destroyed (via route navigation, destroy(…), etc) there will be no hanging subscription, the interval will be canceled and there will be no console logs in the browser anymore. If there are multiple subscriptions you can write code like the below:</p><pre>@Component({...})<br>export class AppComponent implements OnInit, OnDestroy {<br>    subscription1$: Subscription<br>    subscription2$: Subscription <br>    ngOnInit () {<br>        const observable1$ = interval(1000);<br>        const observable2$ = interval(400);<br>        this.subscription1$ = observable1$.subscribe(x =&gt; console.log(&quot;From interval 1000&quot; x));<br>        this.subscription2$ = observable2$.subscribe(x =&gt; console.log(&quot;From interval 400&quot; x));<br>    }<br>    ngOnDestroy() {<br>        this.subscription1$.unsubscribe()<br>        this.subscription2$.unsubscribe()<br>    }<br>}</pre><p>or :</p><pre>@Component({...})<br>export class AppComponent implements OnInit, OnDestroy {<br>    subscription1$: Subscription <br>    subscription2$: Subscription <br>    subscriptions: Subscription[] = []<br>    ngOnInit () {<br>        const observable1$ = interval(1000);<br>        const observable2$ = interval(400);<br>        this.subscription1$ = observable1$.subscribe(x =&gt; console.log(&quot;From interval 1000&quot;, x));<br>        this.subscription2$ = observable2$.subscribe(x =&gt; console.log(&quot;From interval 400&quot;, x));<br>        this.subscriptions.push(this.subscription1$)<br>        this.subscriptions.push(this.subscription2$)<br>    }<br>    ngOnDestroy() {<br>        this.subscriptions.forEach((subscription) =&gt; subscription.unsubscribe())<br>    }<br>}</pre><p>In the above code, we constructed a subscription array and, we gathered all subscriptions in this array. After that, when angular destroys the component, it will automatically unsubscribe in the ngOnDestroy method for each subscription.</p><p>or <strong>Use Async </strong><strong>| Pipe</strong></p><pre>@Component({<br>    ...,<br>    template: `<br>        &lt;div&gt;<br>         Interval: {{observable$ | async}}<br>        &lt;/div&gt;<br>    `<br>})<br>export class AppComponent implements OnInit {<br>    observable$: Observable&lt;any&gt;<br>    ngOnInit () {<br>        this.observable$ = interval(1000);<br>    }<br>}<br></pre><p>On instantiation, the AppComponent will create an Observable from the interval method. In the template, the Observable observable$ is piped to the async Pipe. The async pipe will subscribe to the observable$ and display its value in the DOM. async pipe will unsubscribe the observable$ when the AppComponent is destroyed. async Pipe has ngOnDestroy on its class so it is called when the view is contained in is being destroyed.</p><p>Using the async pipe is a huge advantage if we are using Observables in our components because it will subscribe to them and unsubscribe from them. We will not be bothered about forgetting to unsubscribe from them in ngOnDestroy when the component is being killed off.</p><p><strong>3- Don’t write tons of logic in the template</strong></p><p>This is the case when you calling the functions inside the template, especially in the string interpolation. Calling the function in the string interpolation will impact your performance and it is hard for future refactoring later.</p><p><strong>Code Example:</strong></p><pre>@Component({<br>  template: `<br>    &lt;p&gt;Welcome {{ fullName() }}!&lt;/p&gt;<br>`<br>})<br>export class PersonComponent {  <br>@Input() person: { firstName: string, lastName: string };  constructor() { }  <br>fullName() {<br>    return this.person.firstName + &#39; &#39; + this.person.lastName<br>  }  <br><br>}</pre><p>The solution for that would be to do manual calculations or combinations for your data or use<strong> pipes</strong> for that, that will increase the code <strong>readability</strong> and <strong>re-usability.</strong></p><p><strong>4- Don’t use Promises instead of Observables when making HTTP Requests</strong></p><p>When we create Angular applications we generally use observable when we make HTTP requests. This gives us the benefits of reactive programming which is for example interrupting the data stream with operators and making changes while data is streaming. If we use a promise to receive a response, we can not easily interact with data while we are getting a response. In addition to that, we can not easily cancel a promise. So it is better to use Observable when we make HTTP requests.</p><p><strong>Code Example:</strong></p><pre>getProduct(id: number) {<br>    return this.http.get&lt;IProduct&gt;(<br>      `${this.urlFakeStoreApiDomain}/products/${id}`<br>    );<br>  }<br><br><br>this.producstsService.getProduct(this.id).subscribe((product: IProduct) =&gt; {<br>      this.isLoading = false;<br>      this.product = product;<br>    });</pre><p>In addition to that, the getProduct method is in our product service file and the subscription code below is in the component. This is the best practice of angular. When we create the service to make an HTTP request, we usually subscribe to the method in the component that we want to receive data. Keeping services clean and lean is the best way to create service.</p><p><strong>5- Add $ suffix for variables type observable</strong></p><p>Suffix $ is used to indicate a certain variable is observable. It helps to distinguish between normal variables and observable hence putting suffix increases the code readability.</p><pre>  subscription1$: Subscription;<br>  subscription2$: Subscription;<br>  subscription3$: Subscription;</pre><p><strong>6- Don’t write a very long lines of code in the component</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*3-9ldp2VvlCYRQuwr18fdg.png" /></figure><p>Always focus on keeping your codes shorter and more readable. If your code is too long, split your component, split it into smaller parts. If the lines of methods are too long, use a helper file and keep certain methods in the helper. For the helper, we may create an index.ts file and the helper file. The index.ts file is for the export of functions that we write in the helper file. In the helper file, we write the functions, later we import those functions to the component and we use them whereever we need those functions.</p><pre>// This is the file that we keep functions.<br><br>export function countItems(arr) {<br>  let quantityArr = [];<br>  arr.forEach((cart) =&gt; {<br>    quantityArr.push(cart.quantity);<br>  });<br>  let totalQuantity = quantityArr.reduce((acc, curr) =&gt; acc + curr, 0);<br>  return totalQuantity;<br>}<br><br></pre><pre>// Our index.ts file<br><br>import {countItems} from &quot;./text-modifiers&quot;;<br><br>export {<br>    countItems,<br>}</pre><pre>// the we use in the component.Don&#39;t forget to import<br><br>import {countItems} from &#39;src/app/core/helpers&#39;;<br><br>getProducts() {<br>    this.shoppingService<br>      .getProductsInCart()<br>      .pipe(<br>        map((res) =&gt; {<br>          const arr: Cart[] = [];<br>          let tempProduct: Cart;<br>          for (let key in res) {<br>            if (res.hasOwnProperty(key)) {<br>              tempProduct = res[key];<br>              tempProduct.key = key;<br>              arr.push(tempProduct);<br>            }<br>          }<br>          return arr;<br>        })<br>      )<br>      .subscribe((arr: Cart[]) =&gt; {<br>        this.carts = findOcc(arr, ourKey);<br>        this.totalQuantity = countItems(this.carts);<br>      });<br>  }<br></pre><p><em>I Appreciate the time and attention, as well as your prompt comment.</em></p><p><em>Reyhan Dağcı</em></p><p><em>Frontend Developer</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11135227ac39" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>