> For the complete documentation index, see [llms.txt](https://wiki.purduesigbots.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.purduesigbots.com/software/organizing-code/code-style.md).

# Code Style

Style == Success

## What is code style?

Code style is the idea that code should be formatted in a standardized, readable, and functional way that does not inhibit debugging or peer reviews. Another benefit of good code style (especially in object oriented programming languages) is the ability to code to be easily expandable and added to.

## Reasons for code styles:

As the code for your robots become more complicated, you will spend as much reading code as you do writing it. This is especially true if you have several programmers on your team, all writing code for your robots.

This is why having good code style for your robots is important. Being able to easily understand and read the code makes it easier to iterate and make your code better. Otherwise, you'll spend lots of time figuring out what your teammates and your past-self had written.

Here are a couple examples:

```cpp
// Good Style Example
class Robot {
public:
    Robot() : speed(0), direction("North") {}

    void setSpeed(int newSpeed) {
        speed = newSpeed;
    }

    void setDirection(std::string newDirection) {
        direction = newDirection;
    }

    int getSpeed() const {
        return speed;
    }

    std::string getDirection() const {
        return direction;
    }

private:
    int speed;
    std::string direction;
};
```

```cpp
// Bad Style Example
class robot{
    public: robot():speed(0),direction("North"){}
    void setspeed(int newspeed){speed=newspeed;}
    void SetDirection(std::string newDirection){direction=newDirection;}
    int getspeed(){return speed;}std::string GetDirection(){return direction;}
    private:int speed;std::string direction;};
```

While both of these pieces of code do effectively the same thing, the inconsistency and lack of proper spacing makes reading the bad code much more difficult.

## Rules of code standards:

There are many different code style standards, and the specific one you use doesn't mater so much as you adhere to the following principles:

1. Your code style is consistent across your project(s)
2. All members of the team understand and cooperatively enforce the standards.
3. The style should not inhibit the functionality of the code.

## Appendix: Professional Code Style-Guides

These are reference style guides that exhibit the traits mentioned above.

* [Google C++ Style-guide](https://google.github.io/styleguide/cppguide.html)
* [LLVM Coding Standards](https://llvm.org/docs/CodingStandards.html)
* [Firefox C++ Coding Style](https://firefox-source-docs.mozilla.org/code-quality/coding-style/coding_style_cpp.html)

### Teams Contributed to this Article:

* [BLRS](https://purduesigbots.com/) (Purdue SIGBots)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://wiki.purduesigbots.com/software/organizing-code/code-style.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
