<?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 Lynx Chang on Medium]]></title>
        <description><![CDATA[Stories by Lynx Chang on Medium]]></description>
        <link>https://medium.com/@goblin5417?source=rss-df6e201c11b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JWjp0WHz7BaqkV2rNB7Ntw.png</url>
            <title>Stories by Lynx Chang on Medium</title>
            <link>https://medium.com/@goblin5417?source=rss-df6e201c11b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 18:06:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@goblin5417/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[Vector in C++]]></title>
            <link>https://medium.com/@goblin5417/vector-in-c-2c389741f502?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c389741f502</guid>
            <category><![CDATA[vector]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Wed, 02 Nov 2022 23:10:03 GMT</pubDate>
            <atom:updated>2022-11-02T23:10:03.994Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HSgGPRia_QtIsj42JB5I0w.png" /></figure><h3>Introduction</h3><ul><li>Vectors are part of STL.</li><li>Vectors are sequence containers representing arrays that can change in size.</li><li>Vectors use <strong>contiguous storage locations</strong> for their elements, so their elements can also be accessed using <strong>offsets</strong> on regular pointers to their elements.</li><li>Vector size can change dynamically, with their storage being handled automatically by the container.</li><li>Vectors use a dynamically allocated array to store their elements.</li></ul><h3>Internal Storage</h3><ul><li>Vectors use a <strong>dynamically allocated array</strong> to store their elements.</li><li>This array may need to be reallocated in order to grow in size when new elements are inserted (allocate a new array and move all elements to it) and it is expensive in terms of processing time.</li><li>Vector containers may allocate some <strong>extra storage</strong> to accommodate for possible growth.</li><li>Compared to arrays, vectors <strong>consume more memory</strong> in exchange for the ability to manage storage and grow dynamically.</li></ul><h3>When to Use Vectors?</h3><ul><li>Data is consistently changing.</li><li>The size of data is unknown.</li><li>Elements are not predefined.</li><li>Compared to arrays, there are more ways to copy vectors.</li></ul><h3>Declaration</h3><p>Include #include&lt;vector&gt; library.</p><pre>// Syntax: vector&lt;object_type&gt; vector_variable_name;</pre><pre>#include &lt;vector&gt;<br>using namespace std;</pre><pre>vector&lt;int&gt; numbers;</pre><h3>Initialization</h3><ol><li>Pushing the values one-by-one in vector using push_back():</li></ol><pre>// Syntax: vector_name.push_back(element_value);</pre><pre>numbers.push_back(3);<br>numbers.push_back(8);<br>// numbers = { 3, 8 } </pre><p>2. Using the overload constructor of the vector Class:</p><pre>// Syntax: vector&lt;object_type&gt; vector_name(number_of_repetition, element_value);</pre><pre>vector&lt;int&gt; number1(2, 3);<br>// numbers1 = { 3, 3 }</pre><p>3. Using Array:</p><pre>// Syntax: vector&lt;object_type&gt; vector_name {val1,val2,....,valn};</pre><pre>vector&lt;int&gt; number2 { 9, 3, 6 };<br>// numbers2 = { 9, 3, 6 }</pre><p>4. Using already initialized vector:</p><pre>// Syntax: vector&lt;object_type&gt; vector_name_2(vector_name_1.begin(),vector_name_1.end());</pre><pre>vector&lt;int&gt; number3(number2.begin(), number2.end());<br>// numbers3 = { 9, 3, 6 }</pre><h3>Member Functions</h3><h4>Iterators</h4><ul><li>begin(): Returns an iterator pointing to the first element in the vector.</li><li>end(): Returns an iterator pointing to the last element in the vector.</li></ul><pre>vector&lt;int&gt; a = { 3, 4, 5 };<br>for (auto i = a.begin(); i != a.end(); ++i) {<br>    cout &lt;&lt; *i &lt;&lt; &quot; &quot;;<br>}<br>cout &lt;&lt; endl;</pre><p>Output:</p><pre>3 4 5</pre><h4>Capacity</h4><ul><li>size(): Returns the number of elements currently present in the vector.</li><li>max_size(): Returns the maximum number of elements that a vector can hold.</li><li>capacity(): Returns the storage capacity currently allocated to the vector.</li><li>resize(n): Resizes the container to store n elements.</li><li>empty(): Returns whether the container is empty or not.</li></ul><pre>vector&lt;int&gt; b = { 5, 7, 1 };<br>cout &lt;&lt; b.size() &lt;&lt; endl;<br>cout &lt;&lt; b.max_size() &lt;&lt; endl;<br>cout &lt;&lt; b.capacity() &lt;&lt; endl;<br>b.resize(5);<br>cout &lt;&lt; b.size() &lt;&lt; endl;<br>cout &lt;&lt; b.empty() &lt;&lt; endl;</pre><p>Output:</p><pre>3<br>2305843009213693951<br>3<br>5<br>0</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c389741f502" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Note of GPT-3]]></title>
            <link>https://medium.com/@goblin5417/note-of-gpt-3-d997ced2d2a2?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d997ced2d2a2</guid>
            <category><![CDATA[neural-network-training]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[gpt-3]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Fri, 28 Oct 2022 13:34:55 GMT</pubDate>
            <atom:updated>2022-10-28T13:50:40.525Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4zmZVrDxI8ReU8gNPktQiA.png" /></figure><p>GPT-3 is a neural network machine learning model trained using <strong>internet data</strong> to generate any type of text. It requires a small amount of input text to generate large volumes of relevant and sophisticated machine-generated text.</p><h3>How does GPT-3 work?</h3><p>When a user provides text input, the system analyzes the language and uses a text predictor to create the most likely output. This is accomplished by training the system on the vast body of internet text to spot patterns.</p><p>GPT-3 is focused on text generation based on being pre-trained on a huge amount of text.</p><h3>Capabilities of GPT-3</h3><ul><li>Generate various text content depending on the context and predict statements according to available sentences.</li><li>The text predictor of GPT-3 processes all the text existing on the internet and can calculate the most statistically expected output.</li><li>Write poetry, blogs, PR content, resumes, and technical documentation.</li><li>Analyze the context in the provided text and based on that it can generate business idea pitches, fan fiction, memes, and so on.</li><li>Create workable code that can be run without error.</li><li>One developer has combined the UI prototyping tool Figma with GPT-3 to create websites just by describing them in a sentence or two.</li><li>Clone websites by providing a URL as suggested text.</li><li>In the gaming world, create realistic chat dialog, quizzes, images and other graphics based on text suggestions.</li></ul><h3>History of GPT-3</h3><p>The version of GPT:</p><ul><li>The first version of the GPT (117 million parameters):</li><li>Showed that the language prediction model could capture global knowledge.</li><li>Proposed that a language model must be learned using unlabeled data, then, improved through samples of natural language processing tasks such as text classification, sentiment analysis, and word segmentation.</li></ul><p>GPT-2 (1.5 billio parameters):</p><ul><li>Able to generate realistic text that was refused by OpenAI to be made open-source as the company was concerned about the development and spread of fake news.</li></ul><p>GPT-3 (175 billion parameters)</p><h3>Benefits of GPT-3</h3><p>Whenever a large amount of text needs to be generated from a machine based on some small amount of text input, GPT-3 provides a good solution. There are many situations where it’s not practical or efficient to have a human on hand to generate text output.</p><h3>Risks and limitations of GPT-3</h3><ul><li>The biggest issue is that GPT-3 is not constantly learning. It has been pre-trained, which means that it doesn’t have an ongoing long-term memory that learns from each interaction.</li><li>Limited input size: A user cannot provide a lot of text as input for the output. GPT-3 can only deal with input text a few sentences long.</li><li>A wide range of machine learning bias: Since the model was trained on internet text, it exhibits many of the biases that humans exhibit in their online text.</li></ul><h3>Using GPT-3</h3><ul><li>OpenAI has released an API for accessing AI models developed by them.</li></ul><h3>Reference</h3><ul><li><a href="https://www.einfochips.com/blog/openai-gpt-3-the-most-powerful-language-model-an-overview/">OpenAI GPT-3, the most powerful language model: An Overview</a></li><li><a href="https://www.techtarget.com/searchenterpriseai/definition/GPT-3">GPT-3</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d997ced2d2a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Learn a New Programming Language Systematically and Quickly]]></title>
            <link>https://medium.com/@goblin5417/how-to-learn-a-new-programming-language-systematically-and-quickly-f312026039bf?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f312026039bf</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Fri, 26 Aug 2022 10:03:59 GMT</pubDate>
            <atom:updated>2022-08-27T15:54:07.827Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9UfGD-EqZFFhTkBxQNH1GA.png" /></figure><h3>Introduction</h3><p>I was the CTO of a software company and was responsible for interviewing new developers. Usually, it was difficult to find developers with the full skill set that we needed, so I designed some training materials to help the team members learn systematically and quickly.</p><p>This also can be your practice of a language before a coding test interview.</p><h4><strong>The preconditions of this guide:</strong></h4><ul><li>You already know at least one programming language.</li><li>You know the concept of data structure.</li></ul><h4>The steps to learn:</h4><ol><li>Read the concept of the language from Wikipedia or its official site.</li><li>Learn the syntax of the language.</li><li>Learn the commonly used standard libraries.</li><li>Implement commonly used data structures.</li></ol><h3>Concept</h3><ul><li>Features of the language</li><li>Uses of the language</li></ul><h3>Syntax</h3><p>Have a quick look at this part and write some examples to familiarize the syntax.</p><ul><li>Variables and data type</li><li>Control Structures</li><li>Function</li><li>Class</li><li>Input and output</li><li>Special syntax in the language, e.g. Goroutines</li></ul><h3>Commonly Used Standard Libraries</h3><p>You need to know how to use them and how they are implemented.</p><ul><li>String processing</li><li>Array</li><li>Sorting</li><li>Mapping</li><li>Testing</li></ul><h3>Implement Commonly Used Data Structures</h3><ul><li>Array</li><li>Linked list: Singly linked list, Double linked list</li><li>Stack</li><li>Queue</li><li>Tree: Traversal (preorder, inorder, postorder), Binary search tree, Trie</li><li>Sorting: Quick sort, Insertion sort, Merge sort</li></ul><p>If you have any questions or suggestions, you can send me a message through my LinkedIn:<br><a href="https://www.linkedin.com/in/yuan-yu-c/">https://www.linkedin.com/in/yuan-yu-c/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f312026039bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sorting in Python]]></title>
            <link>https://medium.com/@goblin5417/sorting-in-python-dc8541db69d3?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc8541db69d3</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[implementation]]></category>
            <category><![CDATA[sorting]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Mon, 11 Jul 2022 10:32:13 GMT</pubDate>
            <atom:updated>2022-07-11T10:53:49.602Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PbW8UF5cY6GOdaZGXMgPUg.png" /></figure><h3>Sorting Basics</h3><h4>sorted()</h4><ul><li>Returns a new sorted list.</li><li>Example:</li></ul><pre>&gt;&gt;&gt; sorted([5, 2, 3, 1, 4])<br>[1, 2, 3, 4, 5]</pre><h4>list.sort()</h4><ul><li>Modifies the list in-place.</li><li>Example:</li></ul><pre>&gt;&gt;&gt; a = [5, 2, 3, 1, 4]<br>&gt;&gt;&gt; a.sort()<br>&gt;&gt;&gt; a<br>[1, 2, 3, 4, 5]</pre><h4>Key Functions</h4><ul><li>Sort complex objects using some of the object’s indices as keys.</li><li>Example:</li></ul><pre>&gt;&gt;&gt; students = [<br>...     (&#39;john&#39;, &#39;A&#39;, 15),<br>...     (&#39;jane&#39;, &#39;B&#39;, 12),<br>...     (&#39;dave&#39;, &#39;B&#39;, 10),<br>... ]<br>&gt;&gt;&gt; sorted(students, key=lambda student: student[2])   # sort by age<br>[(&#39;dave&#39;, &#39;B&#39;, 10), (&#39;jane&#39;, &#39;B&#39;, 12), (&#39;john&#39;, &#39;A&#39;, 15)]</pre><h4>Ascending and Descending</h4><ul><li>Accept a reverse parameter with a boolean value.</li><li>Example:</li></ul><pre>&gt;&gt;&gt; sorted([2, 1, 3], reverse=False)<br>[1, 2, 3]<br><br>&gt;&gt;&gt; sorted([2, 1, 3], reverse=True)<br>[3, 2, 1]</pre><h3>Sorting Implementation — TimSort</h3><ul><li>Python’s sorted() and sort() use an algorithm called <a href="https://en.wikipedia.org/wiki/Timsort"><strong>TimSort</strong></a>.</li><li>TimSort is a sorting algorithm that is a hybrid of <strong>merge sort</strong> and <strong>insertion sort</strong> algorithm.</li><li>It is a stable algorithm.</li><li>The list that needs to be sorted is first analyzed, and based on the best approach is selected.</li></ul><h4>TimSort implementation</h4><ol><li>Divide the array into blocks known as <strong>run</strong>.</li><li>The size of a run can either be 32 or 64.</li><li>Sort the elements of every run using insertion sort.</li><li>Merge the sorted runs using the merge sort algorithm.</li><li>Double the size of the merged array after every iteration.</li></ol><h4>Performance</h4><ul><li>Worst-case performance: O(nlogn)</li><li>Best-case performance: O(n)</li><li>Average performance: O(nlogn)</li><li>Worst-case space complexity: O(n)</li></ul><h4>Complexity Comparision with Merge and Quick Sort</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/0*XFgDQTGkQh2r3b0x.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc8541db69d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DDNS（Dynamic Domain Name Server）]]></title>
            <link>https://medium.com/@goblin5417/ddns-49bff36bd27a?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/49bff36bd27a</guid>
            <category><![CDATA[network]]></category>
            <category><![CDATA[ddns]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Thu, 20 Feb 2020 07:45:12 GMT</pubDate>
            <atom:updated>2020-08-08T15:22:45.489Z</atom:updated>
            <content:encoded><![CDATA[<p>DDNS（Dynamic Domain Name Server），動態域名服務。很多普通路由器或者智能路由器設置中，都可以找到 DDNS（動態 DNS）功能。</p><p>通俗的說，DDNS 是將用戶的動態 IP 位址映射到一個固定的域名解析服務上，用戶每次連接網絡的時候客戶端程序就會通過信息傳遞，把該主機的動態 IP 位址傳送給位於服務商主機上的伺服器程序，伺服器程序負責提供 DNS 服務並實現動態域名解析。</p><p>再更簡單的說，目前路由器撥號上網獲得的是動態 IP，DDNS 可以將路由器變化的外網 IP 和固定的域名綁定，用戶就可以在外網通過該固定域名進行訪問路由器。</p><h3>服務原理</h3><p>DDNS 是把互聯網域名指向可變 IP 位址的系統。DNS 只是提供了域名和 IP 位址之間的靜態對應關係，當 IP 位址發生變化時，DNS 無法動態的更新域名和 IP 位址之間的對應關係，從而導致訪問失敗。但是 DDNS 系統是將用戶的動態 IP 位址映射到一個固定的域名解析服務上，用戶每次連接網絡時，客戶端程序通過信息傳遞把該主機的動態 IP 位址傳送給位於服務商主機上的服務器程序，實現動態域名解析。</p><p>DDNS 用來動態更新 DNS 服務器上域名和 IP 位址之間的對應關係，從而保證通過域名訪問到正確的 IP 位址。很多機構都提供了 DDNS 服務，在後台運行並且每隔數分鐘來檢查電腦的 IP 位址，如果 IP 發生變更，就會向 DNS 服務器發送更新 IP 位址的請求。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/0*AHNx-TlhVDJsQreW.png" /></figure><h3>組網原理</h3><p>DDNS 的典型組網環境如下圖所示，DDNS 採用 Clent-Server 模式。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*oG-A9ujQlVrZPWIb.png" /></figure><h4>DDNS 客戶端</h4><p>DDNS 客戶端需要動態更新域名和 IP 位址對應關係的設備。Internet 用戶通常通過域名訪問提供應用層服務的服務器，如 HTTP、FTP 服務器。為了保證 IP 位址變化時，仍然可以通過域名訪問這些服務器，當服務器的IP位址發生變化時，它們將作為 DDNS 客戶端，向 DDNS 服務器發送更新域名和 IP 位址對應關係的 DDNS 更新請求。</p><h4>DDNS 服務器</h4><p>DDNS 服務器負責通知 DNS 服務器動態更新域名和 IP 位址之間的對應關係。接收到 DDNS 客戶端的更新請求後，DDNS 服務器通知 DNS 服務器重新建立域名和 IP 位址之間的對應關係。從而保證即使 DDNS 客戶端的 IP 位址改變，Internet 用戶仍然可以通過同樣的域名訪問 DDNS 客戶端。</p><h4>報文交互方式</h4><p>DDNS 客戶端向 DDNS 服務器發送 TCP 連接請求，如果連接建立成功，則向 DDNS 服務器發送 DDNS 更新請求，並統計發送 DDNS 更新請求報文的次數。</p><p>DDNS 服務器收到 DDNS 客戶端發送過來的 DDNS 更新請求後，通知 DDNS 服務器進行域名更新，並且向 DDNS 客戶端發送應答報文。</p><h3>服務作用</h3><ul><li>目前 ISP 網絡運營商大多提供動態 IP，我們若想在網際網路上以自己的網域公布，DDNS 提供了解決方案，它可以自動更新用戶每次變化的浮動 IP，然後將其與網域相對應，這樣其他上網用戶就可以通過域名訪問您的路由器。</li><li>DDNS 還可以讓我們在自己的或家裡架設 Web、Mail、FTP 等伺服器，而不用花錢去付虛擬主機租金。也就是說，藉助路由器 DDNS 綁定域名，可以將我們電腦作為伺服器功能來使用，通過域名，可以讓全球其他聯網用戶，訪問我們指定的文件或者網頁程式。</li><li>主機是自己的，空間可根據自己的硬碟需求來擴充，維護也比較方便。有了域名與空間，藉助 DDNS 綁定域名就可以架設網站，FTP 伺服器、Email 伺服器都不成問題。</li><li>如果您有對 VPN 的需求，有了 DDNS 就可以用普通上網方式方便地建立 Tunnel。透過網域的方式連結，實現遠端管理、遠端存取、遠端列印等功能。</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49bff36bd27a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Good ways to return string from function in C]]></title>
            <link>https://medium.com/@goblin5417/good-ways-to-return-string-from-function-in-c-899daa60772f?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/899daa60772f</guid>
            <category><![CDATA[string]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Wed, 05 Feb 2020 09:30:18 GMT</pubDate>
            <atom:updated>2020-02-05T09:30:18.638Z</atom:updated>
            <content:encoded><![CDATA[<h3>❧ Pass size to function</h3><h4>Explanation</h4><p>User pass the size of the buffer to the function, and return an error code if the size is not enough.</p><h4>Example</h4><p><a href="https://linux.die.net/man/3/snprintf">snprintf(3) — Linux man page</a></p><pre>int snprintf(char *str, size_t size, const char *format, ...);</pre><h3>❧ Return pointer</h3><h4>Explanation</h4><p>Function allocate a block of memory. You can use alloc(), malloc(), calloc(), etc.</p><h4>Example</h4><p><a href="https://linux.die.net/man/3/strdup">strdup(3) — Linux man page</a></p><pre>char *strdup(const char *s);</pre><h3>❧ Define maximum size</h3><h4>Explanation</h4><p>Define a maximum size in library header.</p><h4>Example</h4><p>Openssl defined EVP_MAX_MD_SIZE, and user always allocate that size for buffer. When user call EVP_DigestFinal_ex(), it return actual used size. (Ref: <a href="https://www.openssl.org/docs/man1.1.0/man3/EVP_DigestFinal_ex.html">EVP_DigestFinal</a>)</p><pre>int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);</pre><h3>❧ Use the same size_t pointer for input and output</h3><h4>Explanation</h4><ul><li>User fill in the buffer size so that the function can check the valid size of the buffer.</li><li>The function will fill in the actual buffer size.</li></ul><h4>Example</h4><p>Function design: (return success or fail)</p><pre>bool function(char *output_buf, size_t *output_buf_size)</pre><p>Function use:</p><pre>char buf[20];<br>size_t buf_sz = sizeof(buf);<br>bool ret = function(buf, &amp;buf_sz);</pre><pre>if (ret) {<br>    // valid output size is in buf_sz<br>}</pre><h3>❧ Summary</h3><ul><li>With a sound function design, don’t let logic go everywhere.</li><li>Reduce the interdependence between functions, and it will be faster and have fewer side effects in maintenance and modification in response to changes.</li><li>Don’t over-design, make simple things too complicated, but reduce the ease of maintenance and corresponding changes.</li><li>Staying flexible and understanding the high-level goals of the program will be a design consideration.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=899daa60772f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[〔Clean Code〕第２章 — 有意義的命名]]></title>
            <link>https://medium.com/@goblin5417/ch2-meaningful-names-bb4ef5d2152e?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb4ef5d2152e</guid>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Thu, 19 Dec 2019 03:11:36 GMT</pubDate>
            <atom:updated>2019-12-21T15:28:09.688Z</atom:updated>
            <content:encoded><![CDATA[<h3>〔Clean Code〕第２章 — 有意義的命名</h3><h3>名副其實</h3><p>變數、函式或類別的名稱應該告訴你：</p><ul><li>它為什麼會存在</li><li>它做什麼事</li><li>應該怎麼用</li></ul><p>如果名稱還需要註解來補充，就不算名副其實。</p><pre>int d // 消逝的時間，以日計</pre><p>選擇指名<strong>計量對象</strong>和<strong>計量單位</strong>的名稱：</p><pre>int elapsedTimeInDays;<br>int daysSinceCreation;<br>int daysSinceModification;<br>int fileAgeInDays;</pre><h3>避免誤導</h3><ul><li><strong>避免使用與本意相悖詞。</strong> 別用 accountList 來指稱一組帳號，除非它真的是 List 類型。List 一詞有特殊意義。如果包納帳號的容器並非 List，就會引起錯誤的判斷。用 accountGroup、bunchOfAccount 或 accounts 都會好一些。</li><li><strong>避免使用不同之處較小的名稱。</strong> 想區分 XYZEfficientHandlingOfStrings 和 XYZEfficientStorageOfStrings 會花不少時間。</li><li><strong>避免使用小寫字母 </strong><strong>l 和大寫字母 </strong><strong>O 作為變數名。</strong> 問題在於它們看起來很像常數的「一」和「零」。</li></ul><pre>int a = l;<br>if ( O == l )<br>    a = O1;<br>else<br>    l = 01;</pre><h3>做有意義的區分</h3><ul><li><strong>以數字系列命名（</strong><strong>a1、</strong><strong>a2…</strong><strong>aN）純屬誤導</strong>，完全沒有提供正確的訊息，沒有提供作者意圖的線索。例如下面這段程式碼，如果參數名稱改為 source 和 destination 就會好很多。</li></ul><pre>public static void copyChars(char a1[], char a2[]) {<br>    for (int i = 0; i &lt; a1.length; i++) {<br>        a2[i] = a1[i]; <br>    }<br>}</pre><ul><li><strong>廢話是另一種沒意義的區分。</strong> 假設你有一個變數 Product，如果還有一個 ProductInfo 或 ProductData，它們的名稱雖然不同，意思卻無區別。</li><li><strong>廢話都是冗餘。</strong>Variable 永遠不應出現在變數名中。Table 永遠不應出現在表名中。NameString 不會比 Name 好，因為 Name 基本上會是字串。</li></ul><h3>使用讀得出來的名稱</h3><p>人類擅長記憶和使用單詞，如果名稱讀不出來，討論時就會像個傻逼。</p><p>例如：</p><pre>class DtaRcrd102 {<br>    private Date genymdhms; <br>    private Date modymdhms;<br>    private final String pszqint = &quot;102&quot;;<br>};</pre><p>改成</p><pre>class Customer {<br>    private Date generationTimestamp; <br>    private Date modificationTimestamp;<br>    private final String recordId = &quot;102&quot;;<br>};</pre><p>讀起來就比較像人話。</p><h3>使用可搜尋的名稱</h3><p>單字母名稱和數字常數有個問題，就是很難在一大篇文字中找出來。</p><p>找 MAX_CLASSES_PER_STUDENT 很容易，但想找數字 7 就麻煩了，它可能是其他常數定義的一部分，出現在不同意圖的各種表達式中。</p><p>例如：</p><pre>for (int j=0; j&lt;34; j++) {<br>    s += (t[j]*4)/5;<br>}</pre><p>改成</p><pre>int NUMBER_OF_TASKS = 34;<br>int realDaysPerIdealDay = 4;<br>const int WORK_DAYS_PER_WEEK = 5;<br>int sum = 0;<br>for (int j=0; j &lt; NUMBER_OF_TASKS; j++) {<br>    int realTaskDays = taskEstimate[j] * realDaysPerIdealDay;<br>    int realTaskWeeks = (realdays / WORK_DAYS_PER_WEEK);<br>    sum += realTaskWeeks;<br>}</pre><p>這些變數都變得比較容易搜尋。</p><h3>避免使用編碼</h3><ul><li><strong>不需要使用類型編碼。</strong> IDE 已經可以在編譯開始前偵測到類型錯誤。所以類型編碼純屬多餘，它們增加了修改變數名稱的難度，增加了閱讀程式碼的難度。</li></ul><pre>PhoneNumber phoneString; // 型態變化時，名稱並不變化！</pre><ul><li><strong>不必使用成員前綴。</strong> 應該把類別和函式做得足夠小，消除對成員前綴的需要。</li></ul><pre>public class Part { <br>    private String m_dsc; // The textual description<br>        void setName(String name) {<br>        m_dsc = name;<br>    }<br>}<br>_________________________________________________</pre><pre>public class Part { <br>    String description;<br>        void setDescription(String description) { <br>        this.description = description;<br>    }<br>}</pre><ul><li><strong>使用不加修飾的介面。</strong> 你如何命名工廠和具體型態呢？IShapeFactory 和 ShapeFactory？前導字母 I 根本是廢話，我不想給用戶知道我給他們的是介面。如果介面和實作必須選一個來編碼，寧可選實作 ShapeFactoryImp。</li></ul><h3>避免思維映射</h3><p>迴圈計數器傳統上被命名為 i、j 或 k，但多數情況下，單字母名稱不是個好選擇。讀者必須在腦中將它映射為真實概念。</p><h3>類別名</h3><ul><li>類別名和物件名應該是名詞或名詞短語，例如 Customer、WikiPage、Account 和 AddressParser。</li><li>避免使用 Manager、Processor、Data 或 Info 這樣的類別名。</li><li>類別名不應該是動詞。</li></ul><h3>方法名</h3><ul><li>方法名應該是動詞或動詞短語，例如 postPayment、deletePage 和 save。</li><li>屬性訪問器、修改器和斷言應該根據其值命名，加上 get、set 和 is 前綴。</li></ul><pre>string name = employee.getName();<br>customer.setName(&quot;mike&quot;);<br>if (paycheck.isPosted()) {<br>    ...<br>}</pre><h3>別扮可愛</h3><p>扮可愛的作法在程式碼中經常體現為使用俗語或俚語。例如：別用 whack() 來表示 kill()。</p><h3>每個概念對應一個詞</h3><p>給每個抽象概念選一個詞。例如，使用 fetch、retrieve 和 get 來給在多個類別中的同種方法命名。</p><h3>別用雙關語</h3><p>避免將同一單詞用於不同目的。同一術語用於不同概念，基本上就是雙關語了。</p><h3>使用解決方案領域名稱</h3><p>記住，只有程式設計師才會讀你的程式碼。所以盡管用那些計算機科學術語、演算法名、模式名、數學術語吧。</p><h3>使用源自所涉問題領域的名稱</h3><p>如果不能用程式設計師熟悉的術語命名，就用所涉問題領域的名稱吧。</p><p>優秀的程式設計師，其工作之一就是分離解決方案領域和問題領域的概念。</p><h3>添加有意義的語境</h3><p>假設你有名為 firstName、lastName、street、houseNumber、city、state 和 zipcode 的變數。當它們放在一起，很明確構成一個地址。但如果在某個方法中看見孤單一個變數 state，就無法推斷那是某個地址的一部分。可添加前綴 addrFirstName、addrLastName、addrState 等，以此提供語境。</p><h3>不要添加沒用的語境</h3><ul><li>假設有一個名為「加油站豪華版」（Gas Station Deluxe）的應用，在其中每個類別添加 GSD 前綴就不好。</li><li>只要短名稱足夠清楚，就要比長名稱好。</li></ul><h3>結語</h3><p>取好名字最難的地方在於需要良好的描述技巧和共有文化背景。</p><p>我們有時會怕其他開發者反對重命名。如果名稱改得更好，那大家真的會感激你。多數時候我們並不記憶類別名和方法名。我們使用現代工具對付這些細節，好讓自己集中精力於把程式碼寫得像詞句篇章、至少像是表和資料結構。</p><h3>♚ 系列文目錄</h3><p><a href="https://medium.com/@goblin5417/clean-co-89f01437492b">Clean Code 摘要系列</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb4ef5d2152e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[〔Clean Code〕第１章 — 無瑕的程式碼]]></title>
            <link>https://medium.com/@goblin5417/ch1-clean-code-cf037287a032?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf037287a032</guid>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Fri, 13 Dec 2019 04:42:17 GMT</pubDate>
            <atom:updated>2019-12-19T03:32:56.842Z</atom:updated>
            <content:encoded><![CDATA[<h3>〔Clean Code〕第１章 - 無瑕的程式碼</h3><h3>糟糕的程式</h3><p>20 世紀 80 年代末，有間公司寫了個很流行的殺手應用，許多專業人士都買來用。後來，發布週期開始拉長。缺陷總是不能修復。安裝時間越來越久，崩潰的機率也越來越大。在那不久後，該公司就倒閉了。</p><p>20 年後，那間公司的一位早期員工說了當年發生什麼事。當時他們趕著推出產品，程式碼寫得亂七八糟。功能越加越多，程式碼也越來越爛，最後再也無法管理這些程式碼。<strong>是糟糕的程式碼毀掉這間公司。</strong></p><h3>混亂的代價</h3><p>有些團隊在項目初期發展迅速，但到後面卻越來越慢。程式碼的每次修改都影響到其他兩三處程式碼。隨著混亂的增加，團隊生產力也持續下降，趨向於零。</p><h3>什麼是無瑕的程式碼</h3><ul><li>程式碼邏輯直截了當，充滿乾淨俐落的抽象和直截了當的控制語句，讓缺陷難以隱藏。</li><li>盡量少的相依關係，明確定義和提供清晰、盡量少的 API。</li><li>沒有重複的程式碼。</li><li>依據某種分層戰略完善錯誤處理程式碼。</li><li>效能調至最優，省得引誘別人做沒規矩的優化，搞出一堆混亂來。</li><li>只做好一件事。</li><li>提供單元測試和驗收測試。</li></ul><h3>小結</h3><p>本書不保證讓你成為好的程式設計師。它所能做的，只是展示好的程式思維過程，還有他們使用的技巧、技術和工具。</p><h3>♚ 系列文目錄</h3><p><a href="https://medium.com/@goblin5417/clean-co-89f01437492b">Clean Code 摘要系列</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf037287a032" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Code 摘要系列]]></title>
            <link>https://medium.com/@goblin5417/clean-co-89f01437492b?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/89f01437492b</guid>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Fri, 13 Dec 2019 04:36:44 GMT</pubDate>
            <atom:updated>2019-12-19T03:21:30.033Z</atom:updated>
            <content:encoded><![CDATA[<ul><li><a href="https://medium.com/@goblin5417/ch1-clean-code-cf037287a032">〔Clean Code〕第１章 — 無瑕的程式碼</a></li><li><a href="https://medium.com/@goblin5417/ch2-meaningful-names-bb4ef5d2152e">〔Clean Code〕第２章 — 有意義的命名</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89f01437492b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[〔Coding style〕Reasons to add the curly brackets behind if / for / while in C/C++]]></title>
            <link>https://medium.com/@goblin5417/coding-style-reasons-to-increase-the-brackets-behind-if-for-while-617e6665ca97?source=rss-df6e201c11b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/617e6665ca97</guid>
            <category><![CDATA[if]]></category>
            <category><![CDATA[brackets]]></category>
            <category><![CDATA[coding-style]]></category>
            <category><![CDATA[c]]></category>
            <dc:creator><![CDATA[Lynx Chang]]></dc:creator>
            <pubDate>Sat, 05 Oct 2019 09:39:44 GMT</pubDate>
            <atom:updated>2023-02-23T07:27:19.682Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*-QD66LrLqRwGwX3lS38HJg.jpeg" /></figure><p>When using the if, for, or while statements, it is important to include curly brackets even when there is only one line of code. This simple rule can greatly enhance the readability and structure of your code. Here are several reasons why:</p><h3>Reason 1: Multi-line macro</h3><p>Consider the following code:</p><pre>if (condition)<br>    DO_SOMETHING;</pre><p>At first glance, it seems fine. However, if DO_SOMETHING itself is a macro and the person who defined the macro did not wrap the whole paragraph with curly brackets, it could cause a logic error. For example:</p><pre>#define DO_SOMETHING int n=0\<br>                     printf(&quot;%d&quot;, n);</pre><p>Including curly brackets in the if statement ensures that the entire macro is executed when the condition is true.</p><h3>Reason 2: Changes on Git</h3><p>Suppose you want to change the code during a code review. For instance, you might change this:</p><pre>if (a &gt; 0) a += b;</pre><p>to this:</p><pre>if (a &gt; 0) {<br>    a += b;<br>    c++;<br>}</pre><p>Your change is a simple addition of a single line of code, but for Git, it registers as a modification of four lines, including the line that the if condition evaluates. Without curly brackets, the reviewer must confirm that the condition in the if statement is consistent with the original code.</p><h3>Reason 3: Consistency</h3><p>Using curly brackets for all if statements ensures consistency in your code style. You don&#39;t have to remember which statements require curly brackets and which do not. This keeps your code looking consistent and reduces unnecessary mental strain.</p><h3>Reason 4: Readability</h3><p>The inclusion of curly brackets makes the boundaries of the code clear, reducing eye strain and improving code readability.</p><h3>Conclusion</h3><p>It is best practice to always use curly brackets when using if, for, or while statements, regardless of the number of lines of code involved. Doing so will help you avoid logic errors, facilitate code reviews, maintain consistency, and enhance the readability of your code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=617e6665ca97" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>