AI assistants in coding: Difference between revisions

Tag: wikieditor
Tag: wikieditor
 
(3 intermediate revisions by the same user not shown)
Line 13: Line 13:


== Prompts cases ==
== Prompts cases ==
=== Imporve the quality of Meta-prompt ===
=== Improve the quality of Meta-prompt ===
Prompt
Prompt
<pre>
<pre>
Line 109: Line 109:
JetBrain 推出 [https://plugins.jetbrains.com/plugin/22282-ai-assistant AI Assistant 外掛]功能,目前付費客戶可以免費試用 7 天。它下的 prompt,供大家參考
JetBrain 推出 [https://plugins.jetbrains.com/plugin/22282-ai-assistant AI Assistant 外掛]功能,目前付費客戶可以免費試用 7 天。它下的 prompt,供大家參考


==== 國語版 ====
==== Prompt from JetBrain ====
<pre>
為 "XXXClass" 類別中的 "xxx" 方法撰寫 "XXXClassTest" 測試。 指南:
 
- 撰寫類別和方法的測試描述。
- 測試檔案應該是完整且可編譯的,不需要進一步的操作。
- 確保每個測試專注於單一用例,以保持清晰和可讀性。
- PHP 測試檔案必須以 PHP 開頭標籤 ?php 開始
- 生成的測試類別應該在命名空間 XXX
- 檔案:XXXClass.php
 
```php
附上程式碼
```
</pre>
 
==== 英文版 ====
<pre>
<pre>
Write "XXXClassTest' tests for the
Write "XXXClassTest' tests for the
Line 141: Line 125:
</pre>
</pre>


==== Prompt with Complete Testing Strategy ====
<pre>
Write complete unit tests for the "$METHOD_NAME" method in the "$CLASS_NAME" class.
## Test Target
- Class: $CLASS_NAME
- Method: $METHOD_NAME
- Test Class Name: ${CLASS_NAME}Test
- Namespace: $NAMESPACE
- Source File: $FILE_NAME
## Source Code
\```php
$CODE
\```
## Writing Conventions
**File Structure**
- Test file must begin with `<?php`
- Namespace should be `Tests\$NAMESPACE`
- Place test file at `__tests__/${CLASS_NAME}Test.php`
**Test Conventions**
- Extend `PHPUnit\Framework\TestCase`
- Each test method should cover only a single behavior
- Method naming format: `test_[method_name]_[scenario_description]`
- Use `setUp()` to initialize shared objects
**Coverage**
- Happy Path: expected results under normal input
- Edge Cases: boundary values, null values, extreme inputs
- Error States: thrown exceptions, error returns
## Output Requirements
- Test file must be complete and executable without any modifications
- Add a comment above each test method describing its purpose
- Include the CLI command to run the test file
</pre>
Instruction of Complete Testing Strategy
1. '''Happy Path''' — Verifies the program behaves correctly under expected, valid inputs.
<pre lang="php">
// e.g. formatDate should return the correct format when given a valid date
$this->assertSame('2024/01/15', $this->formatter->format('2024-01-15'));
</pre>
2. '''Edge Cases''' — Covers extreme or atypical but still valid inputs.
<pre lang="php">
// e.g. empty string, zero value, maximum integer, boundary date
$this->assertSame('', $this->formatter->format(''));
</pre>
3. '''Error States''' — Validates how the program handles illegal inputs or system failures.
<pre lang="php">
// e.g. should throw an exception or degrade gracefully when an invalid date is passed
$this->expectException(\InvalidArgumentException::class);
$this->formatter->format(null);
</pre>
==== Simple version ====


Simple version
<pre>
<pre>
Write PHPUnit test case including edge cases
Write PHPUnit test case including edge cases
Line 176: Line 224:
```
```
SQL syntax ...
SQL syntax ...
```
</pre>
=== Prompt for Direct Code Analysis ===
Use Case: When AI debugging tools aren't working (agents, IDEs, etc.), try a clean approach: Use web-based AI with just the code—no context, no error messages. Simply ask "What's wrong with this code?" or "Find any issues?"
This fresh perspective often solves stubborn problems by avoiding bias from error messages and predetermined fix patterns, uncovering root causes that were previously missed.
Example 1
<pre>
Find any issues in this code:
```
source code ...
```
</pre>
Example 2
<pre>
What problems do you see in this code?
```
source code ...
```
</pre>
Example 3
<pre>
Review this code and identify potential issues:
```
source code ...
```
```
</pre>
</pre>
Line 192: Line 270:
* [https://edge.aif.tw/anitahu-interview-talent-education/ 生成式 AI 增加學生溝通能力?胡敏君:因有強烈動機與好奇心]
* [https://edge.aif.tw/anitahu-interview-talent-education/ 生成式 AI 增加學生溝通能力?胡敏君:因有強烈動機與好奇心]


[[Category:Programming]]
[[Category: Programming]]
[[Category:OpenAI]]
[[Category: Generative AI]]
[[Category:Artificial intelligence]]
[[Category: Revised with LLMs]]
[[Category:Generative AI]]