LogoLogo
  • AppFlowy
    • ⭐Start here
      • Welcome to AppFlowy Docs
      • How to get help
      • Install AppFlowy
    • 🛠️Installation
      • 🖥️System Requirements
      • 💿Installation methods
        • Mac / Windows / Linux Packages
          • Installing on Linux
            • Installing & Setting up Flutter on Linux from Source
        • Docker
    • 🌱Community
      • 🤙Get in contact
      • 📔AppFlowy Mentorship Program
        • Program Guidance
        • Proposal Template
        • Pull Request Template
        • Mentorship 2023
          • Mentee Projects
            • Calendar View for AppFlowy Database
            • Custom Themes
            • Shortcuts and Customized Hotkeys for AppFlowy
            • Table
            • ⭐Favorites
            • Code Block
            • Outlines
            • Importers
            • AI Writers
            • Templates
          • Project Ideas
      • ✍️Write for AppFlowy
        • 📃Drafts
          • [Draft] Use Case: Software Engineer
          • [Draft] Use Case: High School Students
          • [Draft] How to add a new property to appflowy database
      • 🍂Hacktoberfest
    • 🛣️Roadmap
    • 🌋Product
      • 💽Data Storage
      • 🎨Customize and Style Content
      • ⏮️Duplicate, Delete, and Restore
      • 💎Databases
        • 🔢Database Properties
        • 🗃️Manage Properties
      • Ⓜ️Markdown
      • ⌨️Shortcuts
      • 🪄AppFlowy AI
      • 🦙AppFlowy Local AI - Ollama
      • 🎨Themes
      • ☁️AppFlowy Cloud
      • 🧩AppFlowy Plugins
        • Table-view Databases
        • Kanban Board
        • Calendar
        • Auto Generator
        • Smart Edit
        • Code Blocks
        • Math Equations
        • Cover
        • Emoji
  • Documentation
    • 💎Software Contributions
      • 🟢Get started
      • 💀Architecture
        • Frontend
          • Tauri
            • 🗺️CodeMap
          • Web
            • 🌟Design Philosophy
          • Flutter
            • 🗺️Project Structure: CodeMap
            • 🧮Grid
            • ⚙️Setting
          • Inter-Process Communication
          • User
            • User Data
            • Events & Notifications
          • Folder
            • Events & Notifications
          • Document
          • Database View
            • Events & Notifications
            • Grid
            • Calendar
            • Kanban Board
        • Backend
          • Initialize
          • Events
          • Delta(WIP)
          • Profiling
          • Database
        • Domain Driven Design
        • Proposals
      • 🏗️Conventions
        • 🔤Naming Conventions
        • ⌨️Code Conventions
          • 🐦Flutter
        • 🐙Git Conventions
      • 💛Submitting Code
        • 🏦Setting Up Your Repositories
        • ⤴️Submitting your first Pull Request
      • 🤟Coding Standards and Practices
        • 👽Rust Backend
    • 🚀AppFlowy
      • 👾How to contribute to AppFlowy
      • 🏗️Building from Source
        • 🌳Flutter Setup
          • 🐧Building on Linux
          • 🍎Building on macOS
          • 🪟Building on Windows
        • 🌐Web Setup
        • 📡Tauri Setup
      • ☁️Debugging with AppFlowy Cloud
      • 🔁Debugging in VS Code
      • ☎️Translate AppFlowy
      • ❓Troubleshooting
      • 👮‍♀️Licenses
    • 🏍️AppFlowy Editor
      • ⌨️How to Implement Markdown Syntax To Style Text In AppFlowy Editor
      • 🧩How to Create a Plugin for AppFlowy Editor
      • 👮‍♀️Licenses
    • ☁️AppFlowy Cloud
      • 🌈Architecture
      • ☀️Deployment
  • Guides
    • Sync Desktop and Mobile
    • Self-Hosting AppFlowy
      • ☁️Self-hosting AppFlowy with AppFlowy Cloud
      • 🆓Self-hosting AppFlowy for free Using Supabase
    • Import From Notion
  • Blog Highlights
    • 🔮Demystifying AppFlowy Editor's Codebase
  • Handbook
    • Core values
Powered by GitBook
On this page
  • Variables
  • Use Cascade Notation
  • Flutter
  • Rust
  • Use expression bodies
  • Flutter
  • Rust
  • Inline TODOs
  • Dependencies and Crates

Was this helpful?

Edit on GitHub
  1. Documentation
  2. Software Contributions
  3. Conventions

Code Conventions

PreviousNaming ConventionsNextFlutter

Last updated 1 year ago

Was this helpful?

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

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

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

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

💎
🏗️
⌨️
Cascade notation