<?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 Nguyen Trong Thang on Medium]]></title>
        <description><![CDATA[Stories by Nguyen Trong Thang on Medium]]></description>
        <link>https://medium.com/@thangnt_65695?source=rss-66ff1b838fb4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0cfa2_dZIpiFTp1K</url>
            <title>Stories by Nguyen Trong Thang on Medium</title>
            <link>https://medium.com/@thangnt_65695?source=rss-66ff1b838fb4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 03:40:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thangnt_65695/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[[Shared] Layout with CSS Grid Area]]></title>
            <link>https://medium.com/anymind-group/shared-layout-with-css-grid-area-dc57732607df?source=rss-66ff1b838fb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc57732607df</guid>
            <dc:creator><![CDATA[Nguyen Trong Thang]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 02:08:32 GMT</pubDate>
            <atom:updated>2023-02-21T02:10:16.438Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Overview</strong><br>In today’s article, I will learn with you about an advanced concept when writing CSS that is building layouts with Grid Area.</p><p>In order to convey the concept of one clearly and easily, I will go through 2 examples with you to practice the concept of CSS Grid Area.</p><p><strong>#Example 1 — Named Grid Areas</strong></p><p>In the first example, we will come to the concept of Named grid area through practice building layout as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*XWF9tA2Vcr0ahHXtFnZp4Q.png" /></figure><p>As the image shows, blocks from 1 to 5 are arranged in such a way that it is difficult to use normal CSS to implement this layout.</p><p>First step, we will prepare the necessary html tags and some CSS to make example look nicer</p><pre>&lt;div class=&quot;container-grid&quot;&gt;<br>  &lt;div class=&quot;block&quot;&gt;1&lt;/div&gt;<br>  &lt;div class=&quot;block&quot;&gt;2&lt;/div&gt;<br>  &lt;div class=&quot;block&quot;&gt;3&lt;/div&gt;<br>  &lt;div class=&quot;block&quot;&gt;4&lt;/div&gt;<br>  &lt;div class=&quot;block&quot;&gt;5&lt;/div&gt;<br>&lt;/div&gt;</pre><pre>.block {<br>  background: #fff;<br>  box-shadow: rgba(0, 0, 0, 0.16) 0px 10px 36px 0px,<br>    rgba(0, 0, 0, 0.06) 0px 0px 0px 1px;<br>  margin: 1rem;<br>  font-size: 50px;<br>  display: flex;<br>  align-items: center;<br>  justify-content: center;<br>  border-radius: 20px;<br>  color: rgb(109, 17, 17);<br>  min-height: 200px;<br>}</pre><p>Done with the preparation, looking at the existing source code, we can clearly see, now, any further CSS written will be tagged to the container-grid class that covers the blocks from 1 to 5.</p><p>As the concept itself says, in a nutshell, we will name the “grid items” via the css grid-area property and put these names into a “line-based” template via the grid-area property. calculate the grid-template-areas of the parent so that the named blocks are placed in the exact place the template has defined.</p><p>Going into the example, the first step is to name the “grid items” from 1 to 5 respectively.</p><pre>.container-grid .block:nth-child(1) {<br>  grid-area: block-1;<br>}<br><br>.container-grid .block:nth-child(2) {<br>  grid-area: block-2;<br>}<br><br>.container-grid .block:nth-child(3) {<br>  grid-area: block-3;<br>}<br><br>.container-grid .block:nth-child(4) {<br>  grid-area: block-4;<br>}<br><br>.container-grid .block:nth-child(5) {<br>  grid-area: block-5;<br>}</pre><p>To be able to build the correct template with the example, we will do the requirements survey to build a correct template. Building on the request, we can see that this layout is built as a “checkerboard” and our blocks will take the place of a number of corresponding “checkers”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*C3_Swm74o_-aSsCm2Y_juA.png" /></figure><p>After surveying and understanding the requirements of the layout, we build a template for the layout targeting the outermost container-grid class as follows.</p><pre>.container-grid {<br>  display: grid;<br>  grid-template-areas:<br>    &#39;block-1 block-1 block-5&#39;<br>    &#39;block-2 block-4 block-5&#39;<br>    &#39;block-2 block-4 block-5&#39;<br>    &#39;block-3 block-4 block-5&#39;;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*2k-UNGR03Fb_E2WM5QpjeA.png" /></figure><p>With that, we’ve done a custom layout using the Named Grid Area. However, this implementation still has limitations, we can only build layouts in the form of rectangles filled in a “checkerboard”, not able to build custom layouts of T or T shape. L.</p><p>To be able to build other custom layouts, we will come to the second approach in the article on CSS Grid Area.</p><p><strong>#Example 2 — grid-area cell grid placement</strong></p><p>In this part, we will do another custom layout together, depicted by the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*vF4PUquqWnImYOUKCwSiqw.png" /></figure><p>Through the example image, this is not the same as the layout in the first example, and we cannot use naming to build this layout.</p><p>Before we begin, we will also perform the same preparatory steps as the first example.</p><pre>&lt;div class=&quot;container-grid&quot;&gt;<br>  &lt;div class=&quot;block&quot;&gt;1&lt;/div&gt;<br>  &lt;div class=&quot;block&quot;&gt;2&lt;/div&gt;<br>  &lt;div class=&quot;block&quot;&gt;3&lt;/div&gt;<br>  &lt;div class=&quot;block&quot;&gt;4&lt;/div&gt;<br>  &lt;div class=&quot;block&quot;&gt;5&lt;/div&gt;<br>&lt;/div&gt;</pre><p>In this example, we will still rely on the idea of ​​dividing the “chess board” in the previous example, but in this approach, we will specify the position and size of each “chess tile” to place on the board. “chessboard”. As you can see, our layout has 3 columns and we will implement the css for the outer container-grid.</p><pre>.container-grid {<br>  display: grid;<br>  grid-template-columns: repeat(3, 1fr);<br>}</pre><p>To specify the size and position of each block, we will come to another way of writing grid-area. In addition to naming each block as in the example above, grid-area is also a short-hand way of writing 4 other properties in the following order.</p><pre>grid-area: auto/auto/auto/auto;<br>#    grid-row-start: auto;<br>#    grid-column-start: auto;<br>#    grid-row-end: auto;<br>#    grid-column-end: auto;</pre><p>Thus, we can easily see, we will specify the “coordinates” of each block, the blocks will start and end at which lines and columns are completely specified by us, the blocks will be displayed. exactly at the specified locations.</p><p>We will still perform the required survey and draw a corresponding “checkerboard”, thereby getting the correct “coordinates” for the component blocks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZBa6_tK0uF2wmaBXCxXxw.png" /></figure><p>Thus, through the “checkerboard” we can specify the corresponding “coordinates” for each block to complete the layout as required.</p><pre>.container-grid .block:nth-child(1) {<br>  grid-area: 4/1/8 / auto;<br>}<br><br>.container-grid .block:nth-child(2) {<br>  grid-area: 2/2/6 / auto;<br>}<br><br>.container-grid .block:nth-child(3) {<br>  grid-area: 6/2/10 / auto;<br>}<br><br>.container-grid .block:nth-child(4) {<br>  grid-area: 1/3/5 / auto;<br>}<br><br>.container-grid .block:nth-child(5) {<br>  grid-area: 5/3/9 / auto;<br>}</pre><p><strong>Conclusion</strong><br>Through the above 2 examples, I went through 2 examples of custom layouts with CSS Grid Area. The interpretation may not be easy to understand for everyone, however, to be able to use it fluently and form a “reflex” with these layouts, there is no other way than you should code a lot to get used to it.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc57732607df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/anymind-group/shared-layout-with-css-grid-area-dc57732607df">[Shared] Layout with CSS Grid Area</a> was originally published in <a href="https://medium.com/anymind-group">AnyMind Group</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shared] Some tips to make your code cleaner — part 2]]></title>
            <link>https://medium.com/anymind-group/shared-some-tips-to-make-your-code-cleaner-part-2-d3edbe6f773b?source=rss-66ff1b838fb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3edbe6f773b</guid>
            <dc:creator><![CDATA[Nguyen Trong Thang]]></dc:creator>
            <pubDate>Mon, 31 Oct 2022 03:05:04 GMT</pubDate>
            <atom:updated>2022-10-31T03:05:04.584Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Shared] Some tips to make your code cleaner — part 2</h3><p>In the previous parts of the series, we learned about the basics of coding, which are related to: declaring and using variables, commenting on code, as well as formatting the code so that it’s easy to follow. . In the next section, we will go a little deeper to analyze the control structures and logic representations. In any programming language, despite the differences in syntax, they all have one thing in common: control structures. In particular, no matter what language, the control structure always includes two important things: branching and loop handling.</p><p>With the criteria set out throughout this series, the code needs to be easy to read and understand, our task is to make sure the forking and iterative operations make that processing as “natural” as possible. . That is, the reader doesn’t need to read the code over and over again to understand the content of the code — ideally, they only need to read it once.</p><blockquote>Idea: Make sure branching and looping is done as “naturally” as possible.</blockquote><p>To do this, let’s consider the following.</p><p><strong>The order of the parameters in the conditional sentence:</strong></p><p>Try reading the following 2 ways of writing code, do you have any difference?</p><pre>// Option 1<br>if ( page &gt;= 5 ) {<br>   // do something else<br>   // ...<br>}<br> <br>// Option 2<br>if (5 &lt;= page) {<br>   // do something else<br>   // ...<br>}</pre><p>Maybe the difference isn’t much, but I’m sure most of us will find the first way to be easier to read and understand than the second. The reason is simple, way 1 looks more pleasing to the eye and seems more natural. .</p><p>This is like if you were asked about the distance from home to work, assuming the distance is approximately more than 4km but less than 5km. At that time, would you say “The distance from home to office is less than 5km” or “5km is greater than the distance from home to office”? Surely, you will say way 1, right!</p><p><strong>So pay attention:</strong> When creating a compare statement, set a mutable variable on the left, the right will be for a constant or datum.</p><p>There is an interesting note that I also want to mention, which is the equal comparison. Try to consider the following code:</p><pre>// Option 1<br><strong>if</strong> ( page == 0 ) {<br>   // do something else<br>   // ...<br>}</pre><pre>// Option 2<br><strong>if</strong> (0 == page) {<br>   //do something else<br>}</pre><p>If we consider the above criteria, we will choose way 1 to write. But, method 2 has a pretty good point, it’s that method 2 will minimize the possibility of you writing the wrong comparison when you write the = sign. That is, if you write 0 = length, the program will report an error, and if you write length = 0, the program will misunderstand that you are assigning a value, this logic error sometimes has very serious consequences. The error of missing the = sign when comparing is also common, and it is relatively difficult to detect. So be careful.</p><p><strong>Order of if / else . handlers:</strong></p><p>With many if/else handling cases, the advice that experienced people give is, we should prioritize handling the following situations:</p><ul><li>Prioritize simple cases to avoid forgetting.</li><li>Prioritize strange/rare cases to avoid being missed.</li><li>Positive comparisons are easier to read than negative comparisons.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uPwjCwzJPHoPY1F7" /><figcaption>Photo by <a href="https://unsplash.com/es/@nci?utm_source=medium&amp;utm_medium=referral">National Cancer Institute</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine that you are a man, and are looking to hire a lover, the prerequisite is that the candidate is female, not accepting men. In addition, you need to be beautiful, gentle, cute, worried and caring for your lover, not older than 30 but older than 18, etc.. At that time, how did you handle it?</p><pre>// Option 1<br>if (person.gender == &quot;Male&quot;) {<br>   return false;<br>}<br>else if (person.age &gt; 30 || person.age &lt; 18) {<br>   return false;<br>}<br>else if (person is cute, lovely, careful, ...) {<br>   return &quot;Hello!&quot;;<br>}<br> <br>// Option 2<br>if (person.gender != &quot;Male&quot;<br>    &amp;&amp; person.age &gt; 18<br>    &amp;&amp; person.age &lt; 30<br>    &amp;&amp; person is cute, lovely, careful, ...) <br>{<br>    return &quot;Hello!&quot;;<br>}<br>else {<br>    return false;<br>}</pre><p>Would you choose option 1 or option 2?</p><p>With option 2, we have a very complicated if-clause, which is of course confusing. Both negative comparisons make us think backwards, and many conditions, which make it difficult to track and cover the problem, code like this easily leads to potential errors.</p><p>With option 1, we separate the big condition into sub-conditions, handling each simple case first, so our logic is much clearer and separate. In addition, the clear logic also helps us avoid unnecessary errors.</p><p>Similarly, for strange or rare cases, we should also prioritize handling first to avoid being missed:</p><pre>function readFromFile( file ) {<br>   if (file == null) {<br>      return false;<br>   }<br> <br>   // do something here<br>   // ...<br>}</pre><p><strong>Avoid using multiple nested handlers:</strong></p><p>When writing code, we should also avoid writing nested branching handlers too much. Take the example of choosing a girlfriend above as an illustration: assuming your initial request is only “for female subjects”, the code looks like this:</p><pre>if (person.gender != &quot;Male&quot;) {<br>   return &quot;Hello!&quot;;<br>}<br>else {<br>   return false;<br>}</pre><p>After a while, you have one more criterion: ages 18 to 30. You edit the code as follows:</p><pre>if (person.gender != &quot;Male&quot;) {<br>   if (person.age &gt; 18 &amp;&amp; person.age &lt; 30) {<br>      return &quot;Hello!&quot;;<br>   }<br>    <br>   return false;<br>}<br>else {<br>   return false;<br>}</pre><p>After that, you continue to generate more criteria: height must be greater than 160cm. Then you edit the code as follows:</p><pre>if (person.gender != &quot;Male&quot;) {<br>   if (person.age &gt; 18 &amp;&amp; person.age &lt; 30) {<br>      if (person.height &gt; 160) {<br>         return &quot;Hello!&quot;;<br>      }<br>       <br>      return false<br>   }<br> <br>   return false;<br>}<br>else {<br>   return false;<br>}</pre><p>With the above writing, the code actually works, but now it’s become something that looks very complicated and difficult to follow. The reason is because there are too many nested branching handles, making the code very hard to read.</p><p>To handle these situations, we will use the following little trick to make the code more optimal: handle the simple case first, return as soon as possible. Then our code looks like this:</p><pre>if (person.gender == &quot;Male&quot;) {<br>   return false;<br>}<br>if (person.age &lt; 18 || person.age &gt; 30) {<br>   return false;<br>}<br>if (person.height &lt; 160) {<br>   return false;<br>}<br> <br>return &quot;Hello!&quot;;</pre><p>Even though it’s a bit longer, our new code looks much better and easier to understand, doesn’t it? And the most important thing is that the code is “flatter” than before. This technique is especially useful when dealing with forking in loops, the code will look much cleaner and simpler.</p><p><strong>Restricted use due to…while:</strong></p><p>You’re probably no stranger to the do…while loop, right? Logically, all types of loops in programming languages have the same meaning, which is to repeat a certain piece of code as long as the test condition is satisfied.</p><p>Naturally, before doing anything, the first thing we would do is check the validity of the handle. That’s also the reason that any branching (if/else, switch/case, …) or loop (for, while, …) must be processed to check the condition first. The do…while loop is a bit different: it will process the code before checking the condition. Somewhat weird! Try reading the following code quickly:</p><pre>do {<br>   var_dump(&quot;Loop&quot;);<br>   continue;<br>}<br>while (false);</pre><p>What is the output of this code? How many times will the loop run? Then try answering the same question for the following code:</p><pre>while (false) {<br>   var_dump(&quot;Loop&quot;);<br>   continue;<br>}</pre><p>This piece of code is much easier to answer, isn’t it? Perhaps, you also need to admit one thing: the do…while loop has more confusing logic and it seems much “less natural” than the other loops. The good thing is: logic that can be handled by do…while will also be handled by other loops. So, don’t choose a way of writing that is difficult to understand.</p><p><strong>Conclusion:</strong></p><p>The above are the ways I have tried to apply while writing code, the result is that the code looks more convenient, natural and clear. In summary, the things they need to keep in mind when using control structures in programming are:</p><ul><li>When comparing, the parameter will usually stand on the left, the constant or the landmark will stand on the right.</li><li>Dealing with simple or rare cases in the previous fork, also limits the use of negative comparisons in logical operations.</li><li>Avoid writing nested code by returning early if possible.</li><li>Avoid do…while loops, use other loops.</li></ul><p>Remember the original idea: Control operations need to be “natural”. Just that simple.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3edbe6f773b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/anymind-group/shared-some-tips-to-make-your-code-cleaner-part-2-d3edbe6f773b">[Shared] Some tips to make your code cleaner — part 2</a> was originally published in <a href="https://medium.com/anymind-group">AnyMind Group</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shared] Some tips to make your code cleaner]]></title>
            <link>https://medium.com/anymind-group/shared-some-tips-to-make-your-code-cleaner-9509594331e4?source=rss-66ff1b838fb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9509594331e4</guid>
            <dc:creator><![CDATA[Nguyen Trong Thang]]></dc:creator>
            <pubDate>Tue, 07 Jun 2022 07:13:32 GMT</pubDate>
            <atom:updated>2022-06-07T07:13:32.500Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*CbTR70tYPh8MOdA2MQ_uZA.png" /><figcaption>Photo by Mona</figcaption></figure><p>Writing code is not difficult, but writing “clean” code is not that easy I think.</p><p>What is “Clean” code?</p><ul><li>Newbie developers, or junior developers often finish the code without thinking about the future of the project.</li><li>Have you ever reopened your code that you wrote about 1 year ago? and you read it and find yourself unable to understand what you wrote before. Typically, a student or an algorithm code, naming variables a, b, c… and then re-reading it, We can’t remember what a, b, c is. . Clean code is code that you write first that you can read, then someone else reads it, knowing what you’re coding. People who write clean code will not abuse comments, but others still understand what you write.</li></ul><p><strong>1. Use the “Good” IDE</strong></p><p>First, choose the IDE that is suitable for your language, and “Good”.</p><p>For example, before I had code layout with HTML, CSS, JS on <strong>Sublime</strong>, Java in <strong>Eclipse</strong>, after switching to <strong>Webstorm</strong> and <strong>Visual Studio Code</strong>, it was like a new sky. Of course, the IDE is only a part, for new developers, choosing a good IDE will help avoid minor errors and ensure good performance.</p><p>Some IDEs I’m using: <strong>Visual Studio Code</strong> (Front end), <strong>Webstorm</strong> (Front end), <strong>PostMan</strong> ( Call API),…</p><p><strong>2. Variable names should be have meaning</strong></p><p>Naming variables is always a bit of a challenge, but try to put it in a way that is easy to understand</p><p>Not good code:</p><pre>var a = 1;</pre><p>Good code:</p><pre>var name = 1;</pre><p><strong>3. Using Camel/Pascal Case</strong></p><p><strong>a. Camel Case</strong></p><p>Basically, the first letter of the first word would be lowercase, the first letter of the next word would be uppercase</p><p>Not good code:</p><pre>var UserName = &#39;joe&#39;;<br>var UserAge = &#39;18&#39;;</pre><p>Good code:</p><pre>var userName = &#39;joe&#39;;<br>var userAge = &#39;18&#39;;</pre><p><strong>b. Pascal Case</strong></p><p>The first letters of words would be capitalized (Applicable to classes and functions)</p><p>Not good code:</p><pre>export class service {<br>  private readonly name: string = &#39;ad_unit&#39;;<br>}</pre><p>Good code:</p><pre>export class Service {<br>  private readonly name: string = &#39;ad_unit&#39;;<br>}</pre><p><strong>4. Pay attention to the code format</strong></p><p>Not good code:</p><pre>export class Service <br>{<br>private readonly name: string = &#39;ad_unit&#39;;<br>}</pre><p>Choosing a good IDE will help you format your code automatically, Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErXoTP-8RXpr72Dww5lySQ.png" /></figure><p><strong>5. Add Comments Where Necessary</strong></p><p>Only use comments in the “necessary” places, do not overdo it. Anyone who codes is lazy to comment, but try to add it so that we can understand it later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mnIu9xvYjCAz37POle5KYA.png" /></figure><p>Please add comments when your code wants to explain in depth, clearly, do not abuse comments.</p><p><strong>6. Code can be reused</strong></p><p>Writing code that can be reused is pretty important. It can reduce the overall lines of code in your project and make it highly efficient. You don’t want to copy-paste a function across multiple files/classes. Instead, create a generic function, then call it where needed. And, if any modifications are needed, you will only have to change the code in that function, not everywhere.</p><p>Might good more that you can use Generic and Dynamic.</p><p><strong>7. Don’t let 1 Class/Function get too big</strong></p><p>According to SOLID Principles, in a class / function do not code too many lines, each class should be a certain function, if it is too long, separate another class / function.</p><p><strong>8. Using Design patterns</strong></p><p>Choosing a good Design Pattern will make your code more manageable.</p><p><strong>9. Organize folders / Project better</strong></p><p>The division of the project’s layout, including which folders perform which functions, will help you better manage it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*wg4KFIsGf998nfIHL_D6ew.png" /></figure><p>Of course, it is still possible to write all the code in one file or all the files in one folder, but by the time it swells, it’s extremely difficult to expand, it takes time, and other people read it might hard to understand.</p><p><strong>10. Avoid the use of hard-fixed strings/numbers</strong></p><p>Not good code:</p><pre>if (userType == &#39;ADMIN&#39;) {<br>  // logic<br>}</pre><p>Good code:</p><pre>var ADMIN_TYPE = &#39;ADMIN&#39;;<br>if (userType === ADMIN_TYPE) {<br>  // logic<br>}</pre><p>In addition, you can also create an Enum to store fixed values.</p><p><strong>11. Remove the unused code</strong></p><p>You need to remove unused lines of code in the code process, javascript writers often use console.log to see the results, sometimes we forgot to remove it then its stay there forever.</p><p><strong>12. Using Async/Await</strong></p><p>Asynchronous programming will make your code run faster, but task management has never been easy.</p><p><strong>13. Don’t use ‘throw ex’</strong></p><p>Not good code:</p><pre>try<br>{<br>  // Do something..<br>}<br>catch (Exception ex)<br>{<br>  throw ex;<br>}</pre><p>Good code:</p><pre>try<br>{<br>  // Do something..<br>}<br>catch (Exception ex)<br>{<br>  throw;<br>}</pre><p><strong>14. Using the ternary operator</strong></p><p>Not good code:</p><pre>public exampleFunction(id: number) {<br>  if (id === 10)<br>  {<br>    return &#39;Value Id is 10&#39;;<br>  } else {<br>    return &#39;Value Id is not 10&#39;;<br>  }<br>}</pre><p>Good code:</p><pre>public exampleFunction(id: number) {<br>  return id === 10 ? &#39;Value Id is 10&#39; : &#39;Value Id is not 10&#39;;<br>}</pre><p><strong>15. Don’t add strings</strong></p><p>String addition is ok, but it will look very confusing.</p><p>Not good code:</p><pre>public exampleFunction(name: string, age: number) {<br>  return &#39;Name: &#39; + name + &#39;. Age: &#39; + age;<br>}</pre><p>Good code:</p><pre>public exampleFunction(name: string, age: number) {<br>  return `Name: ${name}. Age: ${age}`;<br>}</pre><p><strong>16. Using too many Parameters in the function</strong></p><p>Instead, group them into a class for compactness</p><p>Not good code:</p><pre>public exampleFunction(name: string, age: number, gender: string) {<br>  return {<br>    name,<br>    age,<br>    gender,<br>    // Other parameters too<br>  };<br>}</pre><p>Good code:</p><pre>public exampleFunction(userInfo: IUserInfo) {<br>  return userInfo;<br>}</pre><p><strong>17. Don’t leave catch at blank</strong></p><p>Not good code:</p><pre>public exampleFunction()<br>{<br>  try {<br>    this.doSomethingElse();<br>  } catch {<br>  }<br>}</pre><p>Good code:</p><pre>public exampleFunction()<br>{<br>  try {<br>    this.doSomethingElse();<br>  } catch {<br>    this.doOtherThing();<br>  }<br>}</pre><p><strong>18. Don’t Repeat Yourself (DRY)</strong></p><p>Not good code:</p><pre>public showListStudent(students: IUser[]) {<br>  const newStudents = students.map(student =&gt; {<br>    student.name = this.formatName(student.name);<br>    student.age = this.formatAge(student.age);<br>    return student;<br>  });<br>}</pre><pre>public showListTeacher(teachers: IUser[]) {<br>  const newTeachers = teachers.map(teacher =&gt; {<br>    teacher.name = this.formatName(teacher.name);<br>    teacher.age = this.formatAge(teacher.age);<br>    return teacher;<br>  });<br>}</pre><p>Good code:</p><pre>public formatDataUsers(users: IUser[]) {<br>  const newUsers = users.map(user =&gt; {<br>    user.name = this.formatName(user.name);<br>    user.age = this.formatAge(user.age);<br>    return user;<br>  });<br>}</pre><p><strong>19. SOLID</strong></p><p>The First 5 Principles of Object Oriented Design.</p><p><em>SOLID</em> is an acronym for the first five object-oriented design (OOD) principles by <em>Robert C. Martin</em></p><p>Which is:</p><ul><li>Single-Responsibility Principle</li><li>Open-Closed Principle</li><li>Liskov Substitution Principle</li><li>Interface Segregation Principle</li><li>Dependency Inversion Principle.</li></ul><p>Learn about these rules, it will help you a lot.</p><p><strong>20. Conclusion</strong></p><p>In this article, I shared with you some tips for writing cleaner code. I’m sure there will be many other tips, but for writing too long, I may share more in the following sections.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9509594331e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/anymind-group/shared-some-tips-to-make-your-code-cleaner-9509594331e4">[Shared] Some tips to make your code cleaner</a> was originally published in <a href="https://medium.com/anymind-group">AnyMind Group</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Product Mindset for Development Team?]]></title>
            <link>https://medium.com/anymind-group/product-mindset-for-development-team-cdadc066ab03?source=rss-66ff1b838fb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdadc066ab03</guid>
            <category><![CDATA[product-design]]></category>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[product-development]]></category>
            <category><![CDATA[product-mindset]]></category>
            <dc:creator><![CDATA[Nguyen Trong Thang]]></dc:creator>
            <pubDate>Thu, 10 Mar 2022 07:17:56 GMT</pubDate>
            <atom:updated>2022-03-10T07:17:56.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LjnCAcUDDtVknJnmxgQq5g.png" /><figcaption>Photo from Tim Herbig</figcaption></figure><p><em>In recent times, people have started talking about an issue that is not new but never old — Product mindset.</em></p><p><em>It is understandable that you are a product mindset when you are not only interested in how to make that product.</em></p><p><em>Are you still interested in why you made it? Who will use it and what problem will it be used for? Besides, you will be interested in how to make your product successful in the market or learn about competitors’ products as well as potential customers.</em></p><p><em>So do developers need a Product mindset or only management levels like PM, BA or UX designer need it? And how can I develop my own Product Mindset?</em></p><p>For me, I think this is big yes, all members in Development team needs a product mindset, but it’s also mean that this is not for all of our thoughts have to be the same. Also that’s will make and help a development team even stronger when they can absorb different opinions when making a product.</p><p>Okay lets start!</p><p>First, let’s learn about the concept of “Product Mindset” a bit, how is it called “Product Mindset”?</p><h3>I. Product Mindset</h3><p>You can consider yourself a product mindset when:</p><ul><li>You will not only care about how to make a product. Will you still be interested in why you have to do that product, or that function? And who will that product, or function, use and what problem will it solve?</li><li>You will be interested or thinking about how the product you make can be successful in the market. Is your product really needed in the market? Learn about your competitors’ products or find ways to promote yours to customers, for example.</li><li>You understand that the life cycle of a product you make begins before you even start making it (eg marketing, ideation, ..) and how long it will live after the project is finished. end, such as customer support, or a new upgrade.</li><li>…</li></ul><p>These are common traits found in people with a product mindset. And you’ll find these in most Product Owners and some good PMs.</p><p><em>So why does the Development team (Dev/QA/QC) need a product mindset?</em></p><h3>II. We all make products for the team to use</h3><p>Even if you don’t notice, but whether you are working for large or small projects, outsourcing or product company, our daily job is to make something, that thing will be used by someone else in your team for them continue to do their job.</p><p>For example:</p><ul><li>A Back End Developer makes APIs for the Front End team to use to build product.</li><li>A BA will make requirements for Dev/QA/QC to read and build products</li><li>A QC/QA when discovering a bug, will make a bug report ticket so that Developers can rely on it to fix that bug.</li></ul><p>Based on the above, it can be seen that, no matter what position you are working in, you will be making a product yourself. Plus, your product will be an important input so that other team members can do their job well, and lead to a common end result of making a great product together. And if you understand the basic elements to make a good product, you will also help the team a lot.</p><p>For me it was the following some points here:</p><ul><li><strong>Pay attention to cost, quality, and timeline:</strong> If you make products you will know these things. In particular, actively research to find out how what you make achieves the best overall effect. Also an important part of teamwork.</li><li><strong>Work with your team members and solve their problems using your products:</strong> Really consider them users of what you make, and luckily you have the opportunity to interact with them directly to find out what they need. Don’t do something just because your boss told you to, or because the process and template told you to. Find out what the project needs and suggest the right way from your own product. Another advice, don’t try to make something perfect, focus on solving the problem and the ability to change to improve later.</li><li><strong>Make your team’s products easily integrated:</strong> Remember, what you make will be used by others members, and what they make will be used by someone else. Make sure your team has discussed with each other to come up with a format that works for both the product and the way it works. That’s why Process was born. Process, in a way, is also a product!</li></ul><p>I think there are many other points but these are the ones that I think are the most important. The above points are useful for supporting in the development team, must have a product mindset.</p><p>At the same time, I think you don’t have to have the same product mindset as your Product Owner. We just need to agree on key values. The fact is, if in the work of a project that everyone has exactly the same way of thinking, then I will think that is a really bad thing.</p><h3>III. We need different mindsets to see different problems.</h3><p>Mindset comes from work and skill. Different jobs and skills will have different mindsets.</p><p>In the project:</p><ul><li>You need a PM with a mindset that tells you the dangers of timelines and resources</li><li>You need 1 BA to tell you what end users need</li><li>You need a Developer to tell you technical limitations</li><li>You need a QA/QC who thinks about special cases that no one else has thought of.</li></ul><p>To be more clear, I will give an example I have encountered in the process of making products before:</p><blockquote>In a time when a QA was testing a function that I just deployed to Staging (version testing), this QA found a bug and he thought it was a serious bug, and the QA passed this bug to me and PM to check this bug. After 1 hour of discussion, me and PM agree that this is not really a bug or something existing in the product it’s a completely new missing function.</blockquote><p>And all those mindsets will help us to see different aspects of Product. so that we can be sure that what we decide is not subjective and has considered many sides of the issue.</p><p>However, to make communication clear and easy to reach a consensus, we need common goals and common skills.</p><p>For example:</p><ul><li>A BA will easily talk to a Developer if he also has some knowledge of code, if he at least understands what the word “Framework” is, and if using a framework then roughly what are the problems. If he can speak language in technical of Developer too, that’s fine. That’s an example of common skills.</li><li>At the beginning of the project, the PM said, “Our goal is to finish this product in 7 weeks”. That’s Goal, not Mindset. It will influence all our thoughts and decisions later on. , for every department.</li></ul><p>In short, you need a different mindset, common goals and some common skills. Instead of focusing too much on unifying mindset, we should focus on how to communicate more effectively when there is conflict, and the whole team understand and agree on common goals. Believe me when I say that, once we have agreed on a goal, there will be many things that we will have the same way of thinking.</p><p>Usually the PM — project leader will be the one trying to lead the team towards common goals. I rarely hear that a PM will lead the Development team to have a common mindset.</p><h3>IV. Conclusion</h3><p>Again, just my opinion, a Front End developer with 8 years of experience. Base on this we can know that Product Mindset really important for Development team and with Product Mindset will help building product successful together. <br>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdadc066ab03" width="1" height="1" alt=""><hr><p><a href="https://medium.com/anymind-group/product-mindset-for-development-team-cdadc066ab03">Product Mindset for Development Team?</a> was originally published in <a href="https://medium.com/anymind-group">AnyMind Group</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Tech Blog] Should we use Angular Route Resolver?]]></title>
            <link>https://medium.com/anymind-group/should-we-use-angular-route-resolver-973c14eceb90?source=rss-66ff1b838fb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/973c14eceb90</guid>
            <dc:creator><![CDATA[Nguyen Trong Thang]]></dc:creator>
            <pubDate>Wed, 22 Dec 2021 11:11:25 GMT</pubDate>
            <atom:updated>2021-12-23T03:12:06.498Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/569/0*RIcqFUMfWGXdHEef.png" /></figure><p>When developing an application with Angular, we are basically fetching data from the API with the <strong>ngOnInit</strong> hook, and then rendering it to the UI. While waiting for the api to return the complete data, the component renders the loading, skeleton. etc</p><p>We still have another way to get the data first and then redirect your component. It’s call Route Resolver.</p><p>In this article, I will share with you what is Route Resolver is and how to use it and apply it in a real-life case, should we use it or not.</p><h3>So what is Angular Resolver?</h3><p>Angular Route Resolver is used for pre-fetching some of the data when the user is navigating from one route to another. It can be defined as a smooth approach for enhancing user experience by loading data before the user navigates to a particular component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/0*Ye9aHikCCju1tKze.png" /></figure><p><em>Example simple flow how Resolver work</em></p><h3>1. How to create simple Resolver</h3><p>One simple Resolver to get detail of Site:</p><pre>@Injectable({<br>  providedIn: &#39;root&#39;,<br>})<br>export class SiteSettingResolver implements Resolve&lt;any&gt; {<br>  constructor(private siteService: SiteService,<br>              private router: Router) {<br>  }</pre><pre>  handleError(error) {<br>    this.router.navigateByUrl(&#39;/404&#39;);<br>    return throwError(error);<br>  }</pre><pre>  resolve(<br>    route: ActivatedRouteSnapshot,<br>    state: RouterStateSnapshot<br>  ): Observable&lt;{ site: Site }&gt; {<br>    const siteID = route.paramMap.get(&#39;id&#39;);<br>    if (!siteID) {<br>      setTimeout(() =&gt; {<br>        this.router.navigate([&#39;/404&#39;]);<br>      }, 500);<br>    } else {<br>      return this.siteService.detail(siteID).pipe(<br>        map(resp =&gt; {<br>          return {site: resp as Site};<br>        }),<br>        catchError(err =&gt; this.handleError(err))<br>      );<br>    }<br>  }<br>}</pre><p>Next we are config router for Site Setting Module:</p><pre>{<br>    path: &#39;site-settings&#39;,<br>    component: SiteSettingsComponent,<br>    resolve: { preFetchData: SiteSettingResolver }<br>}</pre><p>This is Site Setting Component show us how to get data from Resolver:</p><pre>constructor(private activatedRoute: ActivatedRoute) {}</pre><pre>get site(): Site {<br>    return this.activatedRoute.snapshot.data.preFetchData.site;<br>}</pre><p>Now imagine an HTTP request response data in 5 seconds. After clicking a link in the application, the HTTP request starts. Routing will not be completed before that HTTP request responds with data. Therefore, if HTTP takes 5 seconds, it will also take 5 seconds for routing to complete.</p><h3>2. What if we don’t use Resolver</h3><p>So how about the usual way (Fetch the detail data of the Site in the ngOnInit hook in the component without using the resolver)?</p><p>This time. The navigation will run right through the site details page without a hitch. Furthermore, our component should add a loading indicator, skeleton loading, etc for user experience purposes.</p><p>This is example one component I don’t use Resolver. I added loading so that the user knows and waits for the data to load.</p><pre>ngOnInit(): void {<br>    this.loading.show();<br>    this.siteService.detailSiteWeb(siteId)<br>        .subscribe((resp: Site) =&gt; {<br>            this.loading.hide();<br>            this.site = resp;<br>    }, err =&gt; {<br>        this.router.navigateByUrl(&#39;/404&#39;);<br>    });<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/0*kNPGXk3xTYjMG0cE.png" /></figure><p><em>Example simple flow when we don’t use </em><em>Resolver</em></p><h3>3. Conclusion</h3><p>So with this article we can understand about how Resolver work. In my opinion any Application should be run fast and the data should load asynchronously at runtime. So we may need to consider carefully before using Resolver.</p><p>In current project I’m working on which is AnyManager I’m not using much Resolver. I’m just use a resolver when I want to fetch data even before the user is directed to the URL. The resolver can include service calls that will give us the data needed to load the next page.</p><p>Here’s what we may need to keep in mind when deciding to use Resolvers:</p><ul><li>If the Resolver is not resolved, you will not be able to see your component rendered. So if you use Observable, and Observable may never complete then you won’t be able to navigate to the page.</li><li>Do not share between multiple resolvers together.</li></ul><p>Therefore, for streams that return multiple values, you should not use resolvers.<br>In my opinion, we should only use Resolver to get part of the data, then the component will continue to execute other connections.</p><h3>Ref:</h3><ul><li><a href="https://angular.io/api/router/Resolve">https://angular.io/api/router/Resolve</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=973c14eceb90" width="1" height="1" alt=""><hr><p><a href="https://medium.com/anymind-group/should-we-use-angular-route-resolver-973c14eceb90">[Tech Blog] Should we use Angular Route Resolver?</a> was originally published in <a href="https://medium.com/anymind-group">AnyMind Group</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>