mickelson / attract

A graphical front-end for command line emulators that hides the underlying operating system and is intended to be controlled with a joystick or gamepad.
http://attractmode.org
GNU General Public License v3.0
393 stars 115 forks source link

Good conventions #648

Open keilmillerjr opened 4 years ago

keilmillerjr commented 4 years ago

Searching for good conventions that a few of us can use to keep consistency and readability. There is no perfect solution. However, settling on a particular convention will make things easier. Below are some ideas. Let me know what you guys think. Is one method better than another? Can edit this post appropriately based on feedback. I am new with git, and will need help with this section.

This issue is a WIP.

Coding Squirrel

Some links for consideration:

File Specifications

LF line endings will be used. It is supported by UNIX (Linux and Mac OS X), as well as properly viewable/editable within notepad on Windows 10 1809+ (only took 33 years!). If your editor does not support changing line endings, use endlines. I created an AUR package of endlines for Arch Linux users.

Comments

// Single line comments above referencing code
local x = null

Statements

Squirrel 3.0 Reference Manual - Statements

// Preferred single line statement
x = null

// Semi-colons can effect readability
x = null

Spaces

// A single space should separate a keyword and brackets.
local x = [ "Bar", "Eek" ]

// A single space should separate a keyword and parenthesis.
if ( x != null )
{

}

Indentations

Spaces retain presentation across screens. Tabs conserve file size and allow your code editor to handle presentation preference. We will use tabs instead of spaces.

Blocks

Blocks in squirrel are indicated by use of curly braces. The preceding curly brace may be placed on the same line (conserving file size), or the following line by itself (visually lining up with proceeding brace). The latter would match the style seen with C in this repository and should be used.

if ( x != null )
{

}

Variable Names

// Variable names should use lower camel case
local someVariable = null

// Static immutable variables should use uppercase
static STATIC_VARIABLE = "This will not change."

Tables

In squirrel 3.0, it is possible to declare tables using the JSON syntax. The advantage to using the JSON syntax is the ability for spaces to exist within keys. Usage is necessary when generating data from an external source. For consistency, the JSON syntax should be used for tables.

local x =
{
  "id": 1,
  "name": "Foo",
  "price": 123,
  "tags": [ "Bar", "Eek" ],
}

Function/Method Names

// Function names should use lower camel case
someFunction()
{

}

Access Modifiers

Squirrel does not have any mechanism to restrict access to functions or variables. However, we can use python naming conventions to help differentiate how they should be used. This is useful to give a clear indication of how to use and extend a class. I don't really see a need for private access.

Full Example

Git

Git/GitHub branching standards & conventions

Instance Branch Description, Instructions, Notes
Stable stable Accepts merges from Working and Hotfixes
Working master Accepts merges from Features/Issues and Hotfixes
Features/Issues topic-* Always branch off HEAD of Working
Hotfix hotfix-* Always branch off Stable
oomek commented 4 years ago

It would be a good idea in my opinion to include a good boilerplate with all callbacks defined, basic modules loaded flw, flh defined for beginners. I even copy and paste the basics instead of repeatedly writing the same over and over again when I do test layouts. If we go with versioning and auto-update a well defined and standardized versioning convention should be included as well.