We now have styling info in the project repo itself: https://github.com/DarkstarProject/dark ... tyle-guide
This should help make your changes easy to read and help follow some already existing conventions, which might help get your change merged faster assuming the change is retail accurate.
I have a mix of examples from more than one language here, hope that isn't confusing.
-------------------------------------------------------------------------------
Properly indent your code
Use 4 spaces for a single indention, not tabs. While I never cared which was used (just that ya bloody pick one!) the project seems to want it all spaces now.
2 indention levels should result in 8 leading spaces, not 6, not 9...8.
- 4 x 2 = 8, for you indent challenged folks.
DSP now prefers Unix Line Ends. See this link.
https://help.github.com/articles/dealin ... e-endings/
If you deal with projects other than DarkStar, you will want to do this per-repository rather than global (they have a section for it on that page) otherwise you can deal with it globally and all pull/commit/push will become Unix line ends automatically.
MS WORD/WORDPAD IS NOT A SUITABLE EDITOR TO WRITE CODE WITH
Get yourself something like notepad++ vim or anything designed to actually edit code. There are tons of options that are 100% free.
Try to limit lines of code to a maximum of 100 characters.
- Exceptions will happen, but try. Typically with well formatted code, you won't go over 80 or so characters anyway.
- the line of dashes above happens to be exactly 80 characters long.
- Generally up/down scrolling is preferable to left/right scrolling as long as your code isn't smelly and hard to read
In Lua, you need the parenthesis around each condition and not every object
Yes:
if ((thing1 and thing3 and thing5) or (thing2 and thing4 and thing6)) then
doStuff()
-- does "stuff" flawlessly anytime either the 3 odd numbered things
-- or the 3 even numbered things are all true.
end
No:
if (thing) and (thing1) and (thing3) or (thing5) and (thing4) and (thing6) then
doStuff()
-- this probably isn't going to behave right
-- and will be harder to spot mistakes
end
In Lua, you need the parenthesis ONLY for making things clear when it isn't obvious.
Code: Select all
var1 + var2 * var3 / var4 ..
INDENTION! INDENTION! INDENTION!
- Seriously its crazy how bad some people are at such a simple thing.
Code: Select all
function getThingDoStuff(player, npc)
local thing1 = npc:getThing(1)
local thing2 = npc:getThing(2)
if (thing1 and thing2) then
doStuff()
end
end
Code: Select all
function getThingDoStuff(player, npc)
local anotherThing1 = npc:getThing(1)
local anotherThing2 = npc:getThing(2)
if thing1 and thing2 then
if anotherThing1 or anotherThing2 then
doStuff()
else
doOtherStuff()
end
end
end
Code: Select all
-- WHYYYYYYYYYY /wrists
function getThingDoStuff(player, npc)
local anotherThing1 = npc:getThing(1)
local anotherThing2 = npc:getThing(2)
if (anotherThing1 or anotherThing2) then
doStuff()
else
doOtherStuff()
end
end
end
Code: Select all
-- TEO WILL END YOU, YOU PUNK!
function getThingDoStuff(player, npc)
local anotherThing1 = npc:getThing(1)
local anotherThing2 = npc:getThing(2)
if (thing1 and thing2) then
if (anotherThing1 or anotherThing2) then
doStuff()
else
doOtherStuff()
end
end
end
Trim all trailing whitespace.
- Do not create excessive blank space without reason.
- Do not confuse trailing whitespace with leading whitespace.
- Use lowerCamelCase or SNAKE_CASE (underscores).
Code: Select all
function goodFunctionName(argument1, argument2)
stuff
end
Code: Select all
function BADFUNCTIONNAME(argument1, argument2)
stuff
end
Code: Select all
function badfunctionname(argument1, argument2)
stuff
end
OK:
Code: Select all
// underscores.
ENUM GOOD_GENERIC_HEX_ENUM
{
THING_1 = 0x0001,
THING_2 = 0x0002,
THING_3 = 0x0004,
THING_4 = 0x0008
}
Code: Select all
// Note the casing.
ENUM alsoGoodGenericHexEnum
{
Thing = 0x0001,
BiggerThing = 0x0002,
EvenBiggerThing = 0x0004,
JustThing = 0x0008
}
(Tabs and spaces have been replaced with underscores and dashes for visibility)
Code: Select all
____ENUM-badgenerichexenum-//-MY-EYES!
____{
________Thing________________=-0x0001____
-----____BiggerThing________-____=____0x0002-
____-____EvenbiggerThing________=-0x0004________
____----JustThing____________=-0x0008----____--____
________//-Don't-do-this.-Tabs-should-not-be-used-for-alignment.
________//-Don't-mix-spaces-between-tabs-or-tabs-between-spaces...
________//-...And-don't-leave-either-trailing!
____}
Example:
Code: Select all
const int MAX_THING = 999;
Code: Select all
function()
{
if (condition)
{
DoStuff
}
}
Code: Select all
function(){
DoStuff
}
Code: Select all
function()
DoStuff
Code: Select all
if (condition)
{
DoStuff
}
else
DoOtherStuff
Somewhat of a personal request here:
Please don't bunch up your code or comments tightly, some contributors that could be helping you are vision impaired and are less likely to offer help if they are straining to see your code. Like me. Lua isn't whitespace sensitive, but my eyes are.
- Also if you are aligning conditionals, please don't put extra whitespace inside braces/brackets/parenthesis.
Code: Select all
// C++ Comment
if (conditions)
Code: Select all
//C++ Comment
if(conditions)
Code: Select all
if( condition9 )then
elseif(condition10)then