Skip to content

This PR contains focused code quality improvements identified through systematic codebase analysis. All changes maintain backward compatibility and follow the project's contribution guidelines.#270

Open
surajsahani wants to merge 2 commits intoKotlin:developfrom
surajsahani:code-quality-improvements

Conversation

@surajsahani
Copy link

@surajsahani surajsahani commented Feb 23, 2026

Changes Made

1. Fixed Redundant Null Check in DataType.kt

File: multik-core/src/commonMain/kotlin/org/jetbrains/kotlinx/multik/ndarray/data/DataType.kt

Issue: The of() function had a redundant null-forgiving operator (!!) after an elvis operator that already throws on null.

Before:

public inline fun <T> of(element: T): DataType {
    element ?: throw IllegalStateException("Element is null cannot find type")
    return dataTypeOf(element!!::class)  // Redundant !!
}

After:

public inline fun <T> of(element: T): DataType {
    element ?: throw IllegalStateException("Element is null cannot find type")
    return dataTypeOf(element::class)  // Clean, no redundant operator
}

Impact: Improves code clarity and follows Kotlin best practices.


2. Added Comprehensive KDoc to EngineFactory Interface

File: multik-core/src/commonMain/kotlin/org/jetbrains/kotlinx/multik/api/EngineFactory.kt

Issue: Public API interface lacked documentation explaining its purpose, usage, and exception behavior.

Added:

  • Interface-level KDoc explaining the factory pattern and platform-specific behavior
  • Method-level KDoc documenting parameters, return values, and exceptions
  • Cross-references to related types (Engine, EngineType)

Impact: Improves API discoverability and developer experience. Aligns with project documentation standards.


3. Removed Explicit Unit Return Types in ComplexArrays.kt

File: multik-core/src/commonMain/kotlin/org/jetbrains/kotlinx/multik/ndarray/complex/ComplexArrays.kt

Issue: Two set() operator functions explicitly declared : Unit return type, which is redundant in Kotlin.

Before:

public operator fun set(index: Int, value: ComplexFloat): Unit { ... }
public operator fun set(index: Int, value: ComplexDouble): Unit { ... }

After:

public operator fun set(index: Int, value: ComplexFloat) { ... }
public operator fun set(index: Int, value: ComplexDouble) { ... }

Impact: Follows Kotlin coding conventions and improves code consistency.


Testing

  • All changes verified with diagnostics - no compilation errors
  • Changes are purely cosmetic/documentation and don't affect runtime behavior
  • No new tests required as changes don't modify behavior

Backward Compatibility

✅ All changes maintain full backward compatibility:

  • No API signatures changed (removing : Unit is binary compatible)
  • No behavior modifications
  • No new dependencies
  • No breaking changes

Checklist

  • Based on develop branch
  • Follows Kotlin Coding Conventions (4 spaces, imports with '*')
  • All public APIs have KDoc documentation
  • No breaking changes
  • Code compiles without errors
  • Changes align with CONTRIBUTING.md guidelines
  • Minimal, focused improvements

Additional Context

During the codebase analysis, several other improvement opportunities were identified for future PRs:

  • 30+ unimplemented TODO methods in NativeEngine
  • Wildcard imports in multiple files
  • Excessive deepCopy() calls in arithmetic operations
  • Missing test coverage for axis-based operations

These are documented separately and can be addressed in follow-up contributions.

…icit Unit returns

- Remove redundant null-forgiving operator in DataType.of()
- Add comprehensive KDoc to EngineFactory interface
- Remove explicit Unit return types from ComplexArrays set() operators

All changes maintain backward compatibility and follow Kotlin coding conventions.
Copilot AI review requested due to automatic review settings February 23, 2026 13:43
@surajsahani surajsahani changed the title Improve code quality: fix redundant null check, add KDoc, remove expl… This PR contains focused code quality improvements identified through systematic codebase analysis. All changes maintain backward compatibility and follow the project's contribution guidelines. Feb 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request focuses on code quality improvements across three files in the Multik library, including removing a redundant null-check operator, adding comprehensive KDoc documentation to the EngineFactory interface, and removing explicit Unit return types from operator functions. The changes align with Kotlin coding conventions and maintain backward compatibility.

Changes:

  • Removed redundant !! null-forgiving operator in DataType.of() after null check
  • Added KDoc documentation to EngineFactory interface and its getEngine() method
  • Removed explicit : Unit return type declarations from ComplexFloatArray.set() and ComplexDoubleArray.set() operators

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
multik-core/src/commonMain/kotlin/org/jetbrains/kotlinx/multik/ndarray/data/DataType.kt Removed redundant null-forgiving operator after null check
multik-core/src/commonMain/kotlin/org/jetbrains/kotlinx/multik/ndarray/complex/ComplexArrays.kt Removed explicit Unit return types from set operators to align with Kotlin conventions
multik-core/src/commonMain/kotlin/org/jetbrains/kotlinx/multik/api/EngineFactory.kt Added comprehensive KDoc documentation for the interface and getEngine method

- Clarify that EngineFactory is a simple factory pattern
- Move platform-specific discovery details to enginesProvider reference
- Fix @throws tag to document IllegalStateException (from error()) instead of EngineMultikException
- Add cross-reference to enginesProvider function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants