2013-01-10 28 views
7

Trong C++/C# quy ước chung cho các lớp riêng tư là m_MyPrivateVar và tôi tin "m_" là viết tắt của "my" (có thể tôi đã sai).Quy ước tiền tố tên lớp Fxxx riêng đến từ đâu?

Trong Delphi, biến lớp học riêng tư bắt đầu bằng F, ví dụ: FHandle, v.v.

F có nghĩa là gì? Foo? :)

+9

... field ..... –

+0

@SertacAkyuz, bạn có chắc không ??? :) – Vlad

+3

Oh yes he is :) – whosrdaddy

Trả lời

17

Có một số quy ước đặt tên không bị mất trong mã.

Dưới đây là ví dụ để chỉ ra lý do tại sao điều này hữu ích.

// Types begins with T 
TFoo = class 
strict private 
    // sometimes I saw strict private fields beginning with underscore 
    // I like this too 
    _Value : string; 
private 
    // private class vars are Fields and therefore begins with F 
    FValue : string; 
    function GetValue : string; 
public 
    property Value : string read GetValue write FValue; 

    // Parameters should NOT begin with P (P is for Pointer) but with A 
    // because "i will pass A value" :o) 
    function GetSomething(const AValue : string) : string; 
end; 

function TFoo.GetValue : string; 
begin 
    Result := '*' + FValue + '*'; 
end;  

function TFoo.GetSomething(const AValue : string) : string; 
var 
    // IMHO there is no naming convention to Local vars 
    // but mine begins with L 
    LValue : string; 
begin 

    LValue { local var } := 
    Value { property via getter } + 
    AValue { parameter } + 
    FValue { field }; 

    Result := LValue; 
end; 
+1

.Douze points !. – Vlad

+16

"A" trong tham số đến từ "Đối số". –

Các vấn đề liên quan