Difference between revisions of "Contributing to SourceMod"
(New page: Rambling about why patches are good =Source Code Guidelines= ==Double-Check your commits, and check compilability== Don't commit something because it looks right -- while you don't need t...) |
m (Contibuting to SourceMod moved to Contributing to SourceMod) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 87: | Line 87: | ||
This adds more spaces but improves readability. It also makes it less annoying to add more into the block later. | This adds more spaces but improves readability. It also makes it less annoying to add more into the block later. | ||
− | Use Camel Case for API | + | ==Use Camel Case for API== |
No questions asked, use CamelCase! SourceMod does everything in a "Verb, Noun" or "Subject, Verb, Noun" form. I.e. SQL_Connect, or GetClientName. Some natives have the verb implied. For example, "StrEqual" is implicitly "IsStrEqual." This practice is kind of cheap and you should try to deprecate usage of it. | No questions asked, use CamelCase! SourceMod does everything in a "Verb, Noun" or "Subject, Verb, Noun" form. I.e. SQL_Connect, or GetClientName. Some natives have the verb implied. For example, "StrEqual" is implicitly "IsStrEqual." This practice is kind of cheap and you should try to deprecate usage of it. | ||
− | Space/parenthesize operators in math functions | + | ==Space/parenthesize operators in math functions== |
The following are not very readable: | The following are not very readable: | ||
Line 101: | Line 101: | ||
int mynum = (((a / b) + c) * d) - e; | int mynum = (((a / b) + c) * d) - e; | ||
</pre> | </pre> | ||
− | Never add extra spaces to parenthetical listings | + | ==Never add extra spaces to parenthetical listings== |
For example, this is silly: | For example, this is silly: | ||
Line 130: | Line 130: | ||
))); | ))); | ||
</pre> | </pre> | ||
− | Don't "crunch" control statements | + | ==Don't "crunch" control statements== |
Bad: | Bad: | ||
Line 145: | Line 145: | ||
while (gaben) | while (gaben) | ||
</pre> | </pre> | ||
− | Don't unnecessarily expand iterator expressions | + | ==Don't unnecessarily expand iterator expressions== |
Example of unnecessary spacing: | Example of unnecessary spacing: | ||
Line 160: | Line 160: | ||
for (int i=1; i<=1; i++) | for (int i=1; i<=1; i++) | ||
</pre> | </pre> | ||
− | Make conditional statements clear | + | ==Make conditional statements clear== |
This is unclear, and may have random bugs: | This is unclear, and may have random bugs: | ||
Line 172: | Line 172: | ||
|| (b -= 5) != 0 ) | || (b -= 5) != 0 ) | ||
</pre> | </pre> | ||
− | Use #if 0 to disable code, not /* */ | + | ==Use #if 0 to disable code, not /* */== |
Block comments are annoying, and tend to be messy when they're nested. Use #if 0 / #endif to disable code. | Block comments are annoying, and tend to be messy when they're nested. Use #if 0 / #endif to disable code. | ||
− | Do not use Hungarian notation | + | ==Do not use Hungarian notation== |
Use g_, m_, b, and f where appropriate. If you find yourself using variable names like m_pszString, you probably need to stop. | Use g_, m_, b, and f where appropriate. If you find yourself using variable names like m_pszString, you probably need to stop. | ||
Latest revision as of 01:46, 19 February 2009
Rambling about why patches are good
Contents
- 1 Source Code Guidelines
- 1.1 Double-Check your commits, and check compilability
- 1.2 Submit one patch idea at a time
- 1.3 ALWAYS MIND BACKWARDS COMPATIBILITY
- 1.4 Coding Style
- 1.5 Use Camel Case for API
- 1.6 Space/parenthesize operators in math functions
- 1.7 Never add extra spaces to parenthetical listings
- 1.8 Don't "crunch" control statements
- 1.9 Don't unnecessarily expand iterator expressions
- 1.10 Make conditional statements clear
- 1.11 Use #if 0 to disable code, not /* */
- 1.12 Do not use Hungarian notation
- 2 Steps
Source Code Guidelines
Double-Check your commits, and check compilability
Don't commit something because it looks right -- while you don't need to explicitly test every addition, it should at least compile. Breaking the build process for anything on either Windows and Linux causes the build server to send everyone an e-mail.
The builds are:
- Windows - Microsoft Visual Studio, 8.0 (required)
- Linux, 32bit - GCC, 4.1 (required)
Submit one patch idea at a time
Mercurial marks all changes in a set. For example, if you change 30 files, all 30 files will be marked as one revision set. Thus, it is best if you submit one "patch idea" at a time. If you add feature X to one file, submit it as a single patch before you add feature Y to another file, otherwise you risk committing both changes in one revision.
ALWAYS MIND BACKWARDS COMPATIBILITY
If you're about to change the functionality of a native, first consider every way a script could be using it. For example, pev() on a string will return the string length. Is it likely any script is actually using this? No. Can we remove this functionality? No.
It may suck, but the instant we break anything, someone will complain that the newer version is worse. All old plugins should work, especially without recompiling. This is called ABI compatibility, and it means that all old SourceMod plugin binaries should work with modification across updates.
Another example: if you are about to add parameters onto a native, you should make the new parameters have default arguments. Furthermore, you must make sure that old binary plugins passing in the old number of parameters will not break (easy, since Pawn tells you how many parameters were passed).
Remember: If it breaks something, don't do it, or else you'll find any number of people hounding you!
Coding Style
For SourceMod, we do have loose official coding style. You should use this style within reasonable limits. The most important rules are the ones about brace blocks and camel case, every thing else can be tweaked to your own style.
Always put braces on a new line, except for else cases The following are bad:
void Gaben() { if (gaben) { hello } else { ghello } }
Always put the brace on a new line:
void Gaben() { if (gaben) { hello } else { ghello } }
OR
void Gaben() { if (gaben) { hello } else { ghello } }
(These are both allowed conventions)
Always use braces for block statements (no one liners!) The following are bad:
if (gaben) hacks if (gaben) hacks if (gaben) { hacks } if (gaben) { hacks }
Proper:
if (gaben) { hacks }
This adds more spaces but improves readability. It also makes it less annoying to add more into the block later.
Use Camel Case for API
No questions asked, use CamelCase! SourceMod does everything in a "Verb, Noun" or "Subject, Verb, Noun" form. I.e. SQL_Connect, or GetClientName. Some natives have the verb implied. For example, "StrEqual" is implicitly "IsStrEqual." This practice is kind of cheap and you should try to deprecate usage of it.
Space/parenthesize operators in math functions
The following are not very readable:
int mynum = (a/b+c)*d-e;
It should be:
int mynum = (((a / b) + c) * d) - e;
Never add extra spaces to parenthetical listings
For example, this is silly:
void Function ( a, b, c, d ) { Function ( a, b, c, d ); }
It should, of course, be:
void Function(a, b, c, d) { Function(a, b, c, d) }
The expection to this rule is with complicated inner expressions. For example:
Function(Calc(Reduce(((*iter)->GetFunc())())))
Is impossible to read, and might look better as:
Function(Calc(Reduce( ((*iter)->GetFunc()) () )));
Don't "crunch" control statements
Bad:
if(a) for(;;) while(gaben)
Good:
if (a) for (;;) while (gaben)
Don't unnecessarily expand iterator expressions
Example of unnecessary spacing:
if ( (fp=fopen("file", "rt")) == NULL ) if ( (a + b) ) for (int i = 1; i <= 1; i++)
Read better as:
if ((fp=fopen("file", "rt") == NULL) if ((a+b) != 0) for (int i=1; i<=1; i++)
Make conditional statements clear
This is unclear, and may have random bugs:
if (a & *b = c + d == t * d+++k || b -= 5)
Better:
if ( ((a & *b) = (c+d)) == (t * (d + ++k)) || (b -= 5) != 0 )
Use #if 0 to disable code, not /* */
Block comments are annoying, and tend to be messy when they're nested. Use #if 0 / #endif to disable code.
Do not use Hungarian notation
Use g_, m_, b, and f where appropriate. If you find yourself using variable names like m_pszString, you probably need to stop.
Steps
Obtaining the Source Code
Download the latest copy of the SourceMod source code using Mercurial. If you are going to be submitting changes for c++ parts of SourceMod make sure you can compile SourceMod.
Making and submitting a patch
Use the Mercurial command:
hg diff file1.txt file2.txt > outputfile.patch
To generate a patch file for your changes. This can then be attached to the appropriate Bugzilla bug report using the Add an attachment link (don't forget to tick the patch box).
Why hasn't my patch been committed?
See Bailopan's blog regarding patch submitting guidelines: Blag