A snippet is easier to reread when it solves a single problem. Provide the language, input, output, and edge cases. Request a usage example and avoid running a snippet you haven't reviewed.
Ten useful requests
- Sort dates, keeping unknown values at the end.
- Load a CSV and UTF-8 and flag the rows with a different number of columns.
- Deduplicate a list of identifiers while preserving their order of appearance.
- Format an amount with a chosen currency and locale.
- Generate filenames without overwriting existing ones.
- Filter a HTML array using a keyboard-accessible search.
- Construct a URL with correctly encoded parameters.
- Validate a JSON configuration and list missing fields.
- Group a task list by status, including unknown status.
- Write a test that checks for an empty input of a function.
Propose the Python snippet for the CSV. Provide a valid example, an incomplete row, and the expected message. I'll keep the trophy for review.
Reuse the correct snippet
Check the dependencies and behavior on your data. Add the test example to the project to document the snippet contract. Note the language version if a recent function is used.
Example snippet to import a CSV
You receive a UTF-8 array with three expected columns. Give NeoCode an example of a valid row and a row where the third field is missing. Describe the desired result. The program could, for example, return the valid rows and a list of errors with their numbers. Specify the separator and the presence of a header.
Request the function code and two reproducible tests. Review how the snippet opens the file and handles quotation marks around text containing a separator. Add an example with an accented character and a blank line. If you need to accept multiple formats, have the rules for each specified before expanding the function.
Choose the control based on the snippet type.
- Sorting or deduplication. Check the order, repeated values, and empty input.
- Name generation. Test two identical inputs and a file that already exists.
- Array filter. Try a search with no results, then clear it and check the returned list.
- Validation. Test for a valid entry and an error for each required field.
Place the tests alongside the snippet you're keeping. When you change the language, data format, or a dependency, rerun these examples before integrating the snippet into the project.
See also
Have an extract checked before reusing it.
A short snippet becomes more useful when it specifies its inputs, outputs, and the cases it should handle. For an import of CSV, specify the separator, column names, and number format. Prepare three dummy lines that cover a normal value, a missing value, and text containing the separator in quotation marks. The test should demonstrate how the snippet reads each line.
Ask NeoCode to explain the dependencies and where the snippet will be called. If the project already has a read function, provide its contract and ask how to reuse that logic. For an existing error format, verify that the new snippet returns a compatible error. A standalone example can facilitate the initial test, followed by testing within the project to verify the actual calls.
Give me a short snippet to process these three lines. Specify the inputs, the expected output, and the errors I need to test for. Use the existing functions whose signatures I provide.
Review the result with the next modification in mind. Note where to change the format, the column name, or the rule for a missing value. Run a case that existed before the addition and compare its output. For a snippet that writes to a file, verify the name and location on a copy. Keep the original example with the code so you can perform a quick test as the project evolves.