From Xojo Documentation
Every developer and team should have coding guidelines to help ensure that code is readable by everyone on the team (or even yourself several months from now). There is no such thing as coding guidelines that everyone will agree with, but the guidelines described here are meant to be a starting point and match the coding guidelines generally used for the Xojo example projects and sample code that you see here in the Dev Center.
The most important thing is consistency, regardless of what guidelines you choose to use. Inconsistent code is more difficult to understand.
|camel case||The first "word" in the name is lower cased. Subsequent "words" are started with an upper case letter: customerName|
|title case||All "words" in the name are started with an upper case letter: CustomerName|
Having a consistent way to name the things in your project is an important first step in coding standards. Ideally coding standards will help others write correct code more easily and grasp existing code more readily.
- Start with lower case "k", followed by title case: kMaxUsers.
- Use camel case: Dim customerName As Text
- Minimize use of abbreviations; spell things out. Use customerName, not custNm.
- Use of single-letter variables names are acceptable for looping variables, such as used by For loops.
- Should be plural: Customers() As Text
- Use title case: CustomerName
- A Private property that is the companion for a Computed Property should start with "m" and then be title case: mCustomerName.
- Use title case: SaveCustomer
- Method parameters should be camel case: SaveCustomer(customerName As Text)
- Use title case, with a suffix indicating the type of control: OKButton. Below are some common suffixes:
|PushButton, WebButton, iOSButton, BevelButton||Button||SaveButton|
|SegmentedButton, WebSegmentedControl, iOSSegmentedControl||Selector||TaskSelector|
|TextField, WebTextField, iOSTextField||Field||NameField|
|TextArea, WebTextArea, iOSTextArea||Area||DescriptionArea|
|Canvas, WebCanvas, iOSCanvas||Canvas||GraphCanvas|
|Label, WebLabel, iOSLabel||Label||NameLabel|
|ProgressWheel, ProgressBar, WebProgressWheel, WebProgressBar, iOSProgressBar, iOSProgressWheel||Progress||DownloadProgress|
|HTMLViewer, WebHTMLViewer, iOSHTMLViewer||Viewer||DocViewer|
|ImageWell, WebImageView, iOSImageView||Image||ProfileImage|
- Use title case.
- Subclasses of built-in classes should use original class name as suffix: CustomerListBox.
- Use title case with "Window" as the suffix: CustomerWindow.
- Use title case with "Interface" suffix.
- Keywords should be in title case:
- Data types should be in title case:
- Put spaces between all lists of arguments or parameters: SaveCustomer(name, location, value)
- Do not put spaces before or after parenthesis.
- Methods called without parameters should not include empty parenthesis. Use: MyMethodinstead of:MyMethod()
- Methods with parameters should always include parenthesis. Use: MyMethod(42)instead of:MyMethod 42
- Leave blank lines between code lines as appropriate to maintain readability.
- SQL commands are written in uppercase:
SELECT * FROM Team WHERE City = "Boston"
- Dim local variables near where they will be used with one declaration per line.
- Methods not used outside the class/module should be Private.
- Prefer dot notation over equivalent global methods when possible: Dim length As Integer = customerName.Len
- Never use Me when you mean Self.
- Limit globals.
- Prefer shared methods/properties on classes over global methods/properties on modules.
- Classes, methods, properties, etc., within a Module or Class should be Private or Protected where possible.