Jump to content

Naming Conventions


Recommended Posts

Hello everybody,

A new user here. I just found out AutoIT last week and I'm so excited about it! Can't wait to convert all of my batch files to au3. Anyways, just wondering if anybody have suggestions/recommendations on AI variable and function naming conventions (ie., prepend data type on variable name, prepend return type on function name)

Appreciate any help!

-MX

Link to comment
Share on other sites

Interesting question, especially with GUI-creation ability in the new "unstable" betas

AutoIt is not case sensitive, so $VAR, $Var, and $var can be used interchangably.

AutoIt does not have true data types, so numbers and strings and booleans can be user interchangably. I guess you could put the type at the beginning if you want: $intX, $int_x and so on

With GUI stuff, I might say $checkbox_Whatever or $checkboxRef.

"Constants" are usually denoted with all caps and underscores to separate the words. For example, $GUI_ENABLE

Many people put an underscore at the beginning of user-defined functions to disginguish them from built-in functions:

_WinCenter("Untitled1 - Notepad", "")
Exit
Func _WinCenter($title, $text)
 ;body of function goes here
EndFunc

Hope this rambling makes some sense.

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

I use a rather loose naming convention as follows:

$aName - An array

$szName - A string

$nName - A number

$hName - A "handle", file functions and using HWND's with window functions

$oName - An "object". Normally I use this when getting a return value from a GUI creation function.

Some special cases are global variables. I prepend g_ to those. Also, if writing a library, I might use __m_ as the prefix to try to minimize name clashes.

Your own personal taste is really all it is. I try to make my names descriptive so I can look at it and know what it represents and what type of data to expect. The less I have to think, the better.

I wish more people actually cared enough about a naming convetion. I just love trying to read scripts with stupidly named variables that have no relation to what they are even used for.

Link to comment
Share on other sites

Seems my own conventions are very similar to Valik's, and I also like the idea employed in some of the examples for User Defined Functions: to prepend UDFs with an underscore: _DoThisOrThat()

Mostly cos this helps them to be highlighted nicely in Textpad (my editor of choice)

HTH :D

Link to comment
Share on other sites

Thanks for everyone's input! I appreciate it. I ended up with the following naming conventions. Some of them are taken from Windows Scripting Doc (v5.6). Suggestions and comments are always welcome.

Thanks,

-MX-

Standard Data Types

Subtype Prefix Example

------- ------ -----------

integer int intQuantity

string str strFirstName

boolean bln blnFound

array arr arrNumbers

handle hdl hdlFile

byte byt bytRasterData

float flt fltAmount

GUI Controls

Subtype Prefix Example

------- ------ -----------

label lbl lblStude

button cmd cmbOk

group frm frmType

checkbox chk chkState

radio opt optStatus

combo cbo cboStype

list lst lstDays

pic pic picEmployee

icon ico icoTravel

edit mem memComments

input txt txtLastName

date dtm dtmEnroll

progress prg prgStatus

avi avi

tab tab tabConnect

updown udb

window wnd wndMain

User Define Function

_<return-type><func-name>

where: <return-type> - any of the following standard data prefix above

Link to comment
Share on other sites

Nice list :D Maybe some things to consider:

boolean bln? "bool" looks better in my opinion

byte byt? why abbreviate byte?

float flt? I might vote for "real" over "flt"

radio opt: This might cause confusion with the Opt() function [AutoItSetOption]

edit mem? Interesting choice... Is it short for "memo" or what?

date dtm? again, wouldn't abbreviate 4-letter words

updown udb? I might choose upd

tab: You might also want a prefix for tabitems. The tab control is simply a container for tabitems

I also find it useful for a variable name to indicate if it is a paramter to a function. For example, a the Win__() AutoIt functions have "title" and "text" arguments; so I use variables with these keywords as part of their names.

Just my 2 cents.

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Thanks for the suggestions! I appreciate it. When I was doing this, I was trying to stick to just 3 letters for the prefix, trying to be consistent :D

bln & byt are from VBS doc, flt (float) is something that I added. I think "float" is from C/C++ if I'm not mistaken. I did C before but that was a long time ago.

Yes, mem is short for memo, udb is for updown bar but I think upd is better. Have to come up with naming conventions for tabitems and radio buttons.

Thanks again,

-MX-

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...