-
Notifications
You must be signed in to change notification settings - Fork 43
DOCSP-33345: Java comments pt. 4 #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOCSP-33345: Java comments pt. 4 #472
Conversation
d81935b
to
ce57a6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of great work here.
I think making the comments more consistent would be helpful in understanding the code, both by users and LLMs.
I think it might be helpful to keep track of (perhaps a separate doc) what code should be commented and which should not. I think we paired on some of this, but happy to contribute to a more formal list. I think it's a little unclear to us since we haven't gotten detailed feedback from CodeWhisperer, so maybe that list could help us identify the concerns.
source/includes/fundamentals/code-snippets/CompoundOperators.java
Outdated
Show resolved
Hide resolved
source/includes/fundamentals/code-snippets/CompoundOperatorsIndividualExamples.java
Outdated
Show resolved
Hide resolved
source/includes/fundamentals/code-snippets/CompoundOperatorsIndividualExamples.java
Outdated
Show resolved
Hide resolved
source/includes/fundamentals/code-snippets/CompoundOperatorsIndividualExamples.java
Outdated
Show resolved
Hide resolved
source/includes/fundamentals/code-snippets/CompoundOperatorsIndividualExamples.java
Outdated
Show resolved
Hide resolved
source/includes/fundamentals/code-snippets/CollationCollectionExample.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. There are a couple issues to address before merging, but approving since they're straightforward fixes.
collection.bulkWrite(bulkOperations); | ||
|
||
// Prints a message if any exceptions occur during the operations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the code comments sheet:
// Prints a message if any exceptions occur during the operations | |
// Prints a message if any exceptions occur during the bulk write operation |
InsertOneModel<Document> insertDoc = new InsertOneModel<>(new Document("_id", 6) | ||
.append("name", "Zaynab Omar") | ||
.append("age", 37)); | ||
|
||
// Creates instructions to replace the matching document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the code comments sheet:
// Creates instructions to replace the matching document | |
// Creates instructions to replace the first document that matches the query |
UpdateOneModel<Document> updateDoc = new UpdateOneModel<>(Filters.eq("name", "Zaynab Omar"), | ||
Updates.set("name", "Zaynab Hassan")); | ||
|
||
// Creates instructions to delete all matching documents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think it would be good for consistency to mention matching the query. Added to the code comment sheet.
// Creates instructions to delete all matching documents | |
// Creates instructions to delete all documents that match the query |
.append("name", "Zaynab Omar") | ||
.append("age", 37)); | ||
|
||
// Creates instructions to replace the matching document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think it's important to mention the first document matched by the query for all instances of "OneModel"s as described on the code comments sheet as it is otherwise inaccurate for the case in which there are more than one matches:
// Creates instructions to replace the matching document | |
// Creates instructions to replace the matching document |
Applies to all instances.
.collation(Collation.builder().locale("de").collationStrength(CollationStrength.PRIMARY).build()); | ||
|
||
// Prints the results of the aggregation that tallied value frequencies and sorted the results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think it could be good to keep the description consistent (e.g. line 65) within the file:
// Prints the results of the aggregation that tallied value frequencies and sorted the results | |
// Prints the JSON representation of the results |
Bson filter = Filters.eq("reserved", false); | ||
|
||
// Atomically finds and updates a document to mark it as reserved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think we landed on the following for findOneAndDelete which should be applied to findOneAndUpdate in the code comments sheet:
// Atomically finds and updates a document to mark it as reserved | |
// Updates the first document that matches the filter to mark it as reserved |
@@ -6,6 +6,9 @@ | |||
import com.mongodb.client.MongoDatabase; | |||
import com.mongodb.client.model.*; | |||
import com.mongodb.client.result.InsertOneResult; | |||
|
|||
import docs.builders.Filters; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question:
Is this import necessary? From a quick scan, I can't tell which file is in the docs.builders package. Please let me know if there's any reason not to delete it.
@@ -49,16 +56,26 @@ private void findOneAndUpdateExample() { | |||
MongoCollection<Document> collection = getCollection(); | |||
//start findOneAndUpdate-example | |||
// <MongoCollection set up code here> | |||
|
|||
// Creates a projection to exclude the "_id" field from the printed documents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue:
I think printed documents is inaccurate. The projection tells the server which fields to return.
Suggestion:
I think it would be better to use the language "retrieved documents" similar to the descriptions of the projection method used in the code comments sheet:
// Creates a projection to exclude the "_id" field from the printed documents | |
// Creates a projection to exclude the "_id" field from the retrieved documents |
@@ -67,18 +79,24 @@ private static void findOneAndUpdateExample(MongoCollection<Document> collection | |||
.collation(Collation.builder().locale("de@collation=phonebook").build()) | |||
.sort(Sorts.ascending("first_name")) | |||
.returnDocument(ReturnDocument.AFTER)); | |||
|
|||
// Prints the JSON representation of the updated document, if an update occurred |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think it would be more grammatical to omit this comma.
// Prints the JSON representation of the updated document, if an update occurred | |
// Prints the JSON representation of the updated document if an update occurred |
* DOCSP-33345: Java code comments pt. 4 * bulkwrite CC feedback * applying CC feedback * small edit * half of feedback * rest of feedback * single line comment * duplicate comments sheet suggestions * small edit * final feedback (cherry picked from commit 4b9070c)
* DOCSP-33345: Java code comments pt. 4 * bulkwrite CC feedback * applying CC feedback * small edit * half of feedback * rest of feedback * single line comment * duplicate comments sheet suggestions * small edit * final feedback (cherry picked from commit 4b9070c)
* DOCSP-33345: Java code comments pt. 4 * bulkwrite CC feedback * applying CC feedback * small edit * half of feedback * rest of feedback * single line comment * duplicate comments sheet suggestions * small edit * final feedback (cherry picked from commit 4b9070c) (cherry picked from commit fd983e9)
* DOCSP-33345: Java code comments pt. 4 * bulkwrite CC feedback * applying CC feedback * small edit * half of feedback * rest of feedback * single line comment * duplicate comments sheet suggestions * small edit * final feedback (cherry picked from commit 4b9070c) (cherry picked from commit fd983e9)
* DOCSP-33345: Java code comments pt. 4 * bulkwrite CC feedback * applying CC feedback * small edit * half of feedback * rest of feedback * single line comment * duplicate comments sheet suggestions * small edit * final feedback (cherry picked from commit 4b9070c) (cherry picked from commit fd983e9)
* DOCSP-33345: Java code comments pt. 4 * bulkwrite CC feedback * applying CC feedback * small edit * half of feedback * rest of feedback * single line comment * duplicate comments sheet suggestions * small edit * final feedback (cherry picked from commit 4b9070c) (cherry picked from commit fd983e9)
* DOCSP-33345: Java code comments pt. 4 * bulkwrite CC feedback * applying CC feedback * small edit * half of feedback * rest of feedback * single line comment * duplicate comments sheet suggestions * small edit * final feedback (cherry picked from commit 4b9070c) (cherry picked from commit fd983e9)
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-33345
Staging:
Aggregation - https://preview-mongodbnorareidy.gatsbyjs.io/java/DOCSP-33345-java-comments-4/fundamentals/aggregation/
BulkWrite - https://preview-mongodbnorareidy.gatsbyjs.io/java/DOCSP-33345-java-comments-4/fundamentals/crud/write-operations/bulk/
Collation - https://preview-mongodbnorareidy.gatsbyjs.io/java/DOCSP-33345-java-comments-4/fundamentals/collations/
Compound operators and individual example - https://preview-mongodbnorareidy.gatsbyjs.io/java/DOCSP-33345-java-comments-4/fundamentals/crud/compound-operations/
Self-Review Checklist