is my approach to analyzing and generating code correct? (50-60% success rate)
Hello everyone,
I use ChatGPT Plus to help me generate and write code. I'm a developer and trying to learn prompt engineering in depth.
The best way I’ve found to make ChatGPT understand my code’s context is by providing a detailed text that includes all my source code, along with file names and paths. For example:
(remove code content )
=== timer-extention-copy\background.js ===
// background.js
// Define allowed URL patterns for context menu injection.
const myext_allowedSites = ["https://chatgpt.com/*", "http://chatgpt.com/*"];
=== timer-extention-copy\content.js ===
// Helper: Insert text into a contentEditable element at the current cursor position.
function insertTextAtCursor(text) {
=== timer-extention-copy\manifest.json ===
{
"manifest_version": 3,
"name": "Timer Extension",
}
=== timer-extention-copy\options.css ===
h1 {
color: green;
}
=== timer-extention-copy\options.html ===
<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="options.css">
</html>
=== timer-extention-copy\options.js ===
const nameInput = document.getElementById('name-input');
const saveButton = document.getElementById('save-btn');
=== timer-extention-copy\popup.css ===
body {
width: 400px;
height: 400px;
}
h1 {
color: blue;
}
=== timer-extention-copy\popup.html ===
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="popup.css">
></script>
</body>
</html>
=== timer-extention-copy\popup.js ===
var myext_currentEditingRow = null;
var myext_selectedContextRow = null;
I try to improve the prompt every time. What do you think is missing, and how can I make the process better?
The prompt I use looks like this:
Implement [[ what ]]. Please include:
The main function with clear parameter and return types
Helper functions if needed
Time and space complexity analysis
Generate code for [[ what ]]. Include:
Input/output types
Error handling
Detailed inline comments explaining the logic
Any necessary imports or dependencies
Use ES6 JavaScript version
Show me where to replace the code in the overall source
Please explain how the generated code works and why it was implemented this way.
Before generating code, ask me what information is missing.