Yeah, here’s some tips to keep your code organized and clean:
- Whitespace is key. Use proper indentation - a single additional indent for each
if/else/elseif
statement,for/while/repeat
loop,function
definition, or anything else that encloses a code segment - Don’t use unneccessary language. For example, if you want to check if something is true, you don’t need to write out
if value == true then
, you can simply putif value then
(this also applies to the opposite withif value == false then
andif not value then
) - Add extra lines where necessary to separate out different key parts of your process. For example, in the code we’ve been working with, I added a space between the first set of values, the wait line, and the second set of values, to show all three ‘stages’ of the function
- Follow the general structure of variable definition first (grouping variables by type, like strings with string, integers with integers, etc.), followed by the rest of your code
- Stay generally clean and concise, using descriptive variable names where possible
There are plenty more guidelines and rules to code styling (to the point of near religion in some places) that vary depending on company, language, and user, but these are a good place to start.