> For the complete documentation index, see [llms.txt](https://docs.appflowy.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.appflowy.io/docs/documentation/software-contributions/conventions/code-conventions.md).

# Code Conventions

## Variables

In the AppFlowy codebase, we prioritise variable immutability and consistency. This approach is integral to our code conventions, enhancing code quality and maintainability.

As much as you can, prefer declaring variables as immutable. This is done in Flutter by the use of the \`final\` keyword, and in Rust by omitting the \`mut\` keyword.

In the case you prefer specifying the type of immutable variables, please do this consistently throughout your code. For immutable variables, **always** specify the type.

By adhering to these principles, we create a codebase that is not only functional but also comprehensible and maintainable for all team members.

## Use Cascade Notation  <a href="#id-405d" id="id-405d"></a>

[Cascade notation](https://flutterbyexample.com/lesson/cascade-notation) allows you to perform a sequence of operations on the same object. It saves your number of steps and needs for a temporary variable.

### Flutter

```
Demo d1 = new Demo();
Demo d2 = new Demo();

// Bad - Without Cascade Notation
d1.setA(20);
d1.setB(30);
d1.showVal();


// Good - With Cascade Notation
d2..setA(10)
  ..setB(15)
  ..showVal();
```

### Rust <a href="#id-2998" id="id-2998"></a>

```
let mut person = Person::new();
let mut numbers = Vec::new();

// Bad - Without Cascade Notation
person.set_name("Alice");
person.set_age(30);
person.print_info();

numbers.push(1);
numbers.push(2);
numbers.push(3);

// Good - With Cascade Notation
person
    .set_name("Alice")
    .set_age(30)
    .print_info(); 

numbers
    .push(1)
    .push(2)
    .push(3);
```

## Use expression bodies  <a href="#id-2998" id="id-2998"></a>

For functions that contain just one expression, you can use an expression function. The `=>` (arrow) notation is used for expression functions.

### Flutter

```
// Good
setState(() => performAction(someValue));

// Bad:
setState(() {
  performAction(someValue);
});
```

### Rust

```
// Good
some_function(|| perform_action(some_value));

// Bad
some_function(|| {
    perform_action(some_value);
});
```

## Inline TODOs

We prefer ***not*** including inline todos in the codebase, however, whilst you're developing feel free to add TODOs.

When opening a PR, please try to resolve the TODOs you created, if they need more attention or are more complex, then you can remove the TODO in favor of opening an issue on Github.

## Dependencies and Crates


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.appflowy.io/docs/documentation/software-contributions/conventions/code-conventions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
