We produce sample programs for all Open Market APIs. To improve the look and consistency of sample programs across all our products, we'd like everyone to follow certain coding guidelines.
We produce sample code in five different languages:
We provide sample C programs for the following APIs:
This section describes the style guidelines for coding sample C applications.
| The start of every sample C program |
| ||||||||||||
| Writing block comments |
| ||||||||||||
| Writing inline comments |
/* like this */ | ||||||||||||
| Naming your programs |
For example: create_digital_offer.c /* good program name */ CreateDigitalOffer.c /* bad program name */ digital_offer.c /* bad program name */ |
||||||||||||
| Naming your functions |
For example: PrepareDatabase(); /* good function name */ prepare_database(); /* bad function name */ database(); /* bad function name */ | ||||||||||||
| Naming your variables |
For example: transaction_server /* good variable name */ transactionserver /* bad variable name (needs underscore) */ ts /* bad variable name (too ambiguous) */ | ||||||||||||
| What the main() function should do |
| ||||||||||||
| How to specify exit codes |
Sample code should contain #define'd exit codes. 0 is reserved for successful error-free exit.
Example: #define SUCCESS 0 #define FILE_NOT_FOUND 1 #define COULD_NOT_CONNECT_WITH_TRANSACT 2 | ||||||||||||
| Using the preprocessor directives #debug and #verbose | Should not be in production sample code but may be in courseware code. | ||||||||||||
| What to name the variable that holds a function's return value. | return_code | ||||||||||||
| What to name variables in BPAPI programs |
|
Here is a sample C function. An explanation follows.
| Line(s) | What To Do On This Line |
|---|---|
| 1 | Put a blank line between functions. |
| 2-5 | Describe the function. |
| 6 | Specify the function's return type on a separate line. |
| 7 | Specify the function's name and its parameters. If the function has only one parameter, specify the function name and parameter on the same line. If the function has multiple parameters, specify one parameter per line. |
| 8 | Place the opening brace { flush left just after the last function parameter. |
| 9-11 | Specify all local function variables starting at column 1. |
| 17, 18, 22, 27, 30 | Outer level code should start at column 3. |
| 19-21, 28-29 | Embedded code should start at column 5. |
| 18, 27 | The starting brace should start at the end of a line (not on its own line). |
| 22, 30 | The closing brace should be aligned with the outer level code (for example, with for and if. |
When describing C programs in your programmer guides, follow these guidelines:
| Correct Term | Incorrect Term | Comment |
|---|---|---|
| function | call | May use "call" as verb, but not as noun. |
| parameter | argument | |
| user name | username | |
| FunctionName() | FunctionName | Add parentheses at end when citing function name in text. |
| Content Server | local server, store server, or web server |
(The doc department modified (slightly) engineering's guidelines for C++.)
We provide sample C++ applications for all Transact APIs, including:
If you are writing fresh C++ examples or modifying some existing ones, then we'd like you to follow these coding guidelines.
We code two different categories of C++ programs:
First off, we (the doc department) aren't writing classes and header files. Rather, we are demonstrating how to instantiate classes that are part of the APIs. Therefore, our sample C++ applications look a lot like sample C applications; that is, they contain a main() function and possibly a bunch of secondary functions called from main(). In fact, because context variables don't work too well as function parameters, our main() functions have a tendency to be quite long.
Most C++ applications have roughly the same start, which is:
Copy the existing starting code for your API or a related API.
Most nonCOM applications require two secondary functions:
Paste the following code into the top of every nonCOM application:
Paste the following code for OutputLatin1 into your application: