Tag Archive: cited


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. View full article »

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.

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. View full article »

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

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

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

後方的浪.

The issue with boost::decay documentation that I blogged about 10 days ago has been fixed in trunk.

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.

這句話說得真好.

via: What Should We Teach New Software Developers? Why?Bjarne Stroustrup.

前陣子看了 Hubert 的 一個 boost::exception 的例子, 猛然注意到自己不確定 boost::decay 的作用.

去看了它的 文件, 才發現文件不盡然正確… 已 submit 了一個 ticket 給 Boost, 希望早日修正.

Bit-fu

Did you know, for x is an integer, that -~x yields x + 1 and ~-x yields x - 1?

via: Advanced bit manipulation-fu.

elleryq 這篇 blog post 談到的 ctor (換成 dtor 也一樣) 呼叫 virtual function 狀況 (或說是 problem) 會是很好的 C++ programmer 面試題目. 可在口試時用以窺探 interviewee 對 C++ object model 的了解.
View full article »