Skip to content

Commit b34e31c

Browse files
committed
WIP on style guide
1 parent 4551ab5 commit b34e31c

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

docs/resources/style-guide.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
3+
# Consistency
4+
5+
## Variable Naming
6+
7+
Follow a consistent naming convention for variables, functions, and components to make your code more readable and maintainable.
8+
9+
Best practices for naming conventions in app development, especially for projects using Flutter, aim to improve code readability, maintainability, and consistency across the application. Here are some general guidelines tailored for different aspects of a Flutter project:
10+
11+
Various naming styles (as suggested by [Dart Effective Style Guide](https://dart.dev/effective-dart/style#identifiers)):
12+
13+
- **UpperCamelCase** names capitalize the first letter of each word, including the first.
14+
15+
- **lowerCamelCase** names capitalize the first letter of each word, except the first which is always lowercase, even if it's an acronym.
16+
17+
- **lowercase_with_underscores** names use only lowercase letters, even for acronyms, and separate words with _.
18+
19+
**General Principles**
20+
- **Be Consistent:** Whatever conventions you choose, apply them consistently across the project.
21+
- **Be Descriptive:** Names should be self-explanatory, reducing the need for additional comments to explain what a variable, function, or class does.
22+
- **Avoid Abbreviations:** Unless it's a well-known abbreviation, spell out words to avoid confusion.
23+
24+
25+
26+
### Components and Widgets
27+
28+
:::tip[Do's]
29+
- **Use UpperCamelCase for Class Names:** Always write class names, including widgets and components, in UpperCamelCase. Example: `MyCustomButton`, `UserProfileWidget`, `MainViewComponent`.
30+
31+
- **Suffix Widget Names with the Type of Widget:** When naming widgets, include a suffix that indicates the type of widget. Example: `LoginButtonWidget`, `ProfileCardComponent`, `HeaderViewWidget`.
32+
33+
- **Use Prefixes for Clarity When Necessary:** Add a prefix only if it significantly improves clarity or helps avoid naming conflicts. Example: `AppUserProfileWidget` (if `UserProfileWidget` is already in use).
34+
:::
35+
36+
:::danger[Don'ts]
37+
- **Don’t Use Prefixes Unnecessarily:** Avoid adding prefixes that do not enhance clarity or that are redundant. Bad Example: `MyAppButtonWidget` (if `ButtonWidget` would suffice).
38+
39+
- **Don’t Use LowerCamelCase for Class Names:** Avoid using **lowerCamelCase** for class names, which is generally reserved for variables and method names. Bad Example: `loginButtonWidget`, `userProfileComponent`.
40+
41+
- **Don’t Mix Naming Conventions:** Stick to **UpperCamelCase** consistently for all class names and widgets. Mixing conventions can reduce code readability. Bad Example: `userLoginWidget`, `ProfilecardComponent`, `headerView`.
42+
:::
43+
44+
### Pages & Screens
45+
46+
:::tip[Do's]
47+
- **Use CamelCase for Page Names:** Name your Pages using CamelCase to clearly indicate their purpose. Example: `HomePage`, `SearchResultsScreen`, `UserProfilePage`.
48+
49+
- **Include "Screen" or "Page" in the Page Name:** Always include the word "Screen" or "Page" in the file name to clearly identify UI screens or pages. Example: `LoginScreen`, `SettingsPage`.
50+
51+
- **Be Descriptive and Clear in File Names:** Ensure that file names are descriptive enough to convey their purpose or content at a glance. Example: `OrderConfirmationScreen`, `ProductDetailsPage`.
52+
:::
53+
54+
:::danger[Don'ts]
55+
- **Don’t Use All Lowercase or Mixed Case in Page Names:** Avoid using all lowercase or inconsistent casing in file names, as it can lead to confusion and reduce readability. Bad Example: `homepage`, `searchResultscreen`.
56+
57+
- **Don’t Use Generic Names Without Purpose:** Avoid generic names that do not clearly indicate the file’s purpose or content. Bad Example: `Main`, `View`, `Screen1`.
58+
59+
- **Don’t Mix Naming Conventions:** Consistently use CamelCase for all page names related to pages and screens. Mixing conventions can make your project harder to navigate. Bad Example: `search_results_screen`, `Userprofilepage`.
60+
:::

0 commit comments

Comments
 (0)