Tag Archive: C


早上在 OSDC.TW 分享的 A Brief Introduction to C++11 投影片.

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.

你一定看過這樣的 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.
View full article »

Preamble

Microsoft 的 MFC 是最早被大量採用 (massive adoption) 的 C++ library 之一. 等到我開始接觸 C++ Standard Library 這東西都已經是玩了兩年 MFC 以後的事. 還記得, 從一開始對 MFC 的讚嘆與擁抱, 幾年後對它的不屑, 到更後來的理解 (理解不好其實也是有原因的).

即便不少 programmer 知道 MFC 是一套瑕疵遍佈的 library, 可能也知道那些地方有問題. 但它以及部份其他 library 聯手對於更多 C++ programmer 造成的傷害已經留下不容易抹滅的痕跡. 它讓許多 programmer 以為這些東西本來就該這樣 (that’s the way things supposed to be), 當有一天這些被誤導的 programmer 有機會可以選擇另一套 library 或是自行設計的時候, 很容易就陷入 MFC 帶給他們已先入為主的錯誤觀念.

View full article »