<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en" xml:base="http://fsfoundry.org/codefreak/wp-atom.php">
	<title type="text">COdE fr3@K</title>
	<subtitle type="text">Weblog of a lively geek.</subtitle>

	<updated>2012-04-29T16:36:12Z</updated>

	<link rel="alternate" type="text/html" href="http://fsfoundry.org/codefreak" />
	<id>http://fsfoundry.org/codefreak/feed/atom/</id>
	

	<generator uri="http://wordpress.org/" version="3.3.2">WordPress</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/codefreak" /><feedburner:info uri="codefreak" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/2.5/" /><logo>http://creativecommons.org/images/public/somerights20.gif</logo><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[&#8220;A Brief Introduction to C++11&#8243; Slidedeck]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/LRBDrcxIJoU/" />
		<id>http://fsfoundry.org/codefreak/?p=2059</id>
		<updated>2012-04-29T16:21:05Z</updated>
		<published>2012-04-15T03:03:14Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C" /><category scheme="http://fsfoundry.org/codefreak" term="C++11" /><category scheme="http://fsfoundry.org/codefreak" term="OSDC.TW" />		<summary type="html"><![CDATA[早上在 OSDC.TW 分享的 A Brief Introduction to C++11 投影片. &#8220;A Brief Introduction to C++11&#8243; Slidedeck was first posted on April 15, 2012 at 11:03 am.©2012 "COdE fr3@K". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2012/04/15/a-brief-introduction-to-cpp11-slidedeck/">&lt;p&gt;早上在 OSDC.TW 分享的 &lt;a href="https://www.box.com/s/3850a16d44ab52b1e92e"&gt;A Brief Introduction to C++11&lt;/a&gt; 投影片.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=2059#comments" title="Comments on &amp;quot;&amp;#8220;A Brief Introduction to C++11&amp;#8243; Slidedeck&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?2059" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2012/04/15/a-brief-introduction-to-cpp11-slidedeck/"&gt;&amp;#8220;A Brief Introduction to C++11&amp;#8243; Slidedeck&lt;/a&gt; was first posted on April 15, 2012 at 11:03 am.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=LRBDrcxIJoU:k7ZWWc9nTcY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=LRBDrcxIJoU:k7ZWWc9nTcY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2012/04/15/a-brief-introduction-to-cpp11-slidedeck/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2012/04/15/a-brief-introduction-to-cpp11-slidedeck/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2012/04/15/a-brief-introduction-to-cpp11-slidedeck/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Why is Force Killing Threads a Bad Idea?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/snE3Ak9quR4/" />
		<id>http://fsfoundry.org/codefreak/?p=1894</id>
		<updated>2012-04-29T16:36:12Z</updated>
		<published>2012-03-05T04:15:53Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="system-programming" />		<summary type="html"><![CDATA[&#8220;把類似 monit 這樣的 watchdog 機制用在 worker threads 上或許是個好主意.&#8221; 前陣子同事在聊天的時候跟我提起這樣的想法. &#8220;我們可以做一個 watchdog thread, 並且讓每個 worker thread 定期向 watchdog 打 heartbeat.&#8221; 他向我進一步說明. &#8220;這樣當其中有 worker 出錯, 沒反應, 以及進入死循環的時候我們就可以把它幹掉, 或許還可以重起.&#8221; 同事愈說愈起勁. 乍聽之下這很合理, 畢竟類似的事情我們已經對 process (monit) 以及 host OS 本身 [1] 做了許久. 只可惜, 實務上把類似的機制套在 thread 身上非常困難, 甚至是完全不可行. 原因是 thread 與 process 有許多不同. 特別是在 resource isolation 方面. Note: 本文所討論的暴力停止方法是如 POSIX 的 [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2012/03/05/why-is-force-killing-threads-a-bad-idea/">&lt;p&gt;&lt;em&gt;&amp;#8220;把類似 &lt;a href="http://mmonit.com/"&gt;monit&lt;/a&gt; 這樣的 watchdog 機制用在 worker threads 上或許是個好主意.&amp;#8221;&lt;/em&gt; 前陣子同事在聊天的時候跟我提起這樣的想法.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;#8220;我們可以做一個 watchdog thread, 並且讓每個 worker thread 定期向 watchdog 打 heartbeat.&amp;#8221;&lt;/em&gt; 他向我進一步說明.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;#8220;這樣當其中有 worker 出錯, 沒反應, 以及進入死循環的時候我們就可以把它幹掉, 或許還可以重起.&amp;#8221;&lt;/em&gt; 同事愈說愈起勁.&lt;span id="more-1894"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;乍聽之下這很合理, 畢竟類似的事情我們已經對 process (monit) 以及 host OS 本身&lt;sup&gt; [&lt;a href="http://fsfoundry.org/codefreak/2012/03/05/why-is-force-killing-threads-a-bad-idea/#footnote_0_1894" id="identifier_0_1894" class="footnote-link footnote-identifier-link" title="如 Linux 的 watchdog(8)."&gt;1&lt;/a&gt;]&lt;/sup&gt; 做了許久. 只可惜, 實務上把類似的機制套在 thread 身上非常困難, 甚至是完全不可行. 原因是 thread 與 process 有許多不同. 特別是在 resource isolation 方面.&lt;/p&gt;
&lt;ul&gt;Note: 本文所討論的暴力停止方法是如 POSIX 的 &lt;a href="http://linux.die.net/man/3/pthread_cancel"&gt;&lt;code&gt;pthread_cancel(3)&lt;/code&gt;&lt;/a&gt; + &lt;a href="http://linux.die.net/man/3/pthread_setcancelstate"&gt;&lt;code&gt;PTHREAD_CANCEL_ASYNCHRONOUS&lt;/code&gt;&lt;/a&gt; 或是 Win32 的 &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms686717(v=vs.85).aspx"&gt;&lt;code&gt;TerminateThread()&lt;/code&gt;&lt;/a&gt; 之類的非同步機制. Java 的 Thread.stop 也有 &lt;a href="http://docs.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html"&gt;類似但不完全相同的問題&lt;/a&gt;.&lt;/ul&gt;
&lt;p&gt;同一個 process 內的各個 thread 的 memory space 是共同擁有的, 也就是說除了 thread local storage 與 per-thread call stack 之外的所有 resource 幾乎都是&lt;em&gt;不分你我&lt;/em&gt;共享的. 正因為這個你泥中有我我泥中有你, 個別的 thread 無法提供如 process 結束時的&lt;em&gt;自動&lt;/em&gt;資源回收機制.&lt;sup&gt; [&lt;a href="http://fsfoundry.org/codefreak/2012/03/05/why-is-force-killing-threads-a-bad-idea/#footnote_1_1894" id="identifier_1_1894" class="footnote-link footnote-identifier-link" title="如回收 fd, 釋放記憶體等等."&gt;2&lt;/a&gt;]&lt;/sup&gt; 換句話說, 如果有個 thread 在來不及 release 已被 allocate 的 resource 時候就被幹掉, 這個 resource 就被 leak 掉了, 直到 process 結束.&lt;/p&gt;
&lt;p&gt;的確, 只要狀況不嚴重&lt;sup&gt; [&lt;a href="http://fsfoundry.org/codefreak/2012/03/05/why-is-force-killing-threads-a-bad-idea/#footnote_2_1894" id="identifier_2_1894" class="footnote-link footnote-identifier-link" title="在我看來, 如果 leak 的只是 memory 而 size 與次數都小, 不見得是不能接受的狀況."&gt;3&lt;/a&gt;]&lt;/sup&gt;, resource leak 並不一定是太糟糕的事情. 可是狀態的不一致 (state inconsistency) 就不一樣了, 後者很容易造成災難. 假設被暴力幹掉的 thread 正 hold 住一個 mutex, 接下來很可能其他的 thread 都將面對被 deadlock 的命運. 也許有人會說, &lt;em&gt;&amp;#8220;這不是問題, 我們的 thread 之間不需要同步沒有用到 mutex.&amp;#8221;&lt;/em&gt; &lt;/p&gt;
&lt;p&gt;只是, 可能不是每個人都清楚的是 &amp;#8211; 很多 library/module 都需要同步! 例如 &lt;code&gt;syslog()&lt;/code&gt;, &lt;code&gt;printf()&lt;/code&gt;/&lt;code&gt;fprintf()&lt;/code&gt; 與 &lt;a href="http://stackoverflow.com/questions/3366307/why-is-malloc-not-async-signal-safe"&gt;&lt;code&gt;malloc()&lt;/code&gt;&lt;/a&gt;/&lt;code&gt;free()&lt;/code&gt; 等直接間接都容易被使用到的 function.&lt;/p&gt;
&lt;p&gt;除了使用的全部是自己最小心寫的 code 之外, 我們怎麼能確定被暴力幹掉的 thread 不是正跑在前述的 function 裏面? 又或不會正在執行 critical section 的 code? 這等於是要求整個程式都要符合 &lt;a href="http://linux.die.net/man/7/signal"&gt;async-signal-safe&lt;/a&gt; 的要求. 相信我, 你不會希望走上這條路的 XD&lt;/p&gt;
&lt;p&gt;結論 &amp;#8211; 暴力停止一個正在運行的 thread 很難避免不理想的結果, 輕則 resource leak, 嚴重時可 deadlock 整個程式, 甚至因狀態的不一致而導致其他無法預測的行為.&lt;/p&gt;
&lt;p&gt;延伸討論 &amp;#8211; fork 一個跑了多個 thread 的 process 會有什麼後果? 提示: 只有 forking thread 會在 child process 繼續跑.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=1894#comments" title="Comments on &amp;quot;Why is Force Killing Threads a Bad Idea?&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?1894" alt="Comments" /&gt;&lt;/a&gt;&lt;ol class="footnotes"&gt;&lt;li id="footnote_0_1894" class="footnote"&gt;如 Linux 的 &lt;a href="http://linux.die.net/man/8/watchdog"&gt;watchdog(8)&lt;/a&gt;.&lt;/li&gt;&lt;li id="footnote_1_1894" class="footnote"&gt;如回收 fd, 釋放記憶體等等.&lt;/li&gt;&lt;li id="footnote_2_1894" class="footnote"&gt;在我看來, 如果 leak 的&lt;em&gt;只是&lt;/em&gt; memory 而 size 與次數都小, 不見得是不能接受的狀況.&lt;/li&gt;&lt;/ol&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2012/03/05/why-is-force-killing-threads-a-bad-idea/"&gt;Why is Force Killing Threads a Bad Idea?&lt;/a&gt; was first posted on March 5, 2012 at 12:15 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=snE3Ak9quR4:07HKocE-Qwc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=snE3Ak9quR4:07HKocE-Qwc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2012/03/05/why-is-force-killing-threads-a-bad-idea/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2012/03/05/why-is-force-killing-threads-a-bad-idea/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2012/03/05/why-is-force-killing-threads-a-bad-idea/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Root of All Evil &#8211; Defining Variables Early]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/fGefPThVm5k/" />
		<id>http://fsfoundry.org/codefreak/?p=1387</id>
		<updated>2010-11-19T14:07:58Z</updated>
		<published>2010-11-07T15:05:19Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="english" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="RoAE" />		<summary type="html"><![CDATA[Before we dive into the topic of this post, I would like to share with you the best possible advise I could ever give &#8211; never do everything by the book. I know it sounds kinda odd and may appear to be irresponsible. After all, this series is about what to avoid and promote best [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/11/07/root-of-all-evil-defining-variables-early/">&lt;p&gt;Before we dive into the topic of this post, I would like to share with you the best possible advise I could ever give &amp;#8211; &lt;em&gt;never do everything by the book&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;I know it sounds kinda odd and may appear to be irresponsible. After all, this series is about what to avoid and promote best practice. Am I not asking you do what I tell you? No, I am not.&lt;/p&gt;
&lt;p&gt;I am asking you to think and to reason consciously why you chose to code something the way you did.&lt;/p&gt;
&lt;p&gt;In the first &lt;a href="http://fsfoundry.org/codefreak/2010/10/31/root-of-all-evil-nasty-if-else-blocks/"&gt;post&lt;/a&gt; of this series, I wrote about how returning early improves code readability. It may appear so in the code snip presented in the post. It may seem to be appropriate in scenarios off the top of your head. However, I am most certain that there are contexts where returning early actually does the opposite &amp;#8211; hurting code readability.&lt;/p&gt;
&lt;p&gt;It is important that we understand a best practice is anything but the law. When circumstances change, it may not stand.&lt;/p&gt;
&lt;p&gt;I ask you to think as you code.&lt;/p&gt;
&lt;p&gt;Now, back to the topic. In this post, we will revisit a well known best practice from a less discussed perspective.&lt;span id="more-1387"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;It is almost always a good practice to define variables where they are first needed, but not earlier. Doing otherwise is almost certainly asking for trouble. Take this &lt;a href="http://code.google.com/p/miranda/source/browse/trunk/miranda/src/core/miranda.cpp?spec=svn13109&amp;#038;r=12825#543" rel="nofollow"&gt;&lt;code&gt;WinMain()&lt;/code&gt;&lt;/a&gt; function from &lt;a href="http://www.miranda-im.org/" ref="nofollow"&gt;Miranda IM&lt;/a&gt; for example, and fast forward to &lt;a href="http://code.google.com/p/miranda/source/browse/trunk/miranda/src/core/miranda.cpp?spec=svn13109&amp;#038;r=12825#649"&gt;line 649&lt;/a&gt;, the first line of interest of this post:&lt;/p&gt;
&lt;pre class="brush: cpp; first-line: 645; highlight: [649]; title: ; notranslate"&gt;
        CreateServiceFunction(MS_SYSTEM_SETIDLECALLBACK,SystemSetIdleCallback);
        CreateServiceFunction(MS_SYSTEM_GETIDLE, SystemGetIdle);
        dwEventTime=GetTickCount();
        myPid=GetCurrentProcessId();
        for(;messageloop;) {
                MSG msg;
                DWORD rc;
                BOOL dying=FALSE;
                rc=MsgWaitForMultipleObjectsExWorkaround(waitObjectCount, hWaitObjects, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);
&lt;/pre&gt;
&lt;p&gt;It is a &lt;code&gt;for&lt;/code&gt; statement using the variable &lt;code&gt;messageloop&lt;/code&gt; as its condition.&lt;/p&gt;
&lt;p&gt;Depending on your preference to trace code &lt;a href="http://code.google.com/p/miranda/source/browse/trunk/miranda/src/core/miranda.cpp?spec=svn13109&amp;#038;r=12825#543"&gt;forwards&lt;/a&gt; or &lt;a href="http://code.google.com/p/miranda/source/browse/trunk/miranda/src/core/miranda.cpp?spec=svn13109&amp;#038;r=12825#649"&gt;backwards&lt;/a&gt;, visit Miranda IM&amp;#8217;s source browser via either link, and try answering this &amp;#8211; what are the possible values of &lt;code&gt;messageloop&lt;/code&gt; when the &lt;code&gt;for&lt;/code&gt; loop starts?&lt;/p&gt;
&lt;p&gt;Before we go on, please allow yourself a minute or two to go through the code and find out the answer.&lt;/p&gt;
&lt;p&gt;Okay, now that we know the variable &lt;code&gt;messageloop&lt;/code&gt; was defined at &lt;a href="http://code.google.com/p/miranda/source/browse/trunk/miranda/src/core/miranda.cpp?spec=svn13109&amp;#038;r=12825#546"&gt;line 546&lt;/a&gt; as &lt;code&gt;int&lt;/code&gt; with the value &lt;code&gt;1&lt;/code&gt; at the beginning of &lt;code&gt;WinMain()&lt;/code&gt;.&lt;/p&gt;
&lt;pre class="brush: cpp; first-line: 543; highlight: [546]; title: ; notranslate"&gt;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int )
{
        DWORD myPid=0;
        int messageloop=1;
        HMODULE hUser32, hThemeAPI, hDwmApi, hShFolder = NULL;
&lt;/pre&gt;
&lt;p&gt;And as it turns out, &lt;code&gt;messageloop&lt;/code&gt; was never modified, in fact, it was never referenced elsewhere, except at line 649, as the condition of said &lt;code&gt;for&lt;/code&gt; statement. That&amp;#8217;s more than 100 LOC (lines of code) apart, and nothing relevant in between.&lt;/p&gt;
&lt;p&gt;I don&amp;#8217;t know about you, but I think it is pure annoying to make people going through more than a few LOC, and end up learning there was nothing of interest, it is a major waste of time and one of the best ways to upset people.&lt;/p&gt;
&lt;p&gt;Mayers has been telling us to &lt;a href="http://www.amazon.com/Effective-Specific-Improve-Programs-Designs/dp/0321334876/"&gt;postpone variable definitions as long as possible&lt;/a&gt; for more than a decade. If you are not convinced by the book for whatever reason, think code readability, and make the lives of your fellow code readers easier.&lt;/p&gt;
&lt;p&gt;One day, that reader of your code may very well be you.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=1387#comments" title="Comments on &amp;quot;Root of All Evil &amp;#8211; Defining Variables Early&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?1387" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/11/07/root-of-all-evil-defining-variables-early/"&gt;Root of All Evil &amp;#8211; Defining Variables Early&lt;/a&gt; was first posted on November 7, 2010 at 11:05 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=fGefPThVm5k:JIOm3FfftdE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=fGefPThVm5k:JIOm3FfftdE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/11/07/root-of-all-evil-defining-variables-early/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/11/07/root-of-all-evil-defining-variables-early/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/11/07/root-of-all-evil-defining-variables-early/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Function overloading by return type]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/cD_D_-lA1V0/" />
		<id>http://fsfoundry.org/codefreak/?p=1367</id>
		<updated>2012-01-14T12:19:53Z</updated>
		<published>2010-11-01T16:07:13Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="english" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[A very interesting and informative answer on Stack Overflow. Note in the end of the post, author of the answer presented a trick demonstrating how one could overload functions by return type. Coincidentally, a similar hack had been shown in an earlier post of mine. One more example why you shouldn&#8217;t insist on using different [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/11/02/function-overloading-by-return-type/">&lt;p&gt;A very interesting and informative &lt;a href="http://stackoverflow.com/questions/442026#442291"&gt;answer&lt;/a&gt; on Stack Overflow.&lt;/p&gt;
&lt;p&gt;Note in the end of the post, author of the answer presented a trick demonstrating how one could overload functions by return type. Coincidentally, a similar hack had been shown in an earlier &lt;a href="http://fsfoundry.org/codefreak/2009/09/17/boost-lexical-cast-alternatives/"&gt;post&lt;/a&gt; of mine.&lt;/p&gt;
&lt;p&gt;One more example why you &lt;a href="http://fsfoundry.org/codefreak/2009/09/17/boost-lexical-cast-alternatives/#class-function-object-naming"&gt;shouldn&amp;#8217;t&lt;/a&gt; insist on using different naming schemes to name classes from functions consistently.&lt;/p&gt;
&lt;p&gt;Hey, sometimes, objects are functions and functions are objects.&lt;sup&gt; [&lt;a href="http://fsfoundry.org/codefreak/2010/11/02/function-overloading-by-return-type/#footnote_0_1367" id="identifier_0_1367" class="footnote-link footnote-identifier-link" title="Some other times, objects could be functions and classes could be objects."&gt;1&lt;/a&gt;]&lt;/sup&gt;&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=1367#comments" title="Comments on &amp;quot;Function overloading by return type&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?1367" alt="Comments" /&gt;&lt;/a&gt;&lt;ol class="footnotes"&gt;&lt;li id="footnote_0_1367" class="footnote"&gt;Some other times, objects could be functions and classes could be objects.&lt;/li&gt;&lt;/ol&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/11/02/function-overloading-by-return-type/"&gt;Function overloading by return type&lt;/a&gt; was first posted on November 2, 2010 at 12:07 am.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=cD_D_-lA1V0:QsJjsW4qBcU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=cD_D_-lA1V0:QsJjsW4qBcU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/11/02/function-overloading-by-return-type/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/11/02/function-overloading-by-return-type/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/11/02/function-overloading-by-return-type/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Root of All Evil &#8211; Nasty If Else blocks]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/kykFtH1qH9Y/" />
		<id>http://fsfoundry.org/codefreak/?p=1092</id>
		<updated>2010-11-19T16:22:52Z</updated>
		<published>2010-10-31T09:18:52Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="english" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="RoAE" />		<summary type="html"><![CDATA[It has been a while since I last wrote. It is not that I wrote enough, I still love it, and am keen to share my (possibly biased) thoughts with fellow developers out there. But life and work have kept me busy in the past few months, busier than I would like to be. Anyhow, [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/10/31/root-of-all-evil-nasty-if-else-blocks/">&lt;p&gt;It has been a while since I last wrote. It is not that I wrote enough, I still love it, and am keen to share my (possibly biased) thoughts with fellow developers out there. But life and work have kept me busy in the past few months, busier than I would like to be.&lt;/p&gt;
&lt;p&gt;Anyhow, I am starting a series of posts called &amp;#8220;Root of All Evil&amp;#8221;. The plan is to write about bad practices I see at work, on the Internet, and smelly code I used to write. I hope to be able to cover the following aspects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What does bad code look like&lt;/li&gt;
&lt;li&gt;Why is it bad&lt;/li&gt;
&lt;li&gt;And how it could be improved/refactored&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you happen to care reading my blog, chances are you won&amp;#8217;t be contributing too many of those. However, even if they were someone else&amp;#8217;s responsibility, &lt;del datetime="2010-11-01T17:21:20+00:00"&gt;it is essential that you&lt;/del&gt; &lt;ins datetime="2010-11-01T17:21:20+00:00"&gt;I encourage you to&lt;/ins&gt; step up, and talk him/her into making necessary changes and quitting the habit, perhaps over a cup of coffee or via a formal code review.&lt;/p&gt;
&lt;p&gt;Though it is unlikely that I would have the luxury and the time to write weekly as I used to, I will just do my best. This series will be written casually, in Chinese or in English, yes, depending on my mood. So, bear with me and here it goes.&lt;span id="more-1092"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Nasty If Else blocks are killers to code readability, and if I may, a huge pain in the ass for sorry developers who ended up maintaining them. They waste your valuable time and energy, deciphering logics that would had otherwise been trivial to understand.&lt;/p&gt;
&lt;p&gt;Not so sure? Take the following random code snip taken from the &lt;a href="http://littlewhite0816.twbbs.org/2009/11/27/treap/" rel="nofollow"&gt;Internet&lt;/a&gt; for example:&lt;/p&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
    void remove(TreapNode *&amp;amp;t, KeyType v)
    {
        if (t == NULL) return;
        if (v &amp;gt; t-&amp;gt;key) remove(t-&amp;gt;right, v);
        else if (v &amp;lt; t-&amp;gt;key) remove(t-&amp;gt;left, v);
        else
        {
            if(t-&amp;gt;left == NULL &amp;amp;&amp;amp; t-&amp;gt;right == NULL)
            {
                delete t;
                t = NULL;
            }
            else if(t-&amp;gt;left == NULL)
            {
                TreapNode *tmp = t;
                t = t-&amp;gt;right;
                delete tmp;
            }
            else if(t-&amp;gt;right == NULL)
            {
                TreapNode *tmp = t;
                t = t-&amp;gt;left;
                delete tmp;
            }
            else
            {
                if (t-&amp;gt;left-&amp;gt;priority &amp;lt; t-&amp;gt;right-&amp;gt;priority)
                {
                    RotateLeft(t);
                    remove(t-&amp;gt;left, v);
                }
                else
                {
                    RotateRight(t);
                    remove(t-&amp;gt;right, v);
                }
            }
        }
    }
&lt;/pre&gt;
&lt;ul&gt;&lt;em&gt;Note: Please don&amp;#8217;t get into what it does, and quite frankly, I don&amp;#8217;t care. Not for the purpose of this post anyway. I personally find it fascinating that, oftentimes, one could improve a piece of code without understanding what it actually does.&lt;/em&gt;&lt;/ul&gt;
&lt;p&gt;Can you tell what goes after the recursive &lt;code&gt;remove()&lt;/code&gt; if the condition in line 4 was &lt;code&gt;true&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;Of course you can. Nothing, it just returns.&lt;/p&gt;
&lt;p&gt;But how long did it take you to find that out? Was it easy to you to skim through the entire function and at the same time, keeping track of levels of if/else blocks?&lt;/p&gt;
&lt;p&gt;Only if it had been written differently, possibly in the line of the following:&lt;/p&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
    void remove(TreapNode *&amp;amp;t, KeyType v)
    {
        if (t == NULL)
          return;

        if (v &amp;gt; t-&amp;gt;key)
        {
          remove(t-&amp;gt;right, v);
          return;
        }

        if (v &amp;lt; t-&amp;gt;key)
        {
          remove(t-&amp;gt;left, v);
          return;
        }

        // snipped...
    }
&lt;/pre&gt;
&lt;p&gt;It is now obvious. Any one could tell in 3 seconds. And better yet, without reading the remaining of the function.&lt;/p&gt;
&lt;p&gt;Dealing with one such badly written function may be trivial, but digging through 10, 20 of these in a large code base may become stressful as complexity adds up.&lt;/p&gt;
&lt;p&gt;To avoid nasty if/else blocks and improve readability, return as early as possible and use &lt;a href="http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/"&gt;Extract Method&lt;/a&gt; when appropriate.&lt;/p&gt;
&lt;p&gt;Trust me, maintainers of your code will appreciate it.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=1092#comments" title="Comments on &amp;quot;Root of All Evil &amp;#8211; Nasty If Else blocks&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?1092" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/10/31/root-of-all-evil-nasty-if-else-blocks/"&gt;Root of All Evil &amp;#8211; Nasty If Else blocks&lt;/a&gt; was first posted on October 31, 2010 at 5:18 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=kykFtH1qH9Y:q29JiOSpegQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=kykFtH1qH9Y:q29JiOSpegQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/10/31/root-of-all-evil-nasty-if-else-blocks/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/10/31/root-of-all-evil-nasty-if-else-blocks/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/10/31/root-of-all-evil-nasty-if-else-blocks/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Re: 你怎麼在看簡體的東西!?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/Hd5xvF1jcwk/" />
		<id>http://fsfoundry.org/codefreak/?p=1182</id>
		<updated>2010-08-25T14:38:23Z</updated>
		<published>2010-08-08T15:54:00Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="FSfoundry" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[Hi Sam, 你的 留言 讓我想了許久. 小弟以為, 原創的繁中技術文字過少的最大關鍵不在於書籍市場, 而在寫的動機. 只要找到非金錢回報的動機, 就能寫得下去. 畢竟, 這是個屬於網路的年代, 只要有心有料, 甚至只要自 high, 誰都可以發表. 我們都在這片土地上生活, 在這個業界燃燒熱血, 盼望能實現自己的夢想. 以我為例, 我的夢想是台灣能有個健康前瞻有搞頭的軟體產業. 讓我們不一定要離鄉背井, 才能夠免去賣肝的宿命, 可以好好賣腦揮撒我們的熱情展現我們的專業, 並且得到適當的回報. 我很清楚, 在這個大環境, 我的想法多少不太現實. 即便如此, 除了抱怨, 我還選擇盡一點微薄的力量. 這個部落格能還能活著, 最大的動力正是對這個夢想的執著. 你的夢想是什麼? [後記] 這篇文字是在抒發我的牢騷, 非針對個人. Sam, 不好意思借用了你的名字&#8230; Re: 你怎麼在看簡體的東西!? was first posted on August 8, 2010 at 11:54 pm.©2012 "COdE fr3@K". Use of [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/08/08/re-%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/">&lt;p&gt;Hi Sam,&lt;/p&gt;
&lt;p&gt;你的 &lt;a href="http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/#comment-13575"&gt;留言&lt;/a&gt; 讓我想了許久. 小弟以為, 原創的繁中技術文字過少的最大關鍵不在於書籍市場, 而在寫的動機. 只要找到非金錢回報的動機, 就能寫得下去. 畢竟, 這是個屬於網路的年代, 只要有心有料, 甚至只要自 high, 誰都可以發表.&lt;/p&gt;
&lt;p&gt;我們都在這片土地上生活, 在這個業界燃燒熱血, 盼望能實現自己的夢想. 以我為例, 我的夢想是台灣能有個健康前瞻有搞頭的軟體產業. 讓我們不一定要離鄉背井, 才能夠免去賣肝的宿命, 可以好好賣腦揮撒我們的熱情展現我們的專業, 並且得到適當的回報.&lt;/p&gt;
&lt;p&gt;我很清楚, 在這個大環境, 我的想法多少不太現實. 即便如此, 除了抱怨, 我還選擇盡一點微薄的力量. 這個部落格能還能活著, 最大的動力正是對這個夢想的執著.&lt;/p&gt;
&lt;p&gt;你的夢想是什麼?&lt;/p&gt;
&lt;p&gt;&lt;em&gt;[後記] 這篇文字是在抒發我的牢騷, 非針對個人. Sam, 不好意思借用了你的名字&amp;#8230;&lt;/em&gt;&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=1182#comments" title="Comments on &amp;quot;Re: 你怎麼在看簡體的東西!?&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?1182" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/08/08/re-%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/"&gt;Re: 你怎麼在看簡體的東西!?&lt;/a&gt; was first posted on August 8, 2010 at 11:54 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=Hd5xvF1jcwk:K3XtYV9jMW0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=Hd5xvF1jcwk:K3XtYV9jMW0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/08/08/re-%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/#comments" thr:count="5" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/08/08/re-%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/feed/atom/" thr:count="5" />
		<thr:total>5</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/08/08/re-%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Did You Know, &#8220;new (nothrow) T&#8221; Throws?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/resX4TUdZKU/" />
		<id>http://fsfoundry.org/codefreak/?p=1091</id>
		<updated>2010-08-05T15:07:17Z</updated>
		<published>2010-08-01T12:08:23Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="error-handling" /><category scheme="http://fsfoundry.org/codefreak" term="exception" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[可能會出乎不少人的意料, 下面的 code snip 可能會拋出 exception. Listing-1. 許多人都知道, 這樣的 new expression (nothrow new) 的做動可分成兩個部份: 首先根據 sizeof(T) 的大小呼叫 nothrow 的 operator new 以取得將被創建於 heap 上的 T 物件的 memory footprint 然後再對該 memory 位置做 T 的 placement new 也可以說, 它與下面的 code 等效： Listing-2. 看到這裡, 相信大部份的朋友已經瞧出端倪來了. Listing 1 的 new expression (或是 listing 2 的第 13 行) 會拋出 exception [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/08/01/new-nothrow-t-throws/">&lt;p&gt;可能會出乎不少人的意料, 下面的 code snip 可能會拋出 exception.&lt;/p&gt;
&lt;ul&gt;
&lt;div id="listing-1" /&gt;&lt;a href="#listing-1"&gt;Listing-1&lt;/a&gt;.&lt;/p&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
using namespace std;
T* new_t_nothrow()
{
  return new (nothrow) T;
}
&lt;/pre&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span id="more-1091"&gt;&lt;/span&gt;&lt;br /&gt;
許多人都知道, 這樣的 new expression (&lt;a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;#038;seqNum=170" rel="nofollow"&gt;nothrow new&lt;/a&gt;) 的做動可分成兩個部份:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;首先根據 &lt;code&gt;sizeof(T)&lt;/code&gt; 的大小呼叫 nothrow 的 &lt;a href="http://stdcxx.apache.org/doc/stdlibref/operatornew.html"&gt;&lt;code&gt;operator new&lt;/code&gt;&lt;/a&gt; 以取得將被創建於 heap 上的 &lt;code&gt;T&lt;/code&gt; 物件的 memory footprint&lt;/li&gt;
&lt;li&gt;然後再對該 memory 位置做 &lt;code&gt;T&lt;/code&gt; 的 &lt;a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;#038;seqNum=304" rel="nofollow"&gt;placement new&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;也可以說, 它與下面的 code 等效：&lt;/p&gt;
&lt;ul&gt;
&lt;div id="listing-2" /&gt;&lt;a href="#listing-2"&gt;Listing-2&lt;/a&gt;.&lt;/p&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
T* new_t_nothrow()
{
  // For the purpose of this discussion, one can freely
  // exchange the following invocation of `operator new`
  // (in line 6) with `malloc(sizeof(T))`.
  char* buf = operator new (sizeof(T), nothrow);
  if(buf == NULL)
    return NULL;

  try
  {
    // Invoke `T::T()` at the address pointed by `buf`.
    return new (buf) T;
  }
  catch(...)
  {
    operator delete (buf);
    throw;
  }
}
&lt;/pre&gt;
&lt;/ul&gt;
&lt;p&gt;看到這裡, 相信大部份的朋友已經瞧出端倪來了. &lt;a href="#listing-1"&gt;Listing 1&lt;/a&gt; 的 new expression (或是 &lt;a href="#listing-2"&gt;listing 2&lt;/a&gt; 的第 13 行) 會拋出 exception 一點也不奇怪, 全看 T 的 definition. 若 &lt;code&gt;T&lt;/code&gt; 的定義為下列任何一種 (note: not a complete listing), 則 &lt;code&gt;new (nothrow) T&lt;/code&gt; 依然可能觸發 exception:&lt;/p&gt;
&lt;ul&gt;
&lt;div id="listing-3" /&gt;&lt;a href="#listing-3"&gt;Listing-3&lt;/a&gt;.&lt;/p&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
struct T1
{
  T1() { throw exception(); }
};
struct T2
{
  T2() { string tmp(&amp;quot;blah blah&amp;quot;); }
};
struct T3
{
  U* u;
  T3() : u(new U) {}
};
struct T4 : Tx // Tx: any one of T1, T2, T3 ...
{};
struct T5
{
  Tx member;
};
struct T6
{
  T6() { Tx tmp; }
};
&lt;/pre&gt;
&lt;/ul&gt;
&lt;p&gt;換一個說法, 如果在 stack 上 instantiate &lt;code&gt;class T&lt;/code&gt; 的物件可能會導致 exception, 那以 nothrow &lt;code&gt;new&lt;/code&gt; 創建也是一樣的狀況:&lt;/p&gt;
&lt;ul&gt;
&lt;div id="listing-4" /&gt;&lt;a href="#listing-4"&gt;Listing-4&lt;/a&gt;.&lt;/p&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
void foo
{
  // If instantiating an object of `class T` on the stack
  // could throw,
  T t;

  // then instantiating it via `nothrow new` could, too.
  T* p = new (nothrow) T;
}
&lt;/pre&gt;
&lt;/ul&gt;
&lt;p&gt;Nothrow &lt;code&gt;new&lt;/code&gt; 所避掉的 exception 只不過是在請求 object 所需的 memory footprint 時所可能引起的 exception, 但不會改變 object 被創建時的行為. 創建中的 object 直接或間接做的事情仍然可能觸發 exception. 而那最外層的 &lt;code&gt;new (nothrow) T&lt;/code&gt; 只會增加正確錯誤處理的複雜度 &amp;#8211; client 既需要 handle &lt;code&gt;NULL&lt;/code&gt; 也要考慮 exception 發生的情況.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=1091#comments" title="Comments on &amp;quot;Did You Know, &amp;#8220;new (nothrow) T&amp;#8221; Throws?&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?1091" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/08/01/new-nothrow-t-throws/"&gt;Did You Know, &amp;#8220;new (nothrow) T&amp;#8221; Throws?&lt;/a&gt; was first posted on August 1, 2010 at 8:08 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=resX4TUdZKU:9g0w1cszohU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=resX4TUdZKU:9g0w1cszohU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/08/01/new-nothrow-t-throws/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/08/01/new-nothrow-t-throws/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/08/01/new-nothrow-t-throws/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[You Don&#8217;t Have to Resort to Goto]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/6UTB0mfFv3M/" />
		<id>http://fsfoundry.org/codefreak/?p=1013</id>
		<updated>2011-11-29T10:13:20Z</updated>
		<published>2010-06-19T14:35:13Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[你一定看過這樣的 code: 可讀性差的巢狀 if block, 只為了堅持由一處 return. 想必也看過這樣的 code: 由多處 return 雖避掉了巢狀 if block, 但需要在多個地方 cleanup 之前所請求的資源. 當然還有這樣的 code: 不管老師以前是如何叮嚀不要用 goto, 為了閃掉那噁心的巢狀 if block 以及重複的 code, 只好還是用了 goto. 其實還有另一種選擇, 不用重複寫釋放資源的 code, 也不需要用到 goto: 一旦把 resource management 跟 logic 的部份拆開, code 就好看多了. 獻給一位因為沒有充足理由的規定, 卻在工作中被迫得寫 pure C 的可憐同事. 後記: 這應該是目前我寫的唯一一篇 pure C 的文字. 擔心它太寂寞, 還是把它打上了 C++ 的 [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/">&lt;p&gt;你一定看過這樣的 code:&lt;/p&gt;
&lt;ul&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
int do_work(size_t n)
{
  int result = ERROR;
  char* buf;

  if(n)
  {
    buf =  malloc(n);
    if(buf != 0)
    {
      if(do_foo(buf, n) == OKAY)
      {
        if(do_bar(buf, n) == OKAY)
          result = OKAY;
      }
      free(buf);
    }
  }

  return result;
}
&lt;/pre&gt;
&lt;/ul&gt;
&lt;p&gt;可讀性差的巢狀 &lt;code&gt;if&lt;/code&gt; block, 只為了堅持由一處 &lt;code&gt;return&lt;/code&gt;.&lt;br /&gt;
&lt;span id="more-1013"&gt;&lt;/span&gt;&lt;br /&gt;
想必也看過這樣的 code:&lt;/p&gt;
&lt;ul&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
int do_work(size_t n)
{
  char* buf;

  if(n == 0)
    return ERROR;

  buf =  malloc(n);
  if(buf == 0)
    return ERROR;

  if(do_foo(buf, n) != OKAY)
  {
    free(buf);
    return ERROR;
  }

  if(do_bar(buf, n) != OKAY)
  {
    free(buf);
    return ERROR;
  }

  return OKAY;
}
&lt;/pre&gt;
&lt;/ul&gt;
&lt;p&gt;由多處 &lt;code&gt;return&lt;/code&gt; 雖避掉了巢狀 &lt;code&gt;if&lt;/code&gt; block, 但需要在多個地方 cleanup 之前所請求的資源.&lt;/p&gt;
&lt;p&gt;當然還有這樣的 code:&lt;/p&gt;
&lt;ul&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
int do_work(size_t n)
{
  int result = ERROR;
  char* buf = 0;

  if(n == 0)
    goto CLEANUP;

  buf =  malloc(n);
  if(buf == 0)
    goto CLEANUP;

  if(do_foo(buf, n) != OKAY)
    goto CLEANUP;

  if(do_bar(buf, n) != OKAY)
    goto CLEANUP;

  result = OKAY;

CLEANUP:
  // free()ing a NULL ptr is a no-op.
  free(buf);

  return result;
}
&lt;/pre&gt;
&lt;/ul&gt;
&lt;p&gt;不管老師以前是如何叮嚀不要用 &lt;code&gt;goto&lt;/code&gt;, 為了閃掉那噁心的巢狀 &lt;code&gt;if&lt;/code&gt; block 以及重複的 code, 只好還是用了 &lt;code&gt;goto&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;其實還有另一種選擇, 不用重複寫釋放資源的 code, 也不需要用到 &lt;code&gt;goto&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
static int do_work_using_client_buffer(char* buf, n)
{
  if(do_foo(buf, n) != OKAY)
    return ERROR;

  if(do_bar(buf, n) != OKAY)
    return ERROR;

  return OKAY;
}

int do_work(size_t n)
{
  int result;
  char* buf;

  if(n == 0)
    return ERROR;

  buf =  malloc(n);
  if(buf == 0)
    return ERROR;

  result = do_work_helper(buf, n);

  free(buf);
  return result;
}
&lt;/pre&gt;
&lt;/ul&gt;
&lt;p&gt;一旦把 resource management 跟 logic 的部份拆開, code 就好看多了.&lt;/p&gt;
&lt;ul&gt;&lt;em&gt;獻給一位因為沒有充足理由的規定, 卻在工作中被迫得寫 pure C 的可憐同事.&lt;/em&gt;&lt;/ul&gt;
&lt;p&gt;後記: 這應該是目前我寫的唯一一篇 pure C 的文字. 擔心它太寂寞, 還是把它打上了 &lt;a href="http://fsfoundry.org/codefreak/tag/cpp/"&gt;C++&lt;/a&gt; 的 tag.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Edit:&lt;/p&gt;
&lt;ul&gt;
do_something() -&gt; do_work()&lt;br /&gt;
do_something_helper() -&gt; do_work_using_client_buffer()
&lt;/ul&gt;
&lt;p&gt;&lt;/em&gt;&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=1013#comments" title="Comments on &amp;quot;You Don&amp;#8217;t Have to Resort to Goto&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?1013" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/"&gt;You Don&amp;#8217;t Have to Resort to Goto&lt;/a&gt; was first posted on June 19, 2010 at 10:35 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=6UTB0mfFv3M:F2lS2HjhHSc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=6UTB0mfFv3M:F2lS2HjhHSc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/#comments" thr:count="8" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/feed/atom/" thr:count="8" />
		<thr:total>8</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[華碩品質, 以卵擊石]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/4KDlcSMUrRY/" />
		<id>http://fsfoundry.org/codefreak/?p=983</id>
		<updated>2010-06-01T17:24:45Z</updated>
		<published>2010-06-01T17:24:23Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="foss" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="whining" />		<summary type="html"><![CDATA[很多人可能已經沒印象了. 但我記得很清楚. 去年 5 月底, The Register 所做的一則 報導: Microsoft and Asus have teamed up to present a new advertising smarm-storm intended to extol the virtues of Windows on netbooks &#8211; and smear Linux. 而在今天的這則 ZDNet Taiwan 的 報導 卻又看到: 英特爾表示，宏碁、華碩、戴爾、諾基亞、惠普(儘管已擁有自己的WebOS)等品牌廠商，都已加入發展MeeGo平板的計畫，並有多家OSV、ISV與服務提供廠商來共同建構此生態鏈。 英特爾表示，MeeGo是一款可跨裝置的行動作業系統，將用在手持裝置、小筆電、平板裝置、車用裝置或電視上，此作業系統是基於Linux的開源碼計畫，並獲Linux基金會贊助，目前正由英特爾、諾基亞與開發者社群合作推動。 並登出一張 以卵擊石 展示機 (?) 的照片: 果真是有堅持有願景的企業啊! 也不知道是什麼時候, 這家 以卵擊石 的公司已經把那 可笑 的網站下線了, 現在是個 [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/06/02/%e8%8f%af%e7%a2%a9%e5%93%81%e8%b3%aa-%e4%bb%a5%e5%8d%b5%e6%93%8a%e7%9f%b3/">&lt;p&gt;很多人可能已經沒印象了. 但我記得很清楚.&lt;/p&gt;
&lt;p&gt;去年 &lt;a href="http://fsfoundry.org/codefreak/2009/05/30/its-better-without-asus/"&gt;5 月底&lt;/a&gt;, The Register 所做的一則 &lt;a href="http://www.theregister.co.uk/2009/05/30/its_better_with_windows/"&gt;報導&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Microsoft and Asus have teamed up to present a new advertising smarm-storm intended to extol the virtues of Windows on netbooks &amp;#8211; and smear Linux.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;span id="more-983"&gt;&lt;/span&gt;&lt;br /&gt;
而在今天的這則 ZDNet Taiwan 的 &lt;a href="http://www.zdnet.com.tw/news/ce/0,2000085674,20145785,00.htm" rel="nofollow"&gt;報導&lt;/a&gt; 卻又看到:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;英特爾表示，宏碁、&lt;big&gt;&lt;strong&gt;&lt;em&gt;華碩&lt;/em&gt;&lt;/strong&gt;&lt;/big&gt;、戴爾、諾基亞、惠普(儘管已擁有自己的WebOS)等品牌廠商，都已加入發展MeeGo平板的計畫，並有多家OSV、ISV與服務提供廠商來共同建構此生態鏈。&lt;/p&gt;
&lt;p&gt;英特爾表示，MeeGo是一款可跨裝置的行動作業系統，將用在手持裝置、小筆電、平板裝置、車用裝置或電視上，&lt;big&gt;&lt;strong&gt;&lt;em&gt;此作業系統是基於Linux的開源碼計畫&lt;/em&gt;&lt;/strong&gt;&lt;/big&gt;，並獲Linux基金會贊助，目前正由英特爾、諾基亞與開發者社群合作推動。&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;並登出一張 &lt;a href="http://www.asus.com/"&gt;以卵擊石&lt;/a&gt; 展示機 (?) 的照片:&lt;/p&gt;
&lt;ul&gt;
&lt;a href="http://fsfoundry.org/codefreak/wp-content/uploads/2010/06/Screenshot-ZDNet-Taiwan-【Computex】台廠展示MeeGo平板、小筆電（圖）-新聞-數位產品-Mozilla-Firefox.png" rel="lightbox"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/uploads/2010/06/Screenshot-ZDNet-Taiwan-【Computex】台廠展示MeeGo平板、小筆電（圖）-新聞-數位產品-Mozilla-Firefox-300x251.png" alt="Screenshot-ZDNet Taiwan - 【Computex】台廠展示MeeGo平板、小筆電（圖） - 新聞 - 數位產品 - Mozilla Firefox" title="Screenshot-ZDNet Taiwan - 【Computex】台廠展示MeeGo平板、小筆電（圖） - 新聞 - 數位產品 - Mozilla Firefox" width="300" height="251" class="alignnone size-medium wp-image-997" /&gt;&lt;/a&gt;
&lt;/ul&gt;
&lt;p&gt;果真是有堅持有願景的企業啊!&lt;/p&gt;
&lt;p&gt;也不知道是什麼時候, 這家 &lt;a href="http://www.asus.com/"&gt;以卵擊石&lt;/a&gt; 的公司已經把那 &lt;a href="http://www.itsbetterwithwindows.com/"&gt;可笑&lt;/a&gt; 的網站下線了, 現在是個 parking page. 真是後悔當時沒做個 screenshot 留個紀念~&lt;/p&gt;
&lt;p&gt;剛剛在 &lt;a href="http://www.google.com.tw/search?hl=zh-TW&amp;#038;lr=lang_zh-CN|lang_zh-TW&amp;#038;safe=off&amp;#038;client=firefox-a&amp;#038;rls=com.ubuntu%3Aen-US%3Aofficial&amp;#038;tbs=lr%3Alang_1zh-CN|lang_1zh-TW&amp;#038;q=asus&amp;#038;aq=f&amp;#038;aqi=&amp;#038;aql=&amp;#038;oq=&amp;#038;gs_rfai="&gt;google 以卵擊石&lt;/a&gt; 的時候發現了一件有趣的事情:&lt;/p&gt;
&lt;ul&gt;
&lt;a href="http://fsfoundry.org/codefreak/wp-content/uploads/2010/06/Screenshot-asus-Google-搜尋-Mozilla-Firefox.png" rel="lightbox"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/uploads/2010/06/Screenshot-asus-Google-搜尋-Mozilla-Firefox-300x264.png" alt="Screenshot-asus - Google 搜尋 - Mozilla Firefox" title="Screenshot-asus - Google 搜尋 - Mozilla Firefox" width="300" height="264" class="alignnone size-medium wp-image-999" /&gt;&lt;/a&gt;
&lt;/ul&gt;
&lt;p&gt;Google &lt;a href="http://www.asus.com/"&gt;以卵擊石&lt;/a&gt; 的第一個結果是 tw.asus.com, 可是 google 看到的內容卻是簡體的. WTF.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=983#comments" title="Comments on &amp;quot;華碩品質, 以卵擊石&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?983" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/06/02/%e8%8f%af%e7%a2%a9%e5%93%81%e8%b3%aa-%e4%bb%a5%e5%8d%b5%e6%93%8a%e7%9f%b3/"&gt;華碩品質, 以卵擊石&lt;/a&gt; was first posted on June 2, 2010 at 1:24 am.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=4KDlcSMUrRY:8U7EACD_vJc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=4KDlcSMUrRY:8U7EACD_vJc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/06/02/%e8%8f%af%e7%a2%a9%e5%93%81%e8%b3%aa-%e4%bb%a5%e5%8d%b5%e6%93%8a%e7%9f%b3/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/06/02/%e8%8f%af%e7%a2%a9%e5%93%81%e8%b3%aa-%e4%bb%a5%e5%8d%b5%e6%93%8a%e7%9f%b3/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/06/02/%e8%8f%af%e7%a2%a9%e5%93%81%e8%b3%aa-%e4%bb%a5%e5%8d%b5%e6%93%8a%e7%9f%b3/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[你怎麼在看簡體的東西!?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/-wSalFm2rnk/" />
		<id>http://fsfoundry.org/codefreak/?p=960</id>
		<updated>2010-05-30T13:17:14Z</updated>
		<published>2010-05-30T08:31:17Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="mortal" /><category scheme="http://fsfoundry.org/codefreak" term="whining" />		<summary type="html"><![CDATA[&#8220;你怎麼在看簡體的東西!?&#8221; 不久前, 一位同事在會議中看到我在 NB 上讀到一半的一篇簡體文章, 驚訝地對我說. [1] &#8220;醒醒吧老兄. 對岸華人同胞產出的技術性文章, 不論是原創或翻譯, 不管是數量甚至很可能連質量, 都超過我們了啊.&#8221; 我心理的 OS. 是的, 我的 feed subscription 的數量: 英文 > 簡中 > 繁中. 台灣, 加油好嗎? 要了解自己, 搞清楚自己的強項面對自己的短處. 不必自大也不需自卑, 別成了井底之蛙. 是不是在開玩笑我就不知道了.你怎麼在看簡體的東西!? was first posted on May 30, 2010 at 4:31 pm.©2012 "COdE fr3@K". Use of this feed is for personal non-commercial use only. If you [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/">&lt;p&gt;&amp;#8220;你怎麼在看簡體的東西!?&amp;#8221; 不久前, 一位同事在會議中看到我在 NB 上讀到一半的一篇簡體文章, 驚訝地對我說.&lt;sup&gt; [&lt;a href="http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/#footnote_0_960" id="identifier_0_960" class="footnote-link footnote-identifier-link" title="是不是在開玩笑我就不知道了."&gt;1&lt;/a&gt;]&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;&amp;#8220;醒醒吧老兄. 對岸華人同胞產出的技術性文章, 不論是原創或翻譯, 不管是數量甚至很可能連質量, 都超過我們了啊.&amp;#8221; 我心理的 OS.&lt;/p&gt;
&lt;p&gt;是的, 我的 feed subscription 的數量: 英文 &gt; 簡中 &gt; 繁中.&lt;/p&gt;
&lt;p&gt;台灣, 加油好嗎? 要了解自己, 搞清楚自己的強項面對自己的短處. 不必自大也不需自卑, 別成了井底之蛙.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=960#comments" title="Comments on &amp;quot;你怎麼在看簡體的東西!?&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?960" alt="Comments" /&gt;&lt;/a&gt;&lt;ol class="footnotes"&gt;&lt;li id="footnote_0_960" class="footnote"&gt;是不是在開玩笑我就不知道了.&lt;/li&gt;&lt;/ol&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/"&gt;你怎麼在看簡體的東西!?&lt;/a&gt; was first posted on May 30, 2010 at 4:31 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=-wSalFm2rnk:I_sCAJmArvw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=-wSalFm2rnk:I_sCAJmArvw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[re: 解读google C++ code style谈对C++的理解]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/cJhCc-nvHts/" />
		<id>http://fsfoundry.org/codefreak/?p=937</id>
		<updated>2010-05-30T13:12:18Z</updated>
		<published>2010-05-30T08:11:25Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="commentary" /><category scheme="http://fsfoundry.org/codefreak" term="exception" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="whining" />		<summary type="html"><![CDATA[想加入這篇 解读google C++ code style谈对C++的理解 的討論. 不幸由於不明原因, 一直被系統認為是廣告 (圖中紅字部份): 先留個底, 再看看該/能怎麼辦吧. ps. cppblog 帳號申請中, 也許有帳號就沒這問題了吧? 不過, 看起來申請帳號要經過人工審核&#8230; @那谁 我不懂 Python, (没写过且只看得懂一点点) 我想你说的那份 Google 开源 的 Python &#8220;没有使用到异常&#8221; 不尽正确. 应为 &#8220;没处理异常&#8221;. 以 &#8220;class CleansedLines(object)&#8221; 的 &#8220;__init__&#8221; method 为例, 里面有对 list 的 append. 虽然我不清楚 Python list 的实作, 但我很难想像可以对任何一种 list 的实作, 不需要 memory allocation 便可对其 append N (N [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/05/30/re-%e8%a7%a3%e8%af%bbgoogle-cpp-code-style%e8%b0%88%e5%af%b9cpp%e7%9a%84%e7%90%86%e8%a7%a3/">&lt;p&gt;&lt;a href="http://fsfoundry.org/codefreak/wp-content/uploads/2010/05/Screenshot-解读google-C++-code-style谈对C++的理解-那谁的技术博客-C++博客-Mozilla-Firefox.png" rel="lightbox"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/uploads/2010/05/Screenshot-解读google-C++-code-style谈对C++的理解-那谁的技术博客-C++博客-Mozilla-Firefox-300x298.png" alt="Screenshot-解读google C++ code style谈对C++的理解 - 那谁的技术博客 - C++博客 - Mozilla Firefox" title="Screenshot-解读google C++ code style谈对C++的理解 - 那谁的技术博客 - C++博客 - Mozilla Firefox" width="300" height="298" class="aligncenter size-medium wp-image-938" align="right" hspace="10" vspace="10" /&gt;&lt;/a&gt;&lt;br /&gt;
想加入這篇 &lt;a href="http://www.cppblog.com/converse/archive/2010/05/29/116689.html" rel="nofollow"&gt;解读google C++ code style谈对C++的理解&lt;/a&gt; 的討論. 不幸由於不明原因, 一直被系統認為是廣告 (圖中紅字部份):&lt;/p&gt;
&lt;p&gt;先留個底, 再看看該/能怎麼辦吧.&lt;/p&gt;
&lt;p&gt;ps. cppblog 帳號申請中, 也許有帳號就沒這問題了吧? 不過, 看起來申請帳號要經過人工審核&amp;#8230;&lt;br /&gt;
&lt;span id="more-937"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;@那谁&lt;br /&gt;
我不懂 Python, (没写过且只看得懂一点点) 我想你说的那份 Google 开源 的 Python  &amp;#8220;没有使用到异常&amp;#8221; 不尽正确. 应为 &amp;#8220;没处理异常&amp;#8221;.&lt;/p&gt;
&lt;p&gt;以 &amp;#8220;class CleansedLines(object)&amp;#8221; 的 &amp;#8220;__init__&amp;#8221; method 为例, 里面有对 list 的 append. 虽然我不清楚 Python list 的实作, 但我很难想像可以对任何一种 list 的实作, 不需要 memory allocation 便可对其 append N (N 未知) 个 element. 一旦需要 memory allocation 就有可能失败, 也就有触发异常的可能. 只是处理与否, 那是另外一回事.&lt;/p&gt;
&lt;p&gt;小弟是你的读者, 虽然不完全同意你所有文章的看法. 回应目的为交流, 非论战.&lt;/p&gt;
&lt;p&gt;@OwnWaterloo&lt;br /&gt;
&amp;#8220;那么， 换来的结论就是： goolge中的C++程序员， 对异常这种编程思想的理解， 还不如google中的python和java程序员。&amp;#8221;&lt;/p&gt;
&lt;p&gt;对 Google 的 coding style 我也得到同样的推论, 我认为可能可以勉强说得通的两个点:&lt;br /&gt;
1. C++ 的 programmer 可能较严谨, 因此更认真看待 exception 的发生以及对应的处理方式. 而部份认真的人得到的结论是 &amp;#8220;don&amp;#8217;t do it&amp;#8221;.&lt;br /&gt;
2. C++ 的 exception 较容易导致 memory leak.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=937#comments" title="Comments on &amp;quot;re: 解读google C++ code style谈对C++的理解&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?937" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/05/30/re-%e8%a7%a3%e8%af%bbgoogle-cpp-code-style%e8%b0%88%e5%af%b9cpp%e7%9a%84%e7%90%86%e8%a7%a3/"&gt;re: 解读google C++ code style谈对C++的理解&lt;/a&gt; was first posted on May 30, 2010 at 4:11 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=cJhCc-nvHts:rVSTxkSn-DA:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=cJhCc-nvHts:rVSTxkSn-DA:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/05/30/re-%e8%a7%a3%e8%af%bbgoogle-cpp-code-style%e8%b0%88%e5%af%b9cpp%e7%9a%84%e7%90%86%e8%a7%a3/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/05/30/re-%e8%a7%a3%e8%af%bbgoogle-cpp-code-style%e8%b0%88%e5%af%b9cpp%e7%9a%84%e7%90%86%e8%a7%a3/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/05/30/re-%e8%a7%a3%e8%af%bbgoogle-cpp-code-style%e8%b0%88%e5%af%b9cpp%e7%9a%84%e7%90%86%e8%a7%a3/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[後方, 起浪了]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/TcJUlieUzZ8/" />
		<id>http://fsfoundry.org/codefreak/?p=929</id>
		<updated>2010-05-06T07:59:52Z</updated>
		<published>2010-05-04T15:54:53Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="mortal" /><category scheme="http://fsfoundry.org/codefreak" term="TM" />		<summary type="html"><![CDATA[後方的浪. 後方, 起浪了 was first posted on May 4, 2010 at 11:54 pm.©2012 "COdE fr3@K". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/05/04/%e5%be%8c%e6%96%b9-%e8%b5%b7%e6%b5%aa%e4%ba%86/">&lt;p&gt;&lt;a href="http://keikoblog.blogspot.com/2010/05/reduce-nrv-to-rv.html"&gt;後方的浪&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=929#comments" title="Comments on &amp;quot;後方, 起浪了&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?929" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/05/04/%e5%be%8c%e6%96%b9-%e8%b5%b7%e6%b5%aa%e4%ba%86/"&gt;後方, 起浪了&lt;/a&gt; was first posted on May 4, 2010 at 11:54 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=TcJUlieUzZ8:eiSZgukM0KE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=TcJUlieUzZ8:eiSZgukM0KE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/05/04/%e5%be%8c%e6%96%b9-%e8%b5%b7%e6%b5%aa%e4%ba%86/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/05/04/%e5%be%8c%e6%96%b9-%e8%b5%b7%e6%b5%aa%e4%ba%86/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/05/04/%e5%be%8c%e6%96%b9-%e8%b5%b7%e6%b5%aa%e4%ba%86/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Pic of starryalley on iThome]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/-11k8EiZWlg/" />
		<id>http://fsfoundry.org/codefreak/?p=916</id>
		<updated>2010-03-23T16:35:57Z</updated>
		<published>2010-03-23T16:35:57Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="TM" />		<summary type="html"><![CDATA[哈~ 同事 starryalley 的照片上了 iThome. Pic of starryalley on iThome was first posted on March 24, 2010 at 12:35 am.©2012 "COdE fr3@K". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/03/24/pic-of-starryalley-on-ithome/">&lt;p&gt;哈~ 同事 &lt;a href="http://starryalley.homelinux.net/blog/"&gt;starryalley&lt;/a&gt; 的照片上了 &lt;a href="http://www.ithome.com.tw/itadm/article.php?c=60147&amp;#038;s=2" rel="nofollow"&gt;iThome&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=916#comments" title="Comments on &amp;quot;Pic of starryalley on iThome&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?916" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/03/24/pic-of-starryalley-on-ithome/"&gt;Pic of starryalley on iThome&lt;/a&gt; was first posted on March 24, 2010 at 12:35 am.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=-11k8EiZWlg:d2Zlxgg8q24:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=-11k8EiZWlg:d2Zlxgg8q24:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/03/24/pic-of-starryalley-on-ithome/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/03/24/pic-of-starryalley-on-ithome/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/03/24/pic-of-starryalley-on-ithome/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Quiz on C++ Object Model]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/KgToVmlwrOY/" />
		<id>http://fsfoundry.org/codefreak/?p=878</id>
		<updated>2010-03-13T09:58:27Z</updated>
		<published>2010-03-03T16:07:05Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[這幾個月忙於工作, 這個部落格都快被我給荒廢掉了. 昨晚終於花了時間完成了一篇積了一兩個月, 說明 virtual function 在執行時期的 override 過程以及 virtual function 與 constructor/destructor 混搭結果 的文字. 今天我準備了個題目給花了時間看了它的朋友, 當作對小弟的說明能力來個測驗. 請問, 下面的 code snip 的輸出結果是什麼? 也就是說, 對同一個, 沒有被 override 過的 virtual function &#8211; Base::print_type_name &#8211; 呼叫兩次 (第一次是透過 Base 的 ctor 間接呼叫, 第二次則是當 Derived 的 object instance 直接呼叫) 的輸出是什麼? And why? 有些事情, 可以是做爽的. 而這些文字除了幫助降低自己 (主要是在工作上) 對相同主題重複一再說明的負擔, 它們還蘊藏著我的理想性 &#8211; 我衷心期望它們能夠對華文技術圈有所助益. [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/">&lt;p&gt;這幾個月忙於工作, 這個部落格都快被我給荒廢掉了. 昨晚終於花了時間完成了一篇積了一兩個月, 說明 &lt;a href="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/"&gt;virtual function 在執行時期的 override 過程以及 virtual function 與 constructor/destructor 混搭結果&lt;/a&gt; 的文字.&lt;/p&gt;
&lt;p&gt;今天我準備了個題目給花了時間看了它的朋友, 當作對小弟的說明能力來個測驗. 請問, 下面的 code snip 的輸出結果是什麼?&lt;br /&gt;
&lt;span id="more-878"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
#include &amp;lt;typeinfo&amp;gt;
#include &amp;lt;iostream&amp;gt;

using namespace std;

struct Base
{
  Base()
  {
    this-&amp;gt;print_type_name();
  }
  virtual void print_type_name()
  {
    cout &amp;lt;&amp;lt; typeid(*this).name() &amp;lt;&amp;lt; endl;
  }
};
struct Derived : Base
{
};

int main()
{
  Derived d;
  d.print_type_name();
  return 0;
}
&lt;/pre&gt;
&lt;p&gt;也就是說, 對同一個, 沒有被 override 過的 virtual function &amp;#8211; &lt;code&gt;Base::print_type_name&lt;/code&gt; &amp;#8211; 呼叫兩次 (第一次是透過 &lt;code&gt;Base&lt;/code&gt; 的 ctor 間接呼叫, 第二次則是當 &lt;code&gt;Derived&lt;/code&gt; 的 object instance 直接呼叫) 的輸出是什麼? And why?&lt;/p&gt;
&lt;p&gt;有些事情, &lt;a href="http://fsfoundry.org/codefreak/2008/10/13/foss-contrib-for-what/"&gt;可以是做爽的&lt;/a&gt;. 而這些文字除了幫助降低自己 (主要是在工作上) 對相同主題重複一再說明的負擔, 它們還蘊藏著我的理想性 &amp;#8211; 我衷心期望它們能夠對華文技術圈有所助益. 也希望我的說明能力不要太差, 讓這些文字淪落到寫爽的.&lt;/p&gt;
&lt;p&gt;Hope you have fun while figuring out the quiz.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=878#comments" title="Comments on &amp;quot;Quiz on C++ Object Model&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?878" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/"&gt;Quiz on C++ Object Model&lt;/a&gt; was first posted on March 4, 2010 at 12:07 am.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=KgToVmlwrOY:SKHrbhE3mi0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=KgToVmlwrOY:SKHrbhE3mi0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[當 Constructor 遇上 Virtual Function]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/RjKaB693FaY/" />
		<id>http://fsfoundry.org/codefreak/?p=789</id>
		<updated>2010-03-03T02:24:45Z</updated>
		<published>2010-03-02T16:19:33Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[Background 不知道你有沒有過這樣的經驗 &#8211; 想要在父類的 constructor 裏面呼叫被子類 override (或是 implement) 的 (pure) virtual function? 我試過. 跟我一樣這樣玩過的朋友, 很快就會學到它不會如你所期望的那樣運作. 如果你的期望是當建構 Derived 的 object instance 時, Derived::on_create 會被呼叫. 要是 Base::on_create 宣告成 pure virtual 的話, 你更會發現它甚至 不能 compile. 這樣的結果或許不是那麼直覺, 但背後的原因卻非常簡單 &#8211; virtual function 的 override 是發生在 object instance 被建構的時候. === mini tutorial === Class Derived 的 object layout 長得像下面這樣 (p [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/">&lt;h3&gt;Background&lt;/h3&gt;
&lt;p&gt;不知道你有沒有過這樣的經驗 &amp;#8211; 想要在父類的 constructor 裏面呼叫被子類 override (或是 implement) 的 (pure) virtual function?&lt;br /&gt;
&lt;span id="more-789"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class="brush: cpp; title: ; notranslate"&gt;
struct Base
{
  Base()
   : x(0)
  {
    on_create();
  }
  virtual void on_create() {}
  int x;
};
struct Derived : Base
{
  Derived()
   : y(1) {}
  void on_create()
  {
    // do Derived specific things
  }
  int y;
};

void foo()
{
  Derived d;
}
&lt;/pre&gt;
&lt;p&gt;我試過. 跟我一樣這樣玩過的朋友, 很快就會學到它不會如你所期望的那樣運作. 如果你的期望是當建構 &lt;code&gt;Derived&lt;/code&gt; 的 object instance 時, &lt;code&gt;Derived::on_create&lt;/code&gt; 會被呼叫. 要是 &lt;code&gt;Base::on_create&lt;/code&gt; 宣告成 pure virtual 的話, 你更會發現它甚至 &lt;a href="http://blog.roodo.com/thinkingmore/archives/11206865.html"&gt;不能 compile&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;這樣的結果或許不是那麼直覺, 但背後的原因卻非常簡單 &amp;#8211; virtual function 的 override 是發生在 object instance 被建構的時候.&lt;/p&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;strong&gt;=== mini tutorial ===&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Class &lt;code&gt;Derived&lt;/code&gt; 的 object layout 長得像下面這樣 (&lt;code&gt;p&lt;/code&gt; 為指向一 &lt;code&gt;Derived&lt;/code&gt; 的 object 的指標):&lt;/p&gt;
&lt;pre&gt;
       +---------+      +-----------------------------+
p-----&gt;|   vptr  |-----&gt;| ptr to typeinfo for Derived |
       +---------+      +-----------------------------+
       |    x    |      |      Derived::on_create     |
       +---------+      +-----------------------------+
       |    y    |
       +---------+
&lt;/pre&gt;
&lt;p&gt;由於擁有 virtual function 的原因, &lt;code&gt;Derived&lt;/code&gt; 的 object instance 在記憶體中會有一個指向其 vtable (virtual table) 的 vptr (virtual pointer).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;=== end mini tutorial ===&lt;/strong&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;h3&gt;Behind the Scenes&lt;/h3&gt;
&lt;p&gt;打開你的 &lt;a href="http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545"&gt;Inside the C++ Object Model&lt;/a&gt; 複習一下. 當我們在程式中建構一個 &lt;code&gt;Derived&lt;/code&gt; 的 object instance 時, 先被建構的是其父類 &amp;#8211; 也就是 class &lt;code&gt;Base&lt;/code&gt; 的部份 &amp;#8211; 而後, 才會建構屬於 class &lt;code&gt;Derived&lt;/code&gt; 的部份. 這過程可約略分為幾個階段:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;準備 &lt;code&gt;Base&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;起始 &lt;code&gt;Base&lt;/code&gt; 的 member, 也就是 &lt;code&gt;Base::x&lt;/code&gt;
&lt;li&gt;呼叫 &lt;code&gt;Base&lt;/code&gt; 的 constructor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Base&lt;/code&gt; 部份建構完成&lt;/li&gt;
&lt;li&gt;準備 &lt;code&gt;Derived&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;起始 &lt;code&gt;Derived&lt;/code&gt; 的 member, 也就是 &lt;code&gt;Derived::y&lt;/code&gt;
&lt;li&gt;呼叫 &lt;code&gt;Derived&lt;/code&gt; 的 constructor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Derived&lt;/code&gt; 完整建構&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;許多人可能不曉得 object 的建構還有上述階段一與階段五的 &amp;#8220;準備&amp;#8221; 工作. 這裡說的準備, 說穿了其實就是設定 object 的 vptr! 也就是說一直到程式完成步驟五之前, 這個 object 的 vptr 指向的是屬於 class &lt;code&gt;Base&lt;/code&gt; 的 vtable:&lt;/p&gt;
&lt;pre&gt;
       +---------+      +-----------------------------+
p-----&gt;|   vptr  |-----&gt;|   ptr to typeinfo for Base  |
       +---------+      +-----------------------------+
       |    x    |      |        Base::on_create      |
       +---------+      +-----------------------------+
       |    y    |
       +---------+
&lt;/pre&gt;
&lt;p&gt;完成了步驟五, 這個 object 的 vptr 才會改而指向 class &lt;code&gt;Derived&lt;/code&gt; 的 vtable. &lt;code&gt;Derived::on_create&lt;/code&gt; 正是在這個時候 override 了 &lt;code&gt;Base::on_create&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;
       +---------+      +-----------------------------+
p-----&gt;|   vptr  |--+   |   ptr to typeinfo for Base  |
       +---------+  |   +-----------------------------+
       |    x    |  |   |        Base::on_create      |
       +---------+  |   +-----------------------------+
       |    y    |  |
       +---------+  |   +-----------------------------+
                    +--&gt;| ptr to typeinfo for Derived |
                        +-----------------------------+
                        |      Derived::on_create     |
                        +-----------------------------+
&lt;/pre&gt;
&lt;p&gt;因此, 在例中 &lt;code&gt;Base&lt;/code&gt; 的 constructor (也就是表中的步驟三) 參考到的 &lt;code&gt;on_create&lt;/code&gt; 不會是被 &lt;code&gt;Derived&lt;/code&gt; override 的版本.&lt;/p&gt;
&lt;h3&gt;With a Little Twist&lt;/h3&gt;
&lt;p&gt;前面提到如果 &lt;code&gt;Base::on_create&lt;/code&gt; 被宣告成 pure virtual, 任何嘗試建構 &lt;code&gt;Derived&lt;/code&gt; 的程式將不能成功編譯.&lt;/p&gt;
&lt;p&gt;因為在這情況下, (假裝這樣的程式可以 compile 並運行) 在開始步驟三時 object 的 layout 會是像這樣:&lt;/p&gt;
&lt;pre&gt;
       +---------+      +-----------------------------+
p-----&gt;|   vptr  |-----&gt;|   ptr to typeinfo for Base  |
       +---------+      +-----------------------------+
       |    x    |      |    &amp;lt;pure virtual marker&amp;gt;    |
       +---------+      +-----------------------------+
       |    y    |
       +---------+
&lt;/pre&gt;
&lt;p&gt;Compiler 會在 class &lt;code&gt;Base&lt;/code&gt; 的 vtable 內, 原本紀錄著 &lt;code&gt;Base::on_create&lt;/code&gt; 的欄位標上一個特殊的 marker 以表示該 virtual function 為 pure virtual. 既然 pure virtual function 是不能被使用者以有意義的方式參考, 間接呼叫了 pure virtual function 的 &lt;code&gt;Derived&lt;/code&gt; 的 constructor (&lt;code&gt;Derived&lt;/code&gt; ctor -&gt; &lt;code&gt;Base&lt;/code&gt; ctor -&gt; pure virtual) 當然也是無效的.&lt;/p&gt;
&lt;h3&gt;What About Destructors&lt;/h3&gt;
&lt;p&gt;在 destructor 內呼叫 (pure) virtual function 也有完全一樣的問題. 只要把文中 object 建構的步驟反過來就可以理解其中的原因.&lt;/p&gt;
&lt;p&gt;Good night.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=789#comments" title="Comments on &amp;quot;當 Constructor 遇上 Virtual Function&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?789" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/"&gt;當 Constructor 遇上 Virtual Function&lt;/a&gt; was first posted on March 3, 2010 at 12:19 am.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=RjKaB693FaY:htI2MLHYCkU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=RjKaB693FaY:htI2MLHYCkU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/#comments" thr:count="4" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/feed/atom/" thr:count="4" />
		<thr:total>4</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[[Update] boost::decay documentation issue]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/OYHm3sBFAvU/" />
		<id>http://fsfoundry.org/codefreak/?p=797</id>
		<updated>2010-01-14T09:38:35Z</updated>
		<published>2010-01-14T09:35:01Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="boost" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="english" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[The issue with boost::decay documentation that I blogged about 10 days ago has been fixed in trunk. [Update] boost::decay documentation issue was first posted on January 14, 2010 at 5:35 pm.©2012 "COdE fr3@K". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/14/update-boost-decay-documentation-issue/">&lt;p&gt;The &lt;a href="https://svn.boost.org/trac/boost/ticket/3704"&gt;issue&lt;/a&gt; with &lt;a href="http://www.boost.org/doc/libs/1_41_0/libs/type_traits/doc/html/boost_typetraits/reference/decay.html"&gt;boost::decay documentation&lt;/a&gt; that I &lt;a href="http://fsfoundry.org/codefreak/2010/01/04/boost-decay/"&gt;blogged&lt;/a&gt; about 10 days ago has been &lt;a href="https://svn.boost.org/trac/boost/changeset/58901"&gt;fixed in trunk&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=797#comments" title="Comments on &amp;quot;[Update] boost::decay documentation issue&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?797" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/01/14/update-boost-decay-documentation-issue/"&gt;[Update] boost::decay documentation issue&lt;/a&gt; was first posted on January 14, 2010 at 5:35 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=OYHm3sBFAvU:d2je5hg-PIg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=OYHm3sBFAvU:d2je5hg-PIg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/14/update-boost-decay-documentation-issue/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/14/update-boost-decay-documentation-issue/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/14/update-boost-decay-documentation-issue/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[What Should We Teach New Software Developers? Why?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/B65c6g6vT14/" />
		<id>http://fsfoundry.org/codefreak/?p=791</id>
		<updated>2010-01-04T16:34:23Z</updated>
		<published>2010-01-04T16:29:27Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[Would you trust someone who had not seen a patient for years to teach surgery? What would you think of a piano teacher who never touched the keyboard? A CS education must bring a student beyond the necessary book learning to a mastery of its application in complete systems and an appreciation of aesthetics in [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/">&lt;blockquote&gt;&lt;p&gt;Would you trust someone who had not seen a patient for years to teach surgery? What would you think of a piano teacher who never touched the keyboard? A CS education must bring a student beyond the necessary book learning to a mastery of its application in complete systems and an appreciation of aesthetics in code.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;這句話說得真好.&lt;/p&gt;
&lt;p&gt;via: &lt;a href="http://cacm.acm.org/magazines/2010/1/55760-what-should-we-teach-new-software-developers-why/fulltext"&gt;What Should We Teach New Software Developers? Why?&lt;/a&gt; &amp;#8211; &lt;a href="http://www2.research.att.com/~bs/"&gt;Bjarne Stroustrup&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=791#comments" title="Comments on &amp;quot;What Should We Teach New Software Developers? Why?&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?791" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/"&gt;What Should We Teach New Software Developers? Why?&lt;/a&gt; was first posted on January 5, 2010 at 12:29 am.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=B65c6g6vT14:1jWGkV-s0gM:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=B65c6g6vT14:1jWGkV-s0gM:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[boost::decay documentation issue]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/Ponr5s691Ys/" />
		<id>http://fsfoundry.org/codefreak/?p=716</id>
		<updated>2010-01-14T09:37:36Z</updated>
		<published>2010-01-04T12:48:21Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="boost" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[前陣子看了 Hubert 的 一個 boost::exception 的例子, 猛然注意到自己不確定 boost::decay 的作用. 去看了它的 文件, 才發現文件不盡然正確&#8230; 已 submit 了一個 ticket 給 Boost, 希望早日修正. boost::decay documentation issue was first posted on January 4, 2010 at 8:48 pm.©2012 "COdE fr3@K". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/04/boost-decay/">&lt;p&gt;前陣子看了 Hubert 的 &lt;a href="http://blog.hubert.tw/2009/07/08/%E4%B8%80%E5%80%8B-boostexception-%E7%9A%84%E4%BE%8B%E5%AD%90/"&gt;一個 boost::exception 的例子&lt;/a&gt;, 猛然注意到自己不確定 boost::decay 的作用.&lt;/p&gt;
&lt;p&gt;去看了它的 &lt;a href="http://www.boost.org/doc/libs/1_41_0/libs/type_traits/doc/html/boost_typetraits/reference/decay.html"&gt;文件&lt;/a&gt;, 才發現文件不盡然正確&amp;#8230; 已 submit 了一個 &lt;a href="https://svn.boost.org/trac/boost/ticket/3704"&gt;ticket&lt;/a&gt; 給 Boost, 希望早日修正.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=716#comments" title="Comments on &amp;quot;boost::decay documentation issue&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?716" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/01/04/boost-decay/"&gt;boost::decay documentation issue&lt;/a&gt; was first posted on January 4, 2010 at 8:48 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=Ponr5s691Ys:pHFMF5JEMuc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=Ponr5s691Ys:pHFMF5JEMuc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/04/boost-decay/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/04/boost-decay/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/04/boost-decay/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Bit-fu]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/3Ov6yR9UVpo/" />
		<id>http://fsfoundry.org/codefreak/?p=778</id>
		<updated>2010-01-03T13:32:52Z</updated>
		<published>2010-01-03T03:40:38Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="english" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[Did you know, for x is an integer, that -~x yields x + 1 and ~-x yields x - 1? via: Advanced bit manipulation-fu. Bit-fu was first posted on January 3, 2010 at 11:40 am.©2012 "COdE fr3@K". Use of this feed is for personal non-commercial use only. If you are not reading this article in [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/03/bit-fu/">&lt;p&gt;Did you know, for &lt;code&gt;x&lt;/code&gt; is an integer, that &lt;code&gt;-~x&lt;/code&gt; yields &lt;code&gt;x + 1&lt;/code&gt; and &lt;code&gt;~-x&lt;/code&gt; yields &lt;code&gt;x - 1&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;via: &lt;a href="http://realtimecollisiondetection.net/blog/?p=78"&gt;Advanced bit manipulation-fu&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=778#comments" title="Comments on &amp;quot;Bit-fu&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?778" alt="Comments" /&gt;&lt;/a&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/01/03/bit-fu/"&gt;Bit-fu&lt;/a&gt; was first posted on January 3, 2010 at 11:40 am.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=3Ov6yR9UVpo:is6a7E4euMc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=3Ov6yR9UVpo:is6a7E4euMc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/03/bit-fu/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/03/bit-fu/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/03/bit-fu/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[2009 工作回顧]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/_8Y7nMI9K3o/" />
		<id>http://fsfoundry.org/codefreak/?p=727</id>
		<updated>2010-01-03T02:54:26Z</updated>
		<published>2010-01-02T10:35:57Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="Uncategoried" /><category scheme="http://fsfoundry.org/codefreak" term="TM" />		<summary type="html"><![CDATA[加入現在服務的公司約 20 個月了, 當然不是 (也不可能會) 所有的事情都是令人開心的. Nevertheless, I am glad that I work here. IMHO, 如果要留在台灣認真搞 software R&#038;D 與 engineering, 這裡絕對是最好的環境之一. 在這不到兩年的時間待過兩個 team 擔任技術職 &#8211; Project Lead [1], 總共只貢獻少得可憐的幾千 LOC 給我所屬的 team. 反觀上一個工作的職稱是 Senior Technical Manager [2], 在被 interview 時長官就已經講明公司期待 manager 要寫最多的 code, 當然正式在上海上崗時的確也是如此. 前後兩個工作形成有趣的強烈對比. 20 個月只貢獻幾千行 code 的技術性工作是不是太無聊了 (還是太爽了) ? 一點也不. 比起寫 code, 我花了更多時間在 [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/">&lt;p&gt;加入現在服務的公司約 20 個月了, 當然不是 (&lt;a href="http://fsfoundry.org/codefreak/2006/04/28/good-job/"&gt;也不可能會&lt;/a&gt;) 所有的事情都是令人開心的. Nevertheless, I am glad that I work here. IMHO, 如果要留在台灣認真搞 software R&amp;#038;D 與 engineering, 這裡絕對是最好的環境之一.&lt;br /&gt;
&lt;span id="more-727"&gt;&lt;/span&gt;&lt;br /&gt;
在這不到兩年的時間待過兩個 team 擔任技術職 &amp;#8211; Project Lead&lt;sup&gt; [&lt;a href="http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/#footnote_0_727" id="identifier_0_727" class="footnote-link footnote-identifier-link" title="名片上中文印的是主任工程師."&gt;1&lt;/a&gt;]&lt;/sup&gt;, 總共只貢獻少得可憐的幾千 LOC 給我所屬的 team. 反觀上一個工作的職稱是 Senior Technical Manager&lt;sup&gt; [&lt;a href="http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/#footnote_1_727" id="identifier_1_727" class="footnote-link footnote-identifier-link" title="這還是內部職稱, 名片上印的可是更響亮的 business title.  "&gt;2&lt;/a&gt;]&lt;/sup&gt;, 在被 interview 時長官就已經講明公司期待 manager 要寫最多的 code, 當然正式在上海上崗時的確也是如此. 前後兩個工作形成有趣的強烈對比.&lt;/p&gt;
&lt;p&gt;20 個月只貢獻幾千行 code 的技術性工作是不是太無聊了 (還是太爽了) ? 一點也不. 比起寫 code, 我花了更多時間在 research, design, review 他人的 design, 幫助別人 review 我的 design, code review, 與 QA co-work 以確保產出的品質, 到 release 後的 defect tracking&amp;#8230; 等等.&lt;/p&gt;
&lt;p&gt;還記得在面試時 hiring manager 問我 &amp;#8211; &amp;#8220;你為什麼想加入這間公司?&amp;#8221;. 我回說 &amp;#8211; &amp;#8220;朋友告訴我這裡可能是台灣最認真做軟體的公司, 而我想見識這邊的 development process 與體驗這樣的企業文化.&amp;#8221; And I have to say, I&amp;#8217;ve got what I came for.&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;以下為廣告&amp;#8230;&lt;/p&gt;
&lt;p&gt;We are hiring! 我們在找熱愛挑戰的 team player. 如果你需要個能發揮並被 appreciate 的舞台, 請參考 &lt;a href="http://fsfoundry.org/codefreak/2009/05/07/new-job-openings-at-work/"&gt;上次的廣告&lt;/a&gt;. 有興趣的朋友請與我連絡.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=727#comments" title="Comments on &amp;quot;2009 工作回顧&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?727" alt="Comments" /&gt;&lt;/a&gt;&lt;ol class="footnotes"&gt;&lt;li id="footnote_0_727" class="footnote"&gt;名片上中文印的是主任工程師.&lt;/li&gt;&lt;li id="footnote_1_727" class="footnote"&gt;這還是內部職稱, 名片上印的可是更響亮的 business title. &lt;img src='http://fsfoundry.org/codefreak/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /&gt; &lt;/li&gt;&lt;/ol&gt;&lt;hr style="border-top:black solid 1px" /&gt;&lt;a href="http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/"&gt;2009 工作回顧&lt;/a&gt; was first posted on January 2, 2010 at 6:35 pm.&lt;br /&gt;©2012 "&lt;a href="http://fsfoundry.org/codefreak"&gt;COdE fr3@K&lt;/a&gt;". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at freak@fsfoundry.org&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=_8Y7nMI9K3o:I30uTtFbdMI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=_8Y7nMI9K3o:I30uTtFbdMI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/</feedburner:origLink></entry>
	</feed>

