<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: bytefish</title>
    <description>The latest articles on DEV Community by bytefish (@bytefish).</description>
    <link>https://dev.to/bytefish</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F604382%2F0f270ae4-c040-4752-89b9-29c242043f4e.png</url>
      <title>DEV Community: bytefish</title>
      <link>https://dev.to/bytefish</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bytefish"/>
    <language>en</language>
    <item>
      <title>5 Ways to Add Breakpoints on Chrome Devtools</title>
      <dc:creator>bytefish</dc:creator>
      <pubDate>Fri, 07 Jan 2022 07:43:51 +0000</pubDate>
      <link>https://dev.to/bytefish/5-ways-to-add-breakpoints-on-chrome-devtools-f28</link>
      <guid>https://dev.to/bytefish/5-ways-to-add-breakpoints-on-chrome-devtools-f28</guid>
      <description>&lt;p&gt;Debug is a skill that every developer must master, and adding breakpoints to the code is the basic of debugging. This article will share 5 ways to add breakpoints in Chrome DevTool.&lt;/p&gt;




&lt;h2&gt;
  
  
  1# Add breakpoints directly
&lt;/h2&gt;

&lt;p&gt;Go to Source Tag of Chrome Devtools, click the line number where the code is located to add a breakpoint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tnkgsaf3kypsvu0j34e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tnkgsaf3kypsvu0j34e.png" alt="111"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This should be the most common way for everyone to add breakpoints.&lt;/p&gt;

&lt;h2&gt;
  
  
  2# Conditional breakpoints
&lt;/h2&gt;

&lt;p&gt;But sometimes, we want a breakpoint to take effect only under certain conditions. At this time, we can take the following approach.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Right-click the line number column&lt;/li&gt;
&lt;li&gt;Choose Add conditional breakpoint&lt;/li&gt;
&lt;li&gt;Enter your condition in the dialog&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For Example, we want to pause the code when i is greater than 10,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`i * i = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezezng0nkv8bjy3qcwud.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezezng0nkv8bjy3qcwud.gif" alt="Image desceetion"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3# DOM change breakpoints
&lt;/h2&gt;

&lt;p&gt;In some cases, we don't want to pause the code at a certain location, but only when a DOM element changes. At this time, we can do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Click the Elements tab.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to the element that you want to set the breakpoint on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right-click the element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hover over Break on then select Subtree modifications, Attribute modifications or Node removal.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, we want to pause the code when the hello element will change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="mi"&gt;2022&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;onclick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2z47n13c7rdbeqot7i0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2z47n13c7rdbeqot7i0.gif" alt="Image descriptweion"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Subtree modifications. Triggered when a child of the currently-selected node is removed or added, or the contents of a child are changed. Not triggered on child node attribute changes, or on any changes to the currently-selected node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Attributes modifications: Triggered when an attribute is added or removed on the currently-selected node, or when an attribute value changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Node Removal: Triggered when the currently-selected node is removed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4# XHR/Fetch breakpoints
&lt;/h2&gt;

&lt;p&gt;If you want to pause the code when JavaScript is trying to make an HTTP request to a URL, we can do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the Sources tab.
Expand the XHR Breakpoints pane.
Click Add breakpoint.
Enter the string which you want to break on. DevTools pauses when this string is present anywhere in an XHR's request URL.
Press Enter to confirm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, we want to pause the code when the script tries to requesting &lt;code&gt;api.github.com&lt;/code&gt; .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="mi"&gt;2022&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.github.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm1apj7iv413q5f7d4cik.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm1apj7iv413q5f7d4cik.gif" alt="Im33"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5# Event listener breakpoints
&lt;/h2&gt;

&lt;p&gt;Of course, we can also pause the code when a certain event is triggered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="mi"&gt;2022&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;onclick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello 2022&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to pause the code after the hello element is clicked, then we can do this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmj8sc8oykpurbtaedbih.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmj8sc8oykpurbtaedbih.gif" alt="Image 444"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What Is the Difference in Thinking Model Between Programmers and Normal Persons?</title>
      <dc:creator>bytefish</dc:creator>
      <pubDate>Wed, 05 Jan 2022 07:50:16 +0000</pubDate>
      <link>https://dev.to/bytefish/what-is-the-difference-in-thinking-model-between-programmers-and-normal-persons-4c6m</link>
      <guid>https://dev.to/bytefish/what-is-the-difference-in-thinking-model-between-programmers-and-normal-persons-4c6m</guid>
      <description>&lt;p&gt;Recently, one of my friends approached me. He told me that he wanted to learn programming, but he didn’t know if he was suitable for this profession. So he asked me a question: Is there any difference between programmers and normal persons in thinking model?&lt;/p&gt;

&lt;p&gt;I know that he has never learned programming before, and it is quite difficult to introduce programming thinking to people who have no coding experience. Um, after thinking about it for a while, I plan to explain the problem in another way.&lt;/p&gt;

&lt;p&gt;I asked him: If you were to buy two pounds of apples now, what would you do?&lt;/p&gt;

&lt;p&gt;He said: Go directly to the fruit shop to buy it.&lt;/p&gt;

&lt;p&gt;I said: If we want to express the process of buying apples programmatically, it might be like this.&lt;/p&gt;




&lt;p&gt;First of all, we must clarify our needs, for example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I plan to buy about two pounds of apples&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The price I can accept is less than 1.5$ per pound&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then we can design the following process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Query surrounding fruit shops to get a shop list;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Visit the fruit shops in the list one by one, and perform the following operations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the fruit shop;&lt;/li&gt;
&lt;li&gt;If the fruit shop is not open, end the current process and then visit the next fruit shop;&lt;/li&gt;
&lt;li&gt;If there is no apple left in the fruit shop, end the current process and then visit the next fruit shop;&lt;/li&gt;
&lt;li&gt;If the price of the apples is higher than US$1.5 per pound, then:

&lt;ul&gt;
&lt;li&gt;Ask the shop owner whether he is willing to lower the price;&lt;/li&gt;
&lt;li&gt;If the shop owner does not agree, end the current process and then visit the next fruit shop&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Take a bag;&lt;/li&gt;
&lt;li&gt;Start picking apples;&lt;/li&gt;
&lt;li&gt;Continue the following operations until the weight of the apples in the bag is greater than two pounds:

&lt;ul&gt;
&lt;li&gt;Pick an apple from the pile of apples;&lt;/li&gt;
&lt;li&gt;Put the apple in the bag;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Calculate the total price of apples in the bag;&lt;/li&gt;
&lt;li&gt;Total price = weight of apples in the bag multiply unit price of apples;&lt;/li&gt;
&lt;li&gt;Pay money;&lt;/li&gt;
&lt;li&gt;Leave the shop;&lt;/li&gt;
&lt;li&gt;Skip the remaining fruit shops in the list;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Take apples home;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Programmers need to consider problems in a rigorous and accurate way.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the above process, we need to record the surrounding fruit shops, so we need to define the variable &lt;strong&gt;friutShops&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We need to visit different fruit shops in turn, which is called &lt;strong&gt;traversal&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then we need to judge the boundary conditions, for example, what if the fruit shop does not open? What if the price of Apple exceeds my expectations?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When we are picking apples, we need to keep putting apples in the bag until it exceeds two pounds. This is called &lt;strong&gt;looping&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the most basic steps when a programmer considers a problem.&lt;/p&gt;

&lt;p&gt;If we use pseudo-code to represent this process, it may be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Query&lt;/span&gt; &lt;span class="nx"&gt;surrounding&lt;/span&gt; &lt;span class="nx"&gt;fruit&lt;/span&gt; &lt;span class="nx"&gt;shops&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;fruitShops&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruitShop&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;fruitShops&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruitShop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isOpen&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruitShop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apple&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;Ask&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;shop&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt; &lt;span class="nx"&gt;whether&lt;/span&gt; &lt;span class="nx"&gt;he&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;willing&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;lower&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;shop&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt; &lt;span class="nx"&gt;does&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;agree&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;fruitShop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apple&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newPrice&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;Take&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;bag&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;Start&lt;/span&gt; &lt;span class="nx"&gt;picking&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;weight&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;bag&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;less&lt;/span&gt; &lt;span class="nx"&gt;than&lt;/span&gt; &lt;span class="nx"&gt;two&lt;/span&gt; &lt;span class="nx"&gt;pounds&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;Pick&lt;/span&gt; &lt;span class="nx"&gt;an&lt;/span&gt; &lt;span class="nx"&gt;apple&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;pile&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;Put&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;apple&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;bag&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;Calculate&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;bag&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;Total&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;weight&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;bag&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;unit&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;Pay&lt;/span&gt; &lt;span class="nx"&gt;money&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;Leave&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;shop&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;Take&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt; &lt;span class="nx"&gt;home&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;After listening to my description, my friend said: Um, you explained well, it seems simple.&lt;/p&gt;

&lt;p&gt;Then, I went on to say: The process is really not complicated, but in the real development, we have to consider many things. For example, in the above case, as long as we find a shop where the price of apples is less than $1.5 per pound, we will buy apples immediately. But if now we want to find the fruit shop with the lowest price for apples. What should we do?&lt;/p&gt;

&lt;p&gt;My friend said: It’s too simple. Go to every fruit shop and ask for the price. Then you can find the fruit shop with the lowest price.&lt;/p&gt;

&lt;p&gt;I said: But we are very lazy and don’t want to walk too much. Now there are 10 fruit shops around us, and they are distributed in different locations. If we want to walk as little as possible while traversing these 10 fruit shops, how can we arrange the order of visits to minimize the total path?&lt;/p&gt;

&lt;p&gt;After thinking about it for a long time, my friend replied: Well, this question sounds complicated, I don’t know.&lt;/p&gt;

&lt;p&gt;I said: It’s okay. This is actually a classic algorithm problem in programming. It’s normal that you won’t think of the answer for a while. When a programmer writes code, he must not only solve the problem correctly, but also solve the problem as efficiently as possible. In the development process, we are solving similar problems one by one.&lt;/p&gt;

&lt;p&gt;Then I continue: And when we choose apples, we all hope to buy bigger and redder apples. Now you need to select N apples from the pile of apples. And you need to make sure that they are the best apples and that the sum of their masses is just over 2 pounds. How do you choose?&lt;/p&gt;

&lt;p&gt;My friend: Well, it’s still a bit difficult.&lt;/p&gt;

&lt;p&gt;I said: Some people will first sort the apple piles according to the quality, and then choose the best apples, but how to sort the apple piles quickly is another problem.&lt;/p&gt;

&lt;p&gt;My friend: Okay, stop talking about it, my mind is a little dizzy. It seems that I am still not suitable as a programmer.&lt;/p&gt;

&lt;p&gt;I said: Haha, it’s okay. I’m a little hungry. Let’s buy some apples first. 😁😁&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>career</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Learn Python From Scratch As a Frontend Developer</title>
      <dc:creator>bytefish</dc:creator>
      <pubDate>Sun, 28 Nov 2021 02:06:52 +0000</pubDate>
      <link>https://dev.to/bytefish/learn-python-from-scratch-as-a-frontend-developer-1hmf</link>
      <guid>https://dev.to/bytefish/learn-python-from-scratch-as-a-frontend-developer-1hmf</guid>
      <description>&lt;p&gt;As I mentioned in the title, I am a frontend developer who is familiar with JavaScript. Recently, I am going to learn Python from scratch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do I want to learn Python now?
&lt;/h2&gt;

&lt;p&gt;Because I want to write a web crawler and do some data analysis.&lt;/p&gt;

&lt;p&gt;I have two choices for web scraping:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Nodejs-related tech stack&lt;/li&gt;
&lt;li&gt;Use Python-related tech stack&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nodejs is a tool that I have worked with for some years. If I choose Node for web scraping, I can reuse my knowledge and don’t need to learn new things.&lt;/p&gt;

&lt;p&gt;But as I know, Python is a more popular language for web scraping. It has a thriving ecosystem in this field. If I choose Python, there are lots of tools, libraries, tutorials, and Stack Overflow Q&amp;amp;A.&lt;/p&gt;

&lt;p&gt;Meanwhile, I want to learn a new programming language to refresh my brain. So, I choose Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Knowledge Background
&lt;/h2&gt;

&lt;p&gt;Actually, I am not totally new to Python. Several years ago, with the popularity of artificial intelligence, I followed the trend and learned Python for a while.&lt;/p&gt;

&lt;p&gt;But I didn’t dig into Python. And with time passed, I forget most knowledge about it. Now, Python is truly a new language for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to learn a new programming language?
&lt;/h2&gt;

&lt;p&gt;In my opinion, programming is an art to imitate the real world. No matter which language, there are always date types such as number, string, boolean, there are always some data structures such as array, map, set. We need keywords such as if , for to control flow, we need libraries to send network requests.&lt;/p&gt;

&lt;p&gt;With experience in JavaScript, I have the confidence to learn Python faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tutoirals about Python
&lt;/h2&gt;

&lt;p&gt;When I search tutorials for Python on Google, there are pretty many results. Um, they are great.&lt;/p&gt;

&lt;p&gt;But there all have a problem: Almost all the tutorials assume that learners are totally new to programming.&lt;/p&gt;

&lt;p&gt;They will explain what is variable, what is a function, what is a class, etc. These concepts are important for new coders, but it’s meanless for experienced coders.&lt;/p&gt;

&lt;p&gt;So I’m trying to use a new way to learn Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Series
&lt;/h2&gt;

&lt;p&gt;Writing is a great way to save the thought eternally. I plan to start a series to record my experience to learn Python.&lt;/p&gt;

&lt;p&gt;I will record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How I learn Python&lt;/li&gt;
&lt;li&gt;What are my thoughts on Python (maybe wrong)&lt;/li&gt;
&lt;li&gt;What bugs I have met.&lt;/li&gt;
&lt;li&gt;…&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  My Goal
&lt;/h2&gt;

&lt;p&gt;Having a vivid goal is important. I am not learning Python itself, I am learning to use Python to finish real tasks.&lt;/p&gt;

&lt;p&gt;My goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write a robust web crawler in Python&lt;/li&gt;
&lt;li&gt;Analysis data and create sheets by Python&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How did you learn Python?&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
