This document outlines various issues, code smells, and areas for improvement in the kmpuiviews module.
- Lack of Documentation: Most classes, functions, and properties lack proper documentation, making it difficult to understand their purpose and usage.
- Inconsistent Error Messages: Error messages in
staticCompositionLocalOfdeclarations are inconsistent - some are empty strings, some are descriptive, and some are generic. - Hardcoded Values: Many hardcoded values without explanation (e.g., cache sizes, time intervals).
- Missing Imports: Some files reference classes or functions without proper imports.
- Global Constants: Use of global constants like
USE_NAV3makes code less testable and harder to maintain. - Duplicate Navigation Implementations: The codebase maintains two separate navigation implementations (Navigation2Actions and Navigation3Actions) controlled by a global flag, increasing maintenance burden.
- Inconsistent Parameter Handling: Different implementations handle parameters differently ( e.g., Navigation2Actions vs Navigation3Actions handling of empty strings).
- Mixed Responsibilities: The file contains multiple unrelated utilities that should be separated into different files.
- Missing Import: Reference to
LocalSettingsHandling.currentwithout proper import. - Infinite Loop:
RecordTimeSpentDoing()function has an infinite loop in a LaunchedEffect, which could cause performance issues. - Unused Code:
ComponentStateenum is defined but not used anywhere in the file. - Poor Organization:
CustomAdaptiveclass andcalculateCellsCrossAxisSizeImplfunction could be moved to a separate file focused on grid-related utilities.
- Missing Imports: References to
Cached.cacheanddispatchIo()without proper imports. - Undocumented Constant: The constant
USE_NAV3is defined without documentation explaining its purpose. - Generic File Name: The file name "Utils.kt" is too generic and doesn't describe the specific utilities it contains.
- Undocumented Function: The function
loadItemlacks documentation.
- Commented-Out Code: The
ExpirableLRUCacheclass has commented-out code in theLinkedHashMapinitialization. - Unreliable Time Comparison: The
recyclemethod usesClock.System.now().nanosecondsOfSecondfor time comparison, which might not be reliable for measuring elapsed time. - Incomplete LRU Implementation: The
cycleKeyMapmethod doesn't properly implement LRU eviction logic since the commented-out code was responsible for that. - Hardcoded Values: The
Cachedobject uses hardcoded values (minimal size of 10 and flush interval of 5 minutes) without explanation. - Lack of Documentation: No documentation for the
Cachedobject.
- Error Swallowing: The
dispatchIoAndCatchListfunction catches exceptions, logs them, and then emits an empty list, which might hide errors from the caller. - Undocumented Function: The
recordFirebaseExceptionfunction is called without documentation about what it does. - Lack of Documentation: No documentation for the utility functions.
- Default Implementation: The
LocalCurrentSourceprovides a default implementation ofCurrentSourceRepository()which might not be appropriate. - Global Constant Dependency: The
KmpLocalCompositionSetupfunction uses the global constantUSE_NAV3to determine which navigation actions to use. - Complex Error Handling: The UriHandler implementation has a complex error handling chain that might be hard to debug.
- Missing Import: Reference to
DateTimeFormatItemwithout proper import. - Lack of Documentation: No documentation for the composition locals or the setup function.
- Repetitive Code: Lots of repetitive code in the LazyColumn items, with many CategoryGroup blocks that follow the same pattern.
- Overloaded Functions: The
AccountInfoItemfunction is overloaded with two nearly identical implementations that differ only in the type of theamountparameter. - Empty Parameter: The
ImageLoaderChoicecomponent is used with an empty name parameter. - Null Handling: The
profileUrlparameter is used withorEmpty()which might not be the best way to handle null values. - Scattered Conditional Rendering: Conditional rendering based on
appConfig.buildTypeis scattered throughout the code. - Lack of Documentation: No documentation for the screen or its components.
- Excessive Flow Combination: The
combineoperator is used with 12 flows, which is excessive and makes the code hard to read and maintain. - Error-Prone Constructor: The
AccountInfoCountconstructor that takes anArray<Int>is error-prone because it relies on the order of the flows in thecombineoperator. - Inefficient Flow Creation: The
flow { emit(translationModelHandler.modelList().size) }creates a new flow for each emission. - Expensive Operations: The
sourceRepository.sources.map { ... }performs filtering and grouping operations on each emission, which could be expensive. - Lack of Error Handling: No error handling in the flow chain.
- Undocumented Function: The
fireListenerfunction is called without documentation about what it does. - Redundant Empty Object: The
AccountInfoCount.Emptyobject could be replaced with a default parameter constructor.
- Lack of Documentation: The interface lacks documentation for its methods, making it difficult to understand their purpose and usage.
- Mixed Responsibilities: The interface contains methods for both navigation and UI state
management (e.g.,
currentDestination). - Generic Method Names: Methods like
navigateandpopBackStackare too generic and don't convey their specific behavior.
- Inconsistent Navigation Options: Some navigation methods include options like
launchSingleTopandrestoreState, while others don't. - Hardcoded Values: Hardcoded values like "NA" for empty titles and descriptions.
- Duplicate URL Encoding: URL encoding is duplicated across multiple methods.
- Complex Destination Checking: The
isTopLevelDestinationInHierarchymethod uses complex string operations to check destinations.
- Custom Back Stack Implementation: Uses a custom
TopLevelBackStackclass instead of the standard navigation library's back stack. - Commented-Out Code: Contains commented-out code like
//navBackStack.add(nav)and//return navBackStack.lastOrNull() == screen. - Inefficient Back Stack Clearing: The
clearBackStackmethod uses a loop to remove items from the back stack, which is inefficient. - Inconsistent Error Handling: No error handling for cases where the back stack might be empty.
- Missing Content Description: The Icon in the BackButton lacks a content description, which is problematic for accessibility.
- No Customization Options: The BackButton doesn't allow for customization of appearance or behavior.
- No Error Handling: No error handling for cases where navigation might fail.
- Duplicate Code: Three scaffold implementations (OtakuHazeScaffold, OtakuScaffold, NormalOtakuScaffold) with significant code duplication.
- Inconsistent Padding Handling: OtakuScaffold and OtakuHazeScaffold combine padding with LocalNavHostPadding, but NormalOtakuScaffold doesn't.
- Unclear Usage Guidance: No documentation explaining when to use each scaffold variant.
- Hardcoded Default Values: Default values like WindowInsets(0.dp) are hardcoded without explanation.
- Layered Abstractions: OtakuHazeScaffold wraps HazeScaffold, creating unnecessary layers of abstraction.
- Inconsistent Parameter Naming: Parameter names differ between OtakuHazeScaffold and
HazeScaffold (e.g.,
statevshazeState).
- Complex Implementation: Contains a complex custom layout implementation that's difficult to understand and maintain.
- Undocumented Composition Locals: Uses composition locals like
LocalScaffoldContentPaddingwithout proper documentation. - Copied Code: Explicitly states it's copied from another project with modifications, which could lead to maintenance issues.
- Utility Extensions: Contains utility extension functions like
plusandminusforPaddingValuesthat should be in a separate utility file. - Inline Utility Function: The
thenIfmodifier extension is unrelated to the scaffold functionality and should be in a separate utility file.
- Excessive File Length: The file is 866 lines long, making it difficult to understand and maintain.
- Multiple Similar Implementations: Contains multiple similar implementations ( BottomSheetDeleteScaffold, BottomSheetDeleteGridScaffold, ModalBottomSheetDelete) with significant code duplication.
- Commented-Out Code: Contains commented-out code that should be removed or implemented properly.
- TODO Comments: Contains TODO comments indicating incomplete work.
- Duplicate Helper Functions: DeleteItemView and DeleteItemDragSelectView are nearly identical with duplicated logic.
- Hardcoded Values: Contains hardcoded values like WindowInsets(0.dp) without explanation.
- No Documentation: Lacks documentation for the components and their parameters.
- Nested AlertDialogs: Contains nested AlertDialogs which can lead to confusing UI behavior.
- Hardcoded Colors: Uses hardcoded colors like Color.Red instead of using theme colors.
- Missing Accessibility: Icons lack content descriptions, which is problematic for accessibility.
- Duplicate Logic: The confirmation dialogs for deletion have duplicate logic across different components.
- Complex State Management: Uses multiple state variables and complex state management logic.
- Lack of Documentation: No KDoc comments explaining the purpose of the component or its parameters.
- Complex Animation Logic: Animation logic is complex and spread across multiple classes.
- Hardcoded Values: Contains hardcoded values like corner radius constants.
- Nested Scaffold: Uses a nested Scaffold inside another Scaffold, which can lead to performance issues.
- Complex State Management: Uses complex state management with multiple state variables.
- No Accessibility Considerations: No accessibility considerations for the bottom sheet.
- Lack of Documentation: No KDoc comments explaining the purpose of the component or its parameters.
- Missing Accessibility: Icons lack content descriptions, which is problematic for accessibility.
- Hardcoded Values: Contains hardcoded values like spacing (2.dp) without explanation.
- No Error Handling: No error handling for cases where the list might be empty.
- Inconsistent Parameter Naming: Parameter naming is inconsistent with other components ( e.g., "list" vs "listOfItems").
- Limited Customization: Offers limited customization options compared to other bottom sheet implementations.
- Lack of Documentation: No KDoc comments explaining the purpose of the component or its parameters.
- Hardcoded Values: Contains hardcoded values like animation delays (250ms) and width (64.dp) without explanation.
- Generic Content Description: Uses a generic content description "Localized description" instead of a meaningful one.
- Complex Animation Logic: Uses complex animation logic with multiple animations combined.
- Tight Coupling: The component is tightly coupled to specific navigation actions and data structures.
- No Error Handling: No error handling for cases where the actions might be null or invalid.
- Performance Concerns: The use of coroutines for simple state changes (show/hide) might be overkill and could lead to performance issues.
- Lack of Documentation: No KDoc comments explaining the purpose or usage of the functions.
- Code Duplication: The two functions have similar logic with slight differences.
- Inconsistent Implementation: The LazyListState version drops the first emission while the LazyGridState version doesn't.
- No Error Handling: No handling for potential exceptions during collection.
- Mutable State Variable: The LazyGridState version uses a mutable state variable ( lastTotalItems) that could be handled differently.
After analyzing multiple files in the kmpuiviews module, several patterns of issues emerge:
- Code Duplication: Many components have multiple similar implementations with significant code duplication (e.g., scaffolds, bottom sheets).
- Lack of Documentation: Most files lack proper documentation for classes, functions, and parameters.
- Large Files: Many files are excessively long and contain multiple components or utilities that should be separated.
- Mixed Responsibilities: Files often contain unrelated functionality that should be separated into different files.
- Hardcoded Values: Hardcoded values are used throughout the codebase without explanation.
- Commented-Out Code: Many files contain commented-out code that should be removed or implemented properly.
- Inconsistent Parameter Naming: Parameter names are inconsistent across similar components.
- Utility Functions in Component Files: Utility functions are often defined in component files instead of dedicated utility files.
- Complex Implementations: Many components have complex implementations that are difficult to understand and maintain.
- Lack of Error Handling: Many components lack proper error handling for edge cases.
- Add Documentation: Add KDoc comments to all public classes, functions, and properties.
- Split Large Files: Split files with mixed responsibilities into smaller, more focused files.
- Improve Error Handling: Add proper error handling to all asynchronous operations.
- Remove Commented-Out Code: Remove or fix commented-out code.
- Use Dependency Injection: Replace global constants and singletons with proper dependency injection.
- Add Unit Tests: Add unit tests to ensure the code works as expected and to prevent regressions.
- Refactor Repetitive Code: Extract repetitive code into reusable functions or components.
- Optimize Flow Operations: Optimize flow operations to avoid unnecessary work.
- Use Default Parameters: Replace overloaded functions with default parameters where appropriate.
- Improve Null Handling: Use more robust null handling patterns.
- Consolidate Navigation Implementations: Choose one navigation approach (either Navigation2 or Navigation3) and standardize the codebase on it.
- Improve Accessibility: Add proper content descriptions to all UI elements for better accessibility.
- Create Base Components: Create base components that can be extended for specific use cases to reduce code duplication.
- Standardize Error Messages: Use consistent error messages in
staticCompositionLocalOfdeclarations. - Extract Constants: Extract hardcoded values into well-named constants with proper documentation.
- Reduce Coupling: Reduce tight coupling between components to improve testability and maintainability.
- Optimize Performance: Review and optimize performance-critical code, especially animations and state management.
- Standardize Parameter Naming: Use consistent parameter naming across similar components.
- Improve Component Reusability: Design components to be more reusable and less specific to particular use cases.
- Add Proper Error Boundaries: Implement error boundaries to prevent crashes and provide better user feedback.