Sutter on Hungarian Notation
Posted on August 18th, 2008 at 16:10 by fr3@K

From Sutter’s Mill:

… The main trouble with Systems Hungarian comes from trying to embed information about a variable’s type into the variable’s name by prepending an encoded wart like the venerable sz, pach, ul, and their ilk. Although potentially helpful in a weakly-typed language like C, that’s known to be brittle and the prefixes tend to turn into lies as variable types morph during maintenance. The warting systems also don’t extend well to user-defined types and templates.

I am glad to learn that the Guru and I share similar views on this matter.


Further readings:

del.icio.us:Sutter on Hungarian Notation digg:Sutter on Hungarian Notation spurl:Sutter on Hungarian Notation newsvine:Sutter on Hungarian Notation furl:Sutter on Hungarian Notation Y!:Sutter on Hungarian Notation 黑米共享書籤:Sutter on Hungarian Notation 推推王:Sutter on Hungarian Notation
Exception Handling 新思維
Posted on August 18th, 2008 at 0:38 by fr3@K

New mind set

一直以來 exception handling 與 exception safety 就是 C++ 最重要的課題之一. 正確的 exception handling 真的不是一件跟吃蛋糕一樣容易的事.

但, 它是否一定如此困難, 以致於 只有語言專家才能搞得定? 我認為這與事實相去甚遠.
(more…)

del.icio.us:Exception Handling 新思維 digg:Exception Handling 新思維 spurl:Exception Handling 新思維 newsvine:Exception Handling 新思維 furl:Exception Handling 新思維 Y!:Exception Handling 新思維 黑米共享書籤:Exception Handling 新思維 推推王:Exception Handling 新思維
GION 0.1.0 Released
Posted on July 15th, 2008 at 0:40 by fr3@K

GION is a project I recently created as a part of my effort towards cleaning-up some of the not-so-pretty and strengthening exception safety of the project code base at work.

It’s released under one of the most permissive FOSS licenses I know of, MIT license, in hope, would help others to write better C++ more easily.

Feedback welcomed.

del.icio.us:GION 0.1.0 Released digg:GION 0.1.0 Released spurl:GION 0.1.0 Released newsvine:GION 0.1.0 Released furl:GION 0.1.0 Released Y!:GION 0.1.0 Released 黑米共享書籤:GION 0.1.0 Released 推推王:GION 0.1.0 Released
C++0x, Near Feature-Complete
Posted on July 8th, 2008 at 19:48 by fr3@K

From Sutter’s Mill:

… we already had a nearly-complete C++0x internal working draft — most features that will be part of C++0x had already been “checked in.” Only a few were still waiting to become stable enough to vote in, including initializer lists, range-based for loops, and concepts.

del.icio.us:C++0x, Near Feature-Complete digg:C++0x, Near Feature-Complete spurl:C++0x, Near Feature-Complete newsvine:C++0x, Near Feature-Complete furl:C++0x, Near Feature-Complete Y!:C++0x, Near Feature-Complete 黑米共享書籤:C++0x, Near Feature-Complete 推推王:C++0x, Near Feature-Complete
Google Forbids Use of Exception in C++
Posted on July 6th, 2008 at 23:57 by fr3@K

Quote from Google C++ Style Guide:

We do not use C++ exceptions.

在極端狀況下, 我能想像在 no virtual function 或是 no templates 但仍能使用 STL 的環境寫 C++. 但完全禁止 user-defined classes/functions 以拋出 exception 的方式回報錯誤的環境呢? No, thanks. 即便有免費的食物與漂亮的辦公室, 這還是太折磨人了.
(more…)

del.icio.us:Google Forbids Use of Exception in C++ digg:Google Forbids Use of Exception in C++ spurl:Google Forbids Use of Exception in C++ newsvine:Google Forbids Use of Exception in C++ furl:Google Forbids Use of Exception in C++ Y!:Google Forbids Use of Exception in C++ 黑米共享書籤:Google Forbids Use of Exception in C++ 推推王:Google Forbids Use of Exception in C++
Containers with Stateful Allocator, a Bug in C++98
Posted on June 8th, 2008 at 15:02 by fr3@K

前一陣子花了些時間寫一個 allocator library. 首要目標就是要能符合 C++ Standard 對 allocator 定義的 requirement. 當然也要相容於 Standard C++ Library 的 container 實作, 能與所有的 container function 正確的 inter-operate. 在這個過程中, 我意外地一腳踏進又一個 C++ 的陰暗角落.

先讓我把這個有點嚇人的結論寫在前面:

    你所使用的標準 container , 很可能無法完全正確地與 object-stateful 的 allocator 一起運作. 即便該 allocator 確實是符合標準規範的.

不過先別慌. 只要拿來與 container 搭配使用的是沒有 per instance 狀態的 allocator, 你就不會遭遇本文所討論的問題.

(more…)

del.icio.us:Containers with Stateful Allocator, a Bug in C++98 digg:Containers with Stateful Allocator, a Bug in C++98 spurl:Containers with Stateful Allocator, a Bug in C++98 newsvine:Containers with Stateful Allocator, a Bug in C++98 furl:Containers with Stateful Allocator, a Bug in C++98 Y!:Containers with Stateful Allocator, a Bug in C++98 黑米共享書籤:Containers with Stateful Allocator, a Bug in C++98 推推王:Containers with Stateful Allocator, a Bug in C++98
Why Const Matters
Posted on May 31st, 2008 at 16:51 by fr3@K

假設我們需要按照順序以紙條對 Alice 與 Bob 打招呼:

    void Alice(string& message_to_alice);
    void Bob(const string& message_to_bob);
    

(more…)

del.icio.us:Why Const Matters digg:Why Const Matters spurl:Why Const Matters newsvine:Why Const Matters furl:Why Const Matters Y!:Why Const Matters 黑米共享書籤:Why Const Matters 推推王:Why Const Matters
Do Things the Standard Style
Posted on May 28th, 2008 at 1:28 by fr3@K

見過不少 C/C++ Standard Library 的不愛用者. 要辨認他們並不困難, 從 code 中可以很容易發現:

  1. 在 header file 以 #pragma once 替代標準 inclusion guard 手法
  2. 將一個 const long* 宣告為 CONST LPLONG
  3. 習慣性使用 ZeroMemory/bzeroCopyMemory/bcopy, 而 (無意間?) 迴避 memsetmemcpy 等標準 API

除了省去替 inclusion guard 取有效 (唯一) 名字的功夫之外, 我實在是看不出上述習慣有任何實質上的好處.
(more…)

del.icio.us:Do Things the Standard Style digg:Do Things the Standard Style spurl:Do Things the Standard Style newsvine:Do Things the Standard Style furl:Do Things the Standard Style Y!:Do Things the Standard Style 黑米共享書籤:Do Things the Standard Style 推推王:Do Things the Standard Style
Strong Guarantee using Transaction
Posted on April 29th, 2008 at 23:24 by fr3@K

Abrahams Guarantees

在 C++ 的世界裡, 正確的 exception handling 是專業的 C++ programmer 不可或缺的技巧. 雖然它的概念並不困難, 但實作起來卻常不見得那麼容易.

要做到正確的 exception handling, 首先必須要了解什麼是 exception safety. 一個需要與 exception 打交道的 component 可在其介面實作人稱 Abrahams guarantees 的三種 exception safety 保證之一:

  1. The basic guarantee
  2. 允許操作失敗時改變物件的狀態, 但不能有 resource leak. 且該物件的狀態必須是可靠的仍然可以被解構, 操作失敗後該物件的狀態可以是不完全能被預測的.

  3. The strong guarantee
  4. 操作後的狀態只能是成功完成, 或是將該物件回復到操作之前的狀態並拋出一個 exception.

  5. The no-throw guarantee
  6. 操作不會拋出 exception.

(more…)

del.icio.us:Strong Guarantee using Transaction digg:Strong Guarantee using Transaction spurl:Strong Guarantee using Transaction newsvine:Strong Guarantee using Transaction furl:Strong Guarantee using Transaction Y!:Strong Guarantee using Transaction 黑米共享書籤:Strong Guarantee using Transaction 推推王:Strong Guarantee using Transaction
re: Socket Programming in C 常犯的錯誤
Posted on April 22nd, 2008 at 12:25 by fr3@K

昨天在網上閒逛, 在樂多上看到篇名為 “Socket Programming in C 常犯的錯誤” 的短文. 這短文作者的動機很好, 指出常見到的錯誤並提供個人看法與可能較好的作法. 這樣的行為很值得鼓勵. 但極可惜的是, 結果卻是很不理想的. 容我說句重話, 如果是考試的話該文是得不到我的分數的.
(more…)

del.icio.us:re: Socket Programming in C 常犯的錯誤 digg:re: Socket Programming in C 常犯的錯誤 spurl:re: Socket Programming in C 常犯的錯誤 newsvine:re: Socket Programming in C 常犯的錯誤 furl:re: Socket Programming in C 常犯的錯誤 Y!:re: Socket Programming in C 常犯的錯誤 黑米共享書籤:re: Socket Programming in C 常犯的錯誤 推推王:re: Socket Programming in C 常犯的錯誤

Page 1 of 4[ 1 ]234»