首页 > doc > namingconvention 
 en fr de es it nl pl pt pt_BR mk sq ca hu cs tr ar fa id vi ko ja ru zh_TW eo
前一个  下一个  编辑  重命名  撤销  刷新  搜索  管理  
文档
历史
 
警告! 该页面尚未更新。  参见英文版 
Variable calling convention
变量命名约定
作者:Fabien Bodard

It's simply how you give name to your variables ! What 方法, to make difference between to type of variables or to type of objects.

你需要采用一个约定

 If you call each 变量, according to the impultion of the moment, not only you will have names that you don't remember, but you will search astute variable name at place of seaching astute algorithms. A calling convention need to be automatic. In fact, two person that use the same calling convention would have the same variables name.

Most of the time, bad calling convention goes from pair with a bad code.

By default, Gambas give a default name to the widgets, like button1, textbox1, etc... and then incrementing the value when you add a new 组件 in the IDE. But the problem with this system is that your code is really difficult to interpret or to debug...

But all is not lost at this time... i've maybe a soluce for you :-).

The hungarian convention for Gambas

The hungarian convention is a good one. You have probably seen this convention in some Microsoft Visual Basic exemples sources. I don't say it's the better one, but i've use it in some other languages php, fortran, and it got fine on Gambas.

All the users of the hungarian convention that i know have in a first time hated it. But whatever your opinion is, you will not regret having learned to read Hungarian. This convention was created by Charle Simonyi, veteran of developement at Microsoft and and Hungarian of birth. It implies that the variables comprises two parts: a basic type in small letters indicating the kind of 变量, and a qualifier with initial in capital letter which distinguishes a variable of the other of the same variables. Then you can a letter like $ at the end to distingish the global variables.

Example

An integer variable that will be used to locate something
iPos

An integer variable that will be used to locate something in a file and another in a textarea
iFilePos
iLinePos

A form for save a file as...
frmSaveFileAs



普通变量类型前缀约定

变量类型 前缀
Integer i
Float f
Boolean b
Byte bt
Short sh
Long l
Single sng
Variant v
Pointer ptr
String s
Date date
Object o

数组或集合变量类型前缀约定

变量类型 前缀
Static array ar + type prefix
Integer[] ari
Float[] arf
Boolean][] arb
Byte][] arbt
Short[] arsh
Long[] arl
Single[] arsng
Variant[] arv
String[] ars
Date[] ardate
Object[] aro
Collection col

特殊类型

变量类型 前缀
File fi
Process proc

一些组件前缀示例

变量类型 前缀
Form frm
TextBox txtb
TextArea txta
ListBox lstb
ComboBox cbo
Timer tmr
Button but
ToggleButton tglbut
ToolButton tbut