1---2name: kotlin-development3description: Kotlin development guidelines with best practices for clean code, naming conventions, function design, and data handling4---56# Kotlin Development Best Practices78## General Principles910- Use English for all code and documentation11- Always declare the type of each variable and function12- Avoid the `any` type; create necessary types instead13- No blank lines within function bodies1415## Naming Conventions1617### Case Standards18- **PascalCase**: Classes, interfaces, enums19- **camelCase**: Variables, functions, methods, parameters20- **UPPERCASE**: Environment variables, constants21- **underscores_case**: Files and directories2223### Naming Guidelines24- Start each function with a verb (get, set, create, update, delete, etc.)25- Use complete words over abbreviations26 - Allowed abbreviations: API, URL, i/j for loops, err, ctx, req/res/next27- Avoid magic numbers; define constants instead28- Boolean variables use prefixes: `isLoading`, `hasError`, `canDelete`2930## Function Design3132### Size and Responsibility33- Keep functions under 20 instructions34- Each function should have a single responsibility35- Extract logic into utility functions when complexity increases3637### Naming Functions38- Use verb-based naming that describes the action39- Prefix boolean-returning functions with `is`, `has`, or `can`40- Prefix void functions with action verbs like `execute`, `save`, `send`4142### Reducing Nesting43- Use early returns to handle edge cases first44- Extract nested logic into separate functions45- Employ higher-order functions (map, filter, reduce) to minimize loops46- Prefer arrow functions for simple operations; use named functions otherwise4748### Parameters49- Use default parameters instead of null checks50- When functions have multiple parameters, consolidate them into objects (RO-RO pattern)51- Keep parameter lists short (max 3-4 parameters)5253## Data Handling5455### Data Classes56- Use data classes for data structures57- Encapsulate primitive types in composite types when they represent domain concepts58- Validate data internally within data classes5960### Immutability61- Prefer immutability for data62- Use `val` for variables that don't change63- Use immutable collections when possible64- Create new instances instead of mutating existing ones6566## Classes and Objects6768### Size Guidelines69- Keep classes under 200 instructions70- Limit to fewer than 10 public methods71- Limit to fewer than 10 properties7273### Design Principles74- Follow SOLID principles75- Favor composition over inheritance76- Use interfaces for abstraction77- Keep classes focused on a single responsibility7879## Exception Handling8081### When to Use Exceptions82- Reserve exceptions for truly unexpected errors83- Don't use exceptions for control flow84- Catch exceptions only to:85 - Fix an anticipated issue86 - Add context before re-throwing8788### Best Practices89- Create custom exception types for domain-specific errors90- Include meaningful error messages91- Log exceptions at appropriate levels9293## Testing9495### Unit Tests96- Follow Arrange-Act-Assert convention97- Write unit tests for all public functions98- Use test doubles (mocks, stubs, fakes) for dependencies99- Name tests descriptively to document behavior100101### Acceptance Tests102- Follow Given-When-Then convention103- Test user-facing behavior and scenarios104- Keep tests independent and repeatable105106## Code Organization107108- Group related functionality together109- Keep files focused and cohesive110- Use packages/modules to organize code by feature or layer111- Maintain consistent file structure across the project