Root of All Evil – Defining Variables Early
Posted on November 7th, 2010 at 23:05 by fr3@K

Before we dive into the topic of this post, I would like to share with you the best possible advise I could ever give – 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 practice. Am I not asking you do what I tell you? No, I am not.

I am asking you to think and to reason consciously why you chose to code something the way you did.

In the first post 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 – hurting code readability.

It is important that we understand a best practice is anything but the law. When circumstances change, it may not stand.

I ask you to think as you code.

Now, back to the topic. In this post, we will revisit a well known best practice from a less discussed perspective. (more…)

del.icio.us:Root of All Evil - Defining Variables Early digg:Root of All Evil - Defining Variables Early spurl:Root of All Evil - Defining Variables Early newsvine:Root of All Evil - Defining Variables Early furl:Root of All Evil - Defining Variables Early Y!:Root of All Evil - Defining Variables Early 黑米共享書籤:Root of All Evil - Defining Variables Early 推推王:Root of All Evil - Defining Variables Early
Function overloading by return type
Posted on November 2nd, 2010 at 0:07 by fr3@K

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’t insist on using different naming schemes to name classes from functions consistently.

Hey, sometimes, objects are functions and functions are objects.

del.icio.us:Function overloading by return type digg:Function overloading by return type spurl:Function overloading by return type newsvine:Function overloading by return type furl:Function overloading by return type Y!:Function overloading by return type 黑米共享書籤:Function overloading by return type 推推王:Function overloading by return type
Root of All Evil – Nasty If Else blocks
Posted on October 31st, 2010 at 17:18 by fr3@K

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, I am starting a series of posts called “Root of All Evil”. 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:

  • What does bad code look like
  • Why is it bad
  • And how it could be improved/refactored

If you happen to care reading my blog, chances are you won’t be contributing too many of those. However, even if they were someone else’s responsibility, it is essential that you I encourage you to 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.

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. (more…)

del.icio.us:Root of All Evil - Nasty If Else blocks digg:Root of All Evil - Nasty If Else blocks spurl:Root of All Evil - Nasty If Else blocks newsvine:Root of All Evil - Nasty If Else blocks furl:Root of All Evil - Nasty If Else blocks Y!:Root of All Evil - Nasty If Else blocks 黑米共享書籤:Root of All Evil - Nasty If Else blocks 推推王:Root of All Evil - Nasty If Else blocks
Re: 你怎麼在看簡體的東西!?
Posted on August 8th, 2010 at 23:54 by fr3@K

Hi Sam,

你的 留言 讓我想了許久. 小弟以為, 原創的繁中技術文字過少的最大關鍵不在於書籍市場, 而在寫的動機. 只要找到非金錢回報的動機, 就能寫得下去. 畢竟, 這是個屬於網路的年代, 只要有心有料, 甚至只要自 high, 誰都可以發表.

我們都在這片土地上生活, 在這個業界燃燒熱血, 盼望能實現自己的夢想. 以我為例, 我的夢想是台灣能有個健康前瞻有搞頭的軟體產業. 讓我們不一定要離鄉背井, 才能夠免去賣肝的宿命, 可以好好賣腦揮撒我們的熱情展現我們的專業, 並且得到適當的回報.

我很清楚, 在這個大環境, 我的想法多少不太現實. 即便如此, 除了抱怨, 我還選擇盡一點微薄的力量. 這個部落格能還能活著, 最大的動力正是對這個夢想的執著.

你的夢想是什麼?

[後記] 這篇文字是在抒發我的牢騷, 非針對個人. Sam, 不好意思借用了你的名字…

del.icio.us:Re: 你怎麼在看簡體的東西!? digg:Re: 你怎麼在看簡體的東西!? spurl:Re: 你怎麼在看簡體的東西!? newsvine:Re: 你怎麼在看簡體的東西!? furl:Re: 你怎麼在看簡體的東西!? Y!:Re: 你怎麼在看簡體的東西!? 黑米共享書籤:Re: 你怎麼在看簡體的東西!? 推推王:Re: 你怎麼在看簡體的東西!?
Did You Know, “new (nothrow) T” Throws?
Posted on August 1st, 2010 at 20:08 by fr3@K

可能會出乎不少人的意料, 下面的 code snip 可能會拋出 exception.

    Listing-1.

    using namespace std;
    T* new_t_nothrow()
    {
      return new (nothrow) T;
    }
    

(more…)

del.icio.us:Did You Know,  digg:Did You Know,  spurl:Did You Know,  newsvine:Did You Know,  furl:Did You Know,  Y!:Did You Know,  黑米共享書籤:Did You Know,  推推王:Did You Know,
You Don’t Have to Resort to Goto
Posted on June 19th, 2010 at 22:35 by fr3@K

你一定看過這樣的 code:

    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;
    }
    

可讀性差的巢狀 if block, 只為了堅持由一處 return.
(more…)

del.icio.us:You Don't Have to Resort to Goto digg:You Don't Have to Resort to Goto spurl:You Don't Have to Resort to Goto newsvine:You Don't Have to Resort to Goto furl:You Don't Have to Resort to Goto Y!:You Don't Have to Resort to Goto 黑米共享書籤:You Don't Have to Resort to Goto 推推王:You Don't Have to Resort to Goto
華碩品質, 以卵擊石
Posted on June 2nd, 2010 at 1:24 by fr3@K

很多人可能已經沒印象了. 但我記得很清楚.

去年 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 – and smear Linux.

(more…)

del.icio.us:華碩品質, 以卵擊石 digg:華碩品質, 以卵擊石 spurl:華碩品質, 以卵擊石 newsvine:華碩品質, 以卵擊石 furl:華碩品質, 以卵擊石 Y!:華碩品質, 以卵擊石 黑米共享書籤:華碩品質, 以卵擊石 推推王:華碩品質, 以卵擊石
你怎麼在看簡體的東西!?
Posted on May 30th, 2010 at 16:31 by fr3@K

“你怎麼在看簡體的東西!?” 不久前, 一位同事在會議中看到我在 NB 上讀到一半的一篇簡體文章, 驚訝地對我說.

“醒醒吧老兄. 對岸華人同胞產出的技術性文章, 不論是原創或翻譯, 不管是數量甚至很可能連質量, 都超過我們了啊.” 我心理的 OS.

是的, 我的 feed subscription 的數量: 英文 > 簡中 > 繁中.

台灣, 加油好嗎? 要了解自己, 搞清楚自己的強項面對自己的短處. 不必自大也不需自卑, 別成了井底之蛙.

del.icio.us:你怎麼在看簡體的東西!? digg:你怎麼在看簡體的東西!? spurl:你怎麼在看簡體的東西!? newsvine:你怎麼在看簡體的東西!? furl:你怎麼在看簡體的東西!? Y!:你怎麼在看簡體的東西!? 黑米共享書籤:你怎麼在看簡體的東西!? 推推王:你怎麼在看簡體的東西!?
re: 解读google C++ code style谈对C++的理解
Posted on May 30th, 2010 at 16:11 by fr3@K

Screenshot-解读google C++ code style谈对C++的理解 - 那谁的技术博客 - C++博客 - Mozilla Firefox
想加入這篇 解读google C++ code style谈对C++的理解 的討論. 不幸由於不明原因, 一直被系統認為是廣告 (圖中紅字部份):

先留個底, 再看看該/能怎麼辦吧.

ps. cppblog 帳號申請中, 也許有帳號就沒這問題了吧? 不過, 看起來申請帳號要經過人工審核…
(more…)

del.icio.us:re: 解读google C++ code style谈对C++的理解 digg:re: 解读google C++ code style谈对C++的理解 spurl:re: 解读google C++ code style谈对C++的理解 newsvine:re: 解读google C++ code style谈对C++的理解 furl:re: 解读google C++ code style谈对C++的理解 Y!:re: 解读google C++ code style谈对C++的理解 黑米共享書籤:re: 解读google C++ code style谈对C++的理解 推推王:re: 解读google C++ code style谈对C++的理解
後方, 起浪了
Posted on May 4th, 2010 at 23:54 by fr3@K

後方的浪.

del.icio.us:後方, 起浪了 digg:後方, 起浪了 spurl:後方, 起浪了 newsvine:後方, 起浪了 furl:後方, 起浪了 Y!:後方, 起浪了 黑米共享書籤:後方, 起浪了 推推王:後方, 起浪了

Page 1 of 24[ 1 ]23451020...Oldest