<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>好文記錄與分享 &#8211; Larry的午茶時光</title>
	<atom:link href="https://blog.yuyansoftware.com.tw/category/good-article-sharing/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.yuyansoftware.com.tw</link>
	<description></description>
	<lastBuildDate>Sun, 14 Jun 2026 06:20:35 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://blog.yuyansoftware.com.tw/wp-content/uploads/2022/10/favicon-45x45.png</url>
	<title>好文記錄與分享 &#8211; Larry的午茶時光</title>
	<link>https://blog.yuyansoftware.com.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MySQL Key 與 Index 的差異？Primary 與 Unique key 的差異？Unique key 能否為 null？</title>
		<link>https://blog.yuyansoftware.com.tw/2018/10/mysql-key-index/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Mon, 15 Oct 2018 03:44:00 +0000</pubDate>
				<category><![CDATA[好文記錄與分享]]></category>
		<category><![CDATA[軟體開發隨筆]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Key 與 index 的差異？Key 包含了兩個功能 1. 約束 (constraint) 2. 索引 (index), 也就是 key 功能上包含了 index. 以 Primary key 來說，他的特性是 1. Unique constraint. 2. Each table can only have one Primary key. 3. Cannot be null.]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">圖片來源 <a href="https://zh.wikipedia.org/wiki/MySQL" target="_blank" rel="noreferrer noopener nofollow">https://zh.wikipedia.org/wiki/MySQL</a></p>



<p class="wp-block-paragraph">之前看到一篇關於 MySQL index / key 的文章，以中文 MySQL 文章來說，larry 覺得寫得滿好的，分享給大家<br><a href="https://blog.csdn.net/nanaMasuda/article/details/52543177" target="_blank" rel="noreferrer noopener nofollow">https://blog.csdn.net/nanaMasuda/article/details/52543177</a><br>(文章內的「索引」就是 index)</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">&#8220;索引被用來快速找出在一個列上用一特定值的行。沒有索引，MySQL不得不首先以第一條記錄開始並然後讀完整個表直到它找出相關的行。&#8221;</p>
</blockquote>



<p class="wp-block-paragraph">文章第一句就點出 index 的主要功能：快速檢索。為啥可以快速檢索？因為 MySQL index 會建一物理結構 BTree 加快檢索，也可以想成是用空間換取速度。</p>



<h2 class="wp-block-heading">Key 與 Index 的差異？</h2>



<h3 class="wp-block-heading">Key 包含了兩個功能</h3>



<ol class="wp-block-list">
<li>約束 (constraint)，包含本文下方提到的 Unique constraint.</li>



<li>索引 (index)，也就是 key 功能上包含了 index.</li>
</ol>



<h2 class="wp-block-heading">Primary 與 Unique key 的差異？</h2>



<h3 class="wp-block-heading">Primary key 的特性是</h3>



<ol class="wp-block-list">
<li>Unique constraint.</li>



<li>Each table can only have one Primary key.</li>



<li>Cannot be null. </li>
</ol>



<h3 class="wp-block-heading">Unique key 的特性是</h3>



<ol class="wp-block-list">
<li>Unique constraint.</li>



<li>Each table can have multiple Unique&nbsp;keys.</li>



<li>Can be null. </li>
</ol>



<p class="wp-block-paragraph">當然，請記得所有的 key 都包含 index 的功能。</p>



<h2 class="wp-block-heading">Unique key 能否為 null？</h2>



<p class="wp-block-paragraph">larry 有做一些實驗跟查找文章<br><a href="http://www.mysqltutorial.org/mysql-unique/" target="_blank" rel="noreferrer noopener nofollow">http://www.mysqltutorial.org/mysql-unique/</a></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">&#8220;Unlike other database systems, MySQL considers NULL values as distinct values. Therefore, you can have multiple NULL values in the UNIQUE index.<br><br>This is how MySQL was designed. It is not a bug even though it was reported as a bug.&#8221;</p>
</blockquote>



<p class="wp-block-paragraph">所以以 MySQL 來說，Unique key 是可以為 null 的。</p>



<p class="wp-block-paragraph">相關文章：<a href="https://blog.yuyansoftware.com.tw/2015/12/mysql-server-mac/">MySQL server 在 Mac 上關不掉的問題</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[好文分享] Create a Custom Theme With OpenCart</title>
		<link>https://blog.yuyansoftware.com.tw/2017/05/create-custom-theme-with-opencart/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Mon, 29 May 2017 08:30:00 +0000</pubDate>
				<category><![CDATA[OpenCart]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[好文記錄與分享]]></category>
		<guid isPermaLink="false">http://test234.yuyansoftware.com.tw/2017/05/29/%e5%a5%bd%e6%96%87%e5%88%86%e4%ba%ab-create-a-custom-theme-with-opencart/</guid>

					<description><![CDATA[可以看到 admin 底下沒有多墊 theme/default 這兩層。就這架構來看 catalog 是可以容納更多 theme 的前端檔案，如果你有裝其他 theme 的話，theme 資料夾底下除了 default, 還會有你裝的其他的 theme.]]></description>
										<content:encoded><![CDATA[<p><span style="color: #444444; font-size: large;"><b>Introduction</b></span><br />
<a href="https://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-introduction--cms-21786" target="_blank" rel="noopener noreferrer"><span style="font-size: large;">https://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-introduction&#8211;cms-21786</span></a><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">(以下測試是依照最新版 OpenCart 2.3.0.2)</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">* 檔案結構上 view 底下是 theme 和 javascript. css, 圖, 和 html (tpl) 是放在 theme 底下。有點特殊的是 javascript 是獨立一個資料夾。</span><span style="font-size: large;">但是 admin 的 view 又不同：</span><br />
<span style="font-size: large;">catalog</span><br />
<span style="font-size: large;">&nbsp; &#8211; view</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &#8211; javascript</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &nbsp; &#8211; bootstrap</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &nbsp; &#8211; font-awesome</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &nbsp; &#8211; &#8230;.</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &#8211; theme</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &nbsp; &#8211; default</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &nbsp; &nbsp; &#8211; image</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &nbsp; &nbsp; &#8211; stylesheet</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &nbsp; &nbsp; &#8211; template</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">admin</span><br />
<span style="font-size: large;">&nbsp; &#8211; view</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &#8211; image</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &#8211; javascript</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &#8211; stylesheets</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &#8211; template</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">可以看到 admin 底下沒有多墊 theme/default 這兩層。就這架構來看 catalog 是可以容納更多 theme 的前端檔案，如果你有裝其他 theme 的話，theme 資料夾底下除了 default, 還會有你裝的其他的 theme.</span></p>
<p><a name="more"></a><span style="font-size: large;">* catalog/view/theme/default/template 底下的架構：</span><br />
<span style="font-size: large;">&#8211; common: 所有頁面的共用元件放在這邊, 例如 header.tpl, footer.tpl.</span><br />
<span style="font-size: large;">&#8211; error</span><br />
<span style="font-size: large;">&#8211; information</span><br />
<span style="font-size: large;">&#8211; module (OpenCart 2.3 是在&nbsp;</span><span style="font-size: large;">template/extension/module)</span><br />
<span style="font-size: large;"><br />
</span><span style="color: #444444; font-size: large;"><b>Part Two</b></span><br />
<a href="https://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-two--cms-21865" target="_blank" rel="noopener noreferrer"><span style="font-size: large;">https://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-two&#8211;cms-21865</span></a><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">作者提到, 不管是新做前端介面或是更改預設介面, 都應該新增一個 theme</span><br />
<span style="font-size: large;">「In either case, I recommend creating a new custom theme instead of modifying the default theme files directly as it&#39;ll make the life easier during the version upgrade of the OpenCart.」</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">OpenCart 2.3 新增 theme 有點複雜 (與上面文章敘述不同), 請參考這篇文章</span><br />
<a href="http://undefined.gr/site/2016/10/09/custom-opencart-2-3-0-2-theme/" target="_blank" rel="noopener noreferrer"><span style="font-size: large;">http://undefined.gr/site/2016/10/09/custom-opencart-2-3-0-2-theme/</span></a><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">1. 新增 catalog/view/theme/mytheme,</span><br />
<span style="font-size: large;">2. 新增 admin/controller/extension/theme/mytheme.php, 記得改 class name&nbsp;ControllerExtensionThemeMyTheme (這很重要)。取代 mytheme.php 裡的 &#8220;theme_default&#8221; 字串成 &#8220;mytheme&#8221;.</span><br />
<span style="font-size: large;">3. 新增&nbsp;admin/view/template/extension/theme/mytheme.tpl, 一樣取代 mytheme.tpl 裡的 &#8220;theme_default&#8221; 字串成 &#8220;mytheme&#8221;.</span><br />
<span style="font-size: large;">4. 新增 admin/language/en-gb/extension/theme/mytheme.php, 更改裡面的 $_[&#8216;heading_title&#8217;]&nbsp;成 &#8220;My Theme&#8221;.</span><br />
<span style="font-size: large;">5. 新增 catalog/view/theme/mytheme/image/mytheme.png</span><br />
<span style="font-size: large;">6. 到你的後台 Extensions -&gt; Extensions, 選擇 Theme, 應該會看到 &#8220;My Theme&#8221;, 點安裝，安裝完後編輯 &#8220;My Theme&#8221; 成 Enable, 資料夾指向 mytheme.</span><br />
<span style="font-size: large;">7. 到 System -&gt; Settings 就可以選擇你商店的 template 了。</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">回到 tutsplus 這篇文章, 將</span><br />
<span style="font-size: large;">catalog/view/theme/mycustomtheme/template/common/header.tpl 中的</span><br />
<span style="font-size: large;">&lt;link href=&#8221;catalog/view/theme/default/stylesheet/stylesheet.css&#8221; rel=&#8221;stylesheet&#8221;&gt;</span><br />
<span style="font-size: large;">改成</span><br />
<span style="font-size: large;">&lt;link href=&#8221;catalog/view/theme/mycustomtheme/stylesheet/stylesheet.css&#8221; rel=&#8221;stylesheet&#8221;&gt;</span><br />
<span style="font-size: large;"><br />
</span><span style="color: #444444; font-size: large;"><b>Part Three</b></span><br />
<a href="https://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-three--cms-21890" target="_blank" rel="noopener noreferrer"><span style="font-size: large;">https://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-three&#8211;cms-21890</span></a><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">OpenCart 的切版是</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Content Top &nbsp; &nbsp; &nbsp;</span><br />
<span style="font-size: large;">Column Left &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Column Right</span><br />
<span style="font-size: large;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Content Bottom</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">程式端可以看 template/common/home.tpl, 就可以清楚的看出來 layout. 後台可以看 Design -&gt; Layouts, 裡面的 layout 設定也是依循 Column Left/Right, Content Top/Bottom, 其中的 $modules (例如在 content_top.tpl 裡面), 就是在 Design -&gt; Layouts 裡設定。</span><br />
<span style="font-size: large;"><br />
</span><span style="color: #444444; font-size: large;"><b>Part Four</b></span><br />
<a href="https://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-four--cms-21932" target="_blank" rel="noopener noreferrer"><span style="font-size: large;">https://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-four&#8211;cms-21932</span></a><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">模組 assign 的方式 OpenCart 2.3 與這篇文章敘述的不同。以 2.3 來說，到 Extensions -&gt; Extensions, 選擇 Modules, 底下會列出所有已安裝的 module, 找到一個 module (例如 Slideshow), 點右邊 + 號，</span><span style="font-size: large;">可以生成一個實體。回到 Design -&gt; Layouts, 選擇一個頁面進入，就可以新增 Column Left/Right, Content Top/Bottom 模組實體。</span></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[好文分享] Why was 80 chosen as the default HTTP port and 443 as the default HTTPS port?</title>
		<link>https://blog.yuyansoftware.com.tw/2016/11/why-was-80-chosen-as-default-http-port/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Mon, 28 Nov 2016 05:53:00 +0000</pubDate>
				<category><![CDATA[好文記錄與分享]]></category>
		<category><![CDATA[網路科技]]></category>
		<guid isPermaLink="false">http://test234.yuyansoftware.com.tw/2016/11/28/%e5%a5%bd%e6%96%87%e5%88%86%e4%ba%ab-why-was-80-chosen-as-the-default-http-port-and-443-as-the-default-https-port/</guid>

					<description><![CDATA[title 這個問題我有疑問一段時間了，偶然找到這個網頁，回答得很好，分享給大家參考： http://www. &#8230; ]]></description>
										<content:encoded><![CDATA[<p><span style="font-size: large;">title 這個問題我有疑問一段時間了，偶然找到這個網頁，回答得很好，分享給大家參考：</span><br />
<a href="http://www.howtogeek.com/233383/why-was-80-chosen-as-the-default-http-port-and-443-as-the-default-https-port/" target="_blank" rel="noopener noreferrer"><span style="font-size: large;">http://www.howtogeek.com/233383/why-was-80-chosen-as-the-default-http-port-and-443-as-the-default-https-port/</span></a></p>
<blockquote style="background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); clear: both; font-family: monospace; font-size: 14.82px; line-height: 1.1em; margin: 0px 0px 10px; max-width: 618px; overflow-x: auto; padding: 10px;">
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; padding: 0px;">The Internet Assigned Numbers Authority (IANA) is a department of ICANN, a non-profit private corporation that oversees global IP address allocation, the Domain Name System (DNS), well-known ports, and other Internet Protocol-related symbols and numbers.</div>
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">During March of 1990, they published a document (<a href="https://tools.ietf.org/html/rfc1060" style="color: #114491;" target="_blank" rel="noopener noreferrer">RFC 1060</a>) where they listed all the well-known ports at that time. In that list there was no protocol assigned to port 80 (it jumped from 79 to 81):</div>
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; margin-top: 10px; padding: 0px;"><img decoding="async" alt="why-was-80-chosen-as-default-http-port-and-443-as-default-https-port-01" class="alignnone size-full wp-image-233388" src="http://www.howtogeek.com/wp-content/uploads/2015/11/625x56xwhy-was-80-chosen-as-default-http-port-and-443-as-default-https-port-01.jpg.pagespeed.gp+jp+jw+pj+js+rj+rp+rw+ri+cp+md.ic.I6RDcM0yxZ.jpg" height="56" style="border: 0px; margin-left: -2px;" width="625"></div>
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">At that time, port 80 was officially free. In 1991, Tim Berners-Lee issued the first version of HTTP in a document (<a href="http://www.w3.org/Protocols/HTTP/AsImplemented.html" style="color: #114491;" target="_blank" rel="noopener noreferrer">HTTP 0.9</a>) where he stated:</div>
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; margin-top: 10px; padding: 0px;"><img decoding="async" alt="why-was-80-chosen-as-default-http-port-and-443-as-default-https-port-02" class="alignnone size-full wp-image-233387" src="http://www.howtogeek.com/wp-content/uploads/2015/11/625x36xwhy-was-80-chosen-as-default-http-port-and-443-as-default-https-port-02.jpg.pagespeed.gp+jp+jw+pj+js+rj+rp+rw+ri+cp+md.ic.tJS2mZctIB.jpg" height="36" style="border: 0px; margin-left: -2px;" width="625"></div>
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">Then in July of 1992, RFC1060 was made obsolete by a new document (<a href="https://tools.ietf.org/html/rfc1340" style="color: #114491;" target="_blank" rel="noopener noreferrer">RFC 1340</a>) where the following appeared:</div>
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; margin-top: 10px; padding: 0px;"><img fetchpriority="high" decoding="async" alt="why-was-80-chosen-as-default-http-port-and-443-as-default-https-port-03" class="alignnone size-full wp-image-233386" src="http://www.howtogeek.com/wp-content/uploads/2015/11/625x99xwhy-was-80-chosen-as-default-http-port-and-443-as-default-https-port-03.jpg.pagespeed.gp+jp+jw+pj+js+rj+rp+rw+ri+cp+md.ic.gxJ6kWuzo-.jpg" height="99" style="border: 0px; margin-left: -2px;" width="625"></div>
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">That document made 80 the official port for HTTP (www). However there is nothing about port 443 in that document. During October of 1994,&nbsp;<a href="https://tools.ietf.org/html/rfc1700" style="color: #114491;" target="_blank" rel="noopener noreferrer">RFC 1700</a>&nbsp;was published and this appeared for the first time:</div>
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; margin-top: 10px; padding: 0px;"><img loading="lazy" decoding="async" alt="why-was-80-chosen-as-default-http-port-and-443-as-default-https-port-04" class="alignnone size-full wp-image-233385" src="http://www.howtogeek.com/wp-content/uploads/2015/11/625x77xwhy-was-80-chosen-as-default-http-port-and-443-as-default-https-port-04.jpg.pagespeed.gp+jp+jw+pj+js+rj+rp+rw+ri+cp+md.ic.8kAz2E48kZ.jpg" height="77" style="border: 0px; margin-left: -2px;" width="625"></div>
<div style="color: #222222; line-height: 21px; margin-bottom: 10px; margin-top: 10px; padding: 0px;">It seems it was solicited by&nbsp;<a href="http://home.mcom.com/people/kipp/" style="color: #114491;" target="_blank" rel="noopener noreferrer">Kipp E.B. Hickman</a>, who at the time worked at Mosaic, the first GUI browser company that later went on to become Netscape. It is not clear why port 443 was chosen. However, the previous RFC document had a gap from 374 through 512, but in RFC1700 the space from 375 to 451 was filled. It is most likely that the numbers were simply given in order of request.</div>
</blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[好文分享] 5 Surprises for PHP Developers Coming to JavaScript</title>
		<link>https://blog.yuyansoftware.com.tw/2016/06/5-surprises-for-php-developers-to-js/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Sun, 12 Jun 2016 12:09:00 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[好文記錄與分享]]></category>
		<category><![CDATA[Link4]]></category>
		<guid isPermaLink="false">http://test234.yuyansoftware.com.tw/2016/06/12/%e5%a5%bd%e6%96%87%e5%88%86%e4%ba%ab-5-surprises-for-php-developers-coming-to-javascript/</guid>

					<description><![CDATA[http://radar.oreilly.com/2013/06/5-surprises-for-php-de &#8230; ]]></description>
										<content:encoded><![CDATA[<div><a href="http://radar.oreilly.com/2013/06/5-surprises-for-php-developers-coming-to-javascript.html" target="_blank" rel="noopener noreferrer"><span style="font-size: large;">http://radar.oreilly.com/2013/06/5-surprises-for-php-developers-coming-to-javascript.html</span></a></div>
<div><span style="font-size: large;"><br />
</span></div>
<p><span style="font-size: large;">1. Functions are objects</span></p>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">* function 是一種 object, 所以它也有 built-in property 或是動態設定 property.</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">* function 可以當 input argument, 也可以當 return variable.</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">2. Function scope</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">* nested function 子層級的 function 可以看到父層級 function 的 variable, PHP 不行，PHP 下層 scope 也看不到 global variable, 除非用 global keyword.</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">3. Hoisting</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">* 變數或 function 宣告都自動提升到該 scope 的上方。注意提升到上方的變數初始為 undefined, 所以如果不是一開始就初始的變數，在初始之前是 undefined.</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">* 一般 function 宣告會 hoisting，但如果是 assign function as a variable, 一樣，該 variable 會 hoisting 到上方初始為 undefined.</span></div>
<div><span style="font-size: large;"></span><br />
<a name="more"></a><span style="font-size: large;">4. No classes</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">* 這是 JS 和一般 OO 語言最大的不同之一，沒有 class，而且 object 可以動態新增 property.</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">5. Constructors and prototypes</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">* JS 的 constructor 是 &#8220;constructor function&#8221;, PHP 是 (double underscore)</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div>
<div><span style="font-size: large;">function __construct() {</span></div>
<div><span style="font-size: large;">&nbsp; &nbsp; &nbsp;&nbsp;</span></div>
<div><span style="font-size: large;">}</span></div>
</div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">* JS 的繼承實作</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div>
<div><span style="font-size: large;">function Animal() {</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">}</span></div>
<div><span style="font-size: large;">&nbsp;&nbsp;</span></div>
<div><span style="font-size: large;">function Dog() {</span></div>
<div><span style="font-size: large;"><br />
</span></div>
<div><span style="font-size: large;">}</span></div>
<div><span style="font-size: large;">&nbsp;&nbsp;</span></div>
<div><span style="font-size: large;">Dog.prototype = new Animal();</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">注意子類別新的 property 不會出現在 prototype 裡 (ex: Dog.prototype)。另外子類別可以複寫父類別的 property (constructing 順序的問題)。</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">* JS&nbsp;ECMAScript 6 有導入 class, constructor, extends 等 keyword.</span></p>
</div>
</div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Swift (3): about Optional</title>
		<link>https://blog.yuyansoftware.com.tw/2015/11/swift-optional/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Sun, 01 Nov 2015 03:26:00 +0000</pubDate>
				<category><![CDATA[好文記錄與分享]]></category>
		<category><![CDATA[軟體開發隨筆]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">http://test234.yuyansoftware.com.tw/2015/11/01/swift-3-about-optional/</guid>

					<description><![CDATA[Marin Todorov&#39;s article:&#160;Swift Optionals: When &#8230; ]]></description>
										<content:encoded><![CDATA[<p><span style="font-size: large;">Marin Todorov&#39;s article:&nbsp;Swift Optionals: When to use if let, when ? and !, when as? and as</span><br />
<a href="http://www.touch-code-magazine.com/swift-optionals-use-let/" target="_blank" rel="noopener noreferrer"><span style="font-size: large;">http://www.touch-code-magazine.com/swift-optionals-use-let/</span></a><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;"><b>The &#8220;class?property&#8221; Syntax</b></span></p>
<pre>controller.navigationController?.pushViewController(myViewController, animated: true)<span style="font-size: large;">
</span></pre>
<p><span style="font-size: large;">如果 controller.navigationController 不為 nil, 執行 function. 如果 controller.navigationController 為 nil, 整行程式碼不執行。他可以替換成：</span></p>
<pre>if controller.navigationController != nil {
    controller.navigationController.pushViewController(myViewController, animated: true)
}</pre>
<p><span style="font-size: large;"><br />
</span><span style="font-size: large;"><b>The &#8220;if let&#8221; Syntax  </b></span></p>
<pre>if let nav = controller.navigationController {
    nav.pushViewController(myViewController, animated: true)
} else {
    //show an alert ot something else
}</pre>
<p><span style="font-size: large;">&#8220;if let&#8221; 的語法隱含了 &#8220;and if nav != nil&#8221;. 當你有多行程式碼需要 unwrap, use &#8220;if let&#8221;.</span></p>
<p><span style="font-size: large;"><b>The &#8220;as?&#8221; Syntax </b></span></p>
<pre>let myVC = controller.presentedViewController as? MyViewController
myVC?.lastUpdated = NSDate()<span style="font-size: large;">
</span></pre>
<p><span style="font-size: large;">&#8220;as?&#8221; 有點像 C++ 的 dynamic cast, 以上面例子來說，myVC 有可能是 nil. 正因如此，&#8221;as?&#8221; 底下通常要接 &#8220;class?property&#8221;. 另外如果用 &#8220;as&#8221; 而不是 &#8220;as?&#8221; (沒有問號)，則是 C++ 的 static cast，上面文章連結也有提到你要 101% 確定可以 cast 才用 &#8220;as&#8221; 去 cast. </span></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[好文分享] JavaScript Concurrency model and Event Loop</title>
		<link>https://blog.yuyansoftware.com.tw/2015/01/javascript-concurrency-model-and-event/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Tue, 27 Jan 2015 13:09:00 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[好文記錄與分享]]></category>
		<guid isPermaLink="false">http://test234.yuyansoftware.com.tw/2015/01/27/%e5%a5%bd%e6%96%87%e5%88%86%e4%ba%ab-javascript-concurrency-model-and-event-loop/</guid>

					<description><![CDATA[https://developer.mozilla.org/en-US/docs/Web/JavaScript &#8230; ]]></description>
										<content:encoded><![CDATA[<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop"><span style="font-size: large;">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop</span></a><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">JavaScript 是 event driven 的, 在當下 event handler (包含他所有 call stack) 結束之前, 是不會被 interrupt 的. 如果當下 event handler 在執行中又有其他 event, 則 queue 起來再處理. By this model, JavaScript 在撰寫時有幾點要注意:</span><br />
<span style="font-size: large;"><br />
</span><span style="font-size: large;">1. As the link says &#8220;A good practice to follow is to make message processing short and if possible cut down one message into several messages.&#8221;</span><br />
<span style="font-size: large;">2. 避免 recursive function calls, 即使有的話也要特別注意.</span><br />
<span style="font-size: large;">3. 真的要開 thread 就要用 web workers. 他 postMessage 一樣加到 message queue 等待執行.</span><br />
<span style="font-size: large;">4. Ajax XHR 的&nbsp;onreadystatechange event 一樣是加到 message queue 等待執行.</span></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[好文分享] 加速網站的最佳實踐 Best Practices for Speeding Up Your Web Site</title>
		<link>https://blog.yuyansoftware.com.tw/2015/01/best-practices-for-speeding-up-your-web/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Sun, 18 Jan 2015 14:45:00 +0000</pubDate>
				<category><![CDATA[好文記錄與分享]]></category>
		<category><![CDATA[網路科技]]></category>
		<guid isPermaLink="false">http://test234.yuyansoftware.com.tw/2015/01/18/%e5%a5%bd%e6%96%87%e5%88%86%e4%ba%ab-best-practices-for-speeding-up-your-web-site/</guid>

					<description><![CDATA[Yahoo Developer 關於加速網站的好文https://developer.yahoo.com/pe &#8230; ]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Yahoo Developer 關於加速網站的好文<br><a href="https://developer.yahoo.com/performance/rules.html" target="_blank" rel="noreferrer noopener">https://developer.yahoo.com/performance/rules.html</a></p>



<p class="wp-block-paragraph">1. Reduce http requests: using CSS sprites is a good example.</p>



<p class="wp-block-paragraph">2. Static cache expiration: set the expiration to never or long time.</p>



<p class="wp-block-paragraph">3. Gzip components.</p>



<p class="wp-block-paragraph">4. Put stylesheets at the top: for progressive rendering.</p>



<p class="wp-block-paragraph">5. Put scripts at the bottom: avoid downloading 2 or more components in parallel (don&#39;t let downloading javascript block downloading html and assets.)</p>



<p class="wp-block-paragraph">6. Make JavaScript and CSS external: then they can be cached in the client. But note the JS with template language still stays in html.</p>



<p class="wp-block-paragraph">7. Minify JavaScript and CSS.</p>



<p class="wp-block-paragraph">8. Remove duplicate scripts: review if your html contains duplicate scripts.</p>



<p class="wp-block-paragraph">9. Make Ajax cacheable: need a timestamp to judge if really need to submit a request.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[好文分享] The Basics of Web Workers</title>
		<link>https://blog.yuyansoftware.com.tw/2014/12/basics-of-web-workers/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Sat, 06 Dec 2014 09:22:00 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[好文記錄與分享]]></category>
		<guid isPermaLink="false">http://test234.yuyansoftware.com.tw/2014/12/06/%e5%a5%bd%e6%96%87%e5%88%86%e4%ba%ab-the-basics-of-web-workers/</guid>

					<description><![CDATA[http://www.html5rocks.com/en/tutorials/workers/basics/  &#8230; ]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><a href="http://www.html5rocks.com/en/tutorials/workers/basics/" target="_blank" rel="noreferrer noopener">http://www.html5rocks.com/en/tutorials/workers/basics/</a></p>



<p class="wp-block-paragraph">HTML 5 新的規格: Web Workers<br><a rel="noreferrer noopener" href="https://html.spec.whatwg.org/multipage/workers.html#workers" target="_blank">https://html.spec.whatwg.org/multipage/workers.html#workers</a></p>



<p class="wp-block-paragraph">在此技術之前 JavaScript 是單執行緒的，所以如果在 client 端做 computationally intensive 的工作 (ex: image processing)，通常頁面會 hang 住，再點頁面就會跳 warning dialog 之類。</p>



<p class="wp-block-paragraph">Web Worker 的開啟相當簡單，在 caller side 下：</p>



<pre class="wp-block-code"><code>var worker = new Worker('task.js');
worker.postMessage(); // Start the worker.</code></pre>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">postMessage</mark></code> 是 main thread 與 worker thread 溝通的方法 (當然兩端都要註冊 message handler)。另外上面連結還有提到：</p>



<p class="wp-block-paragraph"><strong>1. Transferrable objects</strong>：C / C++ pass by reference 的概念。只要用 Transferrable Objects 規範內的 data type，搭配特定 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">postMessage</mark></code> prototype，就可以達到 object pass by reference，大幅提升 post 物件的效能 (本來是 pass by value)。</p>



<p class="wp-block-paragraph"><strong>2. Subworkers</strong>：worker thread 可以再生成 worker thread。</p>



<p class="wp-block-paragraph"><strong>3. Inline Workers</strong>：worker script 不用寫死在 js 檔裡，在 caller 端先產生 Blob 再產生 Worker。</p>



<p class="wp-block-paragraph"><strong>4. Handling Errors</strong>：在 main thread 宣告 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">onError</mark></code> function 接 worker thread 丟出來的 error。</p>



<p class="wp-block-paragraph"><strong>5. Same Origin Consideration</strong>：worker scripts and the webpage must be from the same origin。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
