Back to all reviewers

Constructor over setter

langchain-ai/langchainjs
Based on 3 comments
Other

Prefer passing configuration through constructor parameters rather than setting properties after instantiation. This makes APIs more predictable, enables immutability, and clearly communicates required dependencies at creation time. Additionally, use consistent method naming conventions like `.invoke()` for primary API methods.

API Other

Reviewer Prompt

Prefer passing configuration through constructor parameters rather than setting properties after instantiation. This makes APIs more predictable, enables immutability, and clearly communicates required dependencies at creation time. Additionally, use consistent method naming conventions like .invoke() for primary API methods.

Instead of this:

const loader = new GoogleDriveLoader();
loader.recursive = true;
loader.folderId = "YourGoogleDriveFolderId";

Do this:

const loader = new GoogleDriveLoader({
  recursive: true,
  folderId: "YourGoogleDriveFolderId"
});

Similarly, when adding methods to an API class, prefer descriptive action names like invoke() over generic terms like call(). This creates a more intuitive API that follows established patterns across the ecosystem.

3
Comments Analyzed
Other
Primary Language
API
Category

Source Discussions