本文介绍了Fxxx私有类名称前缀约定来自哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++ / C#中,私有类vars的通用约定是 m_MyPrivateVar ,我相信 m _ 代表我的可能是错误的)。

In C++/C# the common convention for private class vars is m_MyPrivateVar, and I belive "m_" stands for "my" (I might be wrong).

在Delphi中,私有类变量以 F 开头,例如FHandle等。

In Delp private class variables begin with F, e.g. FHandle etc.

F是什么意思?好吗:

What does the F means? Foo? :)

推荐答案

有一些命名约定不会丢失代码。

There are some naming conventions not to get lost in code.

这是一个例子,指出为什么这是有用的。

Here is an example to point out why this is useful.

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

这篇关于Fxxx私有类名称前缀约定来自哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 03:27