This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
cs:coding_conventions:start [2017/04/08 12:43] Brandon Kallaher [All Languages] |
cs:coding_conventions:start [2017/04/08 12:50] (current) Brandon Kallaher |
||
|---|---|---|---|
| Line 15: | Line 15: | ||
| ===Trailing Spaces=== | ===Trailing Spaces=== | ||
| - | Trailing whitespace at the end of a line is not allowed. | + | Trailing whitespace at the end of a line is not allowed. \\ |
| **Rational:** most text editors will actually automatically chop the trailing whitespace when you open a file. If people aren't paying attention, this can result in them commiting a file where they made no functional changes other than to cut the whitespace, resulting in a confusing source control history. In addition, it's just a cleanliness thing. | **Rational:** most text editors will actually automatically chop the trailing whitespace when you open a file. If people aren't paying attention, this can result in them commiting a file where they made no functional changes other than to cut the whitespace, resulting in a confusing source control history. In addition, it's just a cleanliness thing. | ||
| ===Extra Newlines=== | ===Extra Newlines=== | ||
| - | More than one blank line in a row is not allowed. **Rational**: If you need to break up your code into logical chunks it is better to use a single newline and a comment describing the next code block. | + | More than one blank line in a row is not allowed. \\ |
| + | **Rational**: If you need to break up your code into logical chunks it is better to use a single newline and a comment describing the next code block. | ||
| ===== C++ ===== | ===== C++ ===== | ||
| running | running | ||
| Line 26: | Line 27: | ||
| ===== Python ===== | ===== Python ===== | ||
| - | + | Nodes should be defined in classes with the constructor called in the "main" section. | |
| - | + | <code python> | |
| - | + | def Node(): | |
| - | + | def __init__(): | |
| + | # define pubs and subs here | ||
| + | ... | ||
| + | |||
| + | if __name__=='__main__': | ||
| + | rospy.init_node() | ||
| + | Node() | ||
| + | rospy.spin() | ||
| + | </code> | ||