Moved documents to their own directory
This commit is contained in:
parent
ef03c8a039
commit
b4fdbcc025
2 changed files with 0 additions and 0 deletions
21
documents/PowerOf10Prompt.txt
Normal file
21
documents/PowerOf10Prompt.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
You are an expert English-speaking software developer specializing in writing clean, efficient, and reliable code. As a software developer, your task is to write complete, self-contained programs that adhere to best practices for safety, maintainability, and performance.
|
||||
|
||||
Focus on:
|
||||
- Writing clear, well-structured, and maintainable code
|
||||
- Following best practices for security, performance, and reliability
|
||||
- Ensuring portability and adaptability across different environments
|
||||
- Managing resources efficiently and safely
|
||||
|
||||
Follow these guidelines to enhance software safety and reliability:
|
||||
- Avoid overly complex control structures; prioritize clarity and simplicity in logic.
|
||||
- Restrict dynamic memory allocation where unnecessary; prefer predictable resource management.
|
||||
- Keep functions or methods short and focused to improve readability and maintainability.
|
||||
- Enforce runtime checks and assertions where applicable to catch unexpected behavior early.
|
||||
- Minimize the scope of variables and functions to reduce unintended side effects.
|
||||
- Always validate and sanitize input to prevent security vulnerabilities.
|
||||
- Use preprocessors, macros, or metaprogramming techniques sparingly to maintain code clarity.
|
||||
- Limit the use of global state, direct memory manipulation, or unsafe operations.
|
||||
- Enable and address all warnings and errors provided by linters, compilers, or static analyzers.
|
||||
- Always comment your code. Use documentation-style for functions or methods.
|
||||
|
||||
Adapt these principles to the capabilities of the programming language while maintaining a strong emphasis on writing robust, secure, and maintainable software.
|
175
documents/Powerof10Guide.md
Normal file
175
documents/Powerof10Guide.md
Normal file
|
@ -0,0 +1,175 @@
|
|||
# Power of 10 for C#
|
||||
|
||||
I asked the AI to write their instructions in the form of guidelines. I figured I'd use C# since it's both my preferred language and the syntax should be fairly easy to grasp once you understand the basics. My only request was to apply .NET 6's [top-level statements]([Top-level statements tutorial - C# | Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/top-level-statements)) for brevity. Aside from that, it all works flawlessly.
|
||||
|
||||
## 1. Write Clear, Well-Structured, and Maintainable Code
|
||||
|
||||
- Keep the code simple and coherent. Use meaningful identifiers and limit the complexity of expressions.
|
||||
- Keep functions or methods short, with a single responsibility.
|
||||
|
||||
**Example:**
|
||||
|
||||
```csharp
|
||||
// Good example of a short, focused method
|
||||
int Sum(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// Good example of clear, well-structured code
|
||||
var result = Sum(5, 3);
|
||||
Console.WriteLine($"The sum is {result}");
|
||||
```
|
||||
|
||||
## 2. Follow Best Practices for Security, Performance, and Reliability
|
||||
|
||||
- Validate and sanitize inputs to prevent security vulnerabilities like injection attacks.
|
||||
- Use try-catch blocks to handle exceptions gracefully.
|
||||
|
||||
**Example:**
|
||||
|
||||
```csharp
|
||||
using System.Globalization;
|
||||
|
||||
string userInput = "2023-10-30";
|
||||
if (DateTime.TryParseExact(userInput, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date))
|
||||
{
|
||||
Console.WriteLine($"Parsed date: {date}");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FormatException("Invalid date format.");
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Ensure Portability and Adaptability Across Different Environments
|
||||
|
||||
- Use environment variables or configuration files for environment-specific settings.
|
||||
- Rely on cross-platform libraries within .NET.
|
||||
|
||||
**Example:**
|
||||
|
||||
```csharp
|
||||
// Reading configuration using environment variables
|
||||
var configValue = Environment.GetEnvironmentVariable("CONFIG_KEY");
|
||||
if (configValue != null)
|
||||
{
|
||||
Console.WriteLine($"Configuration value: {configValue}");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Configuration key not found.");
|
||||
}
|
||||
```
|
||||
|
||||
## 4. Manage Resources Efficiently and Safely
|
||||
|
||||
- Prefer `using` statements to safely manage resource cleanup.
|
||||
- Avoid excessive memory allocation and prefer stack-allocated variables.
|
||||
|
||||
**Example:**
|
||||
|
||||
```csharp
|
||||
// Using statement to ensure safe disposal
|
||||
using (var reader = new StreamReader("example.txt"))
|
||||
{
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
Console.WriteLine(line);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Use Minimal Scope for Variables and Functions
|
||||
|
||||
- Limit the visibility of variables and functions to the smallest scope necessary.
|
||||
|
||||
**Example:**
|
||||
|
||||
```csharp
|
||||
void Main()
|
||||
{
|
||||
int a = 5, b = 3;
|
||||
Console.WriteLine($"Sum: {Add(a, b)}");
|
||||
|
||||
// 'a' and 'b' are limited to Main method scope
|
||||
}
|
||||
|
||||
int Add(int a, int b)
|
||||
{
|
||||
// 'a' and 'b' are limited to Add method scope
|
||||
return a + b;
|
||||
}
|
||||
```
|
||||
|
||||
## 6. Always Validate and Sanitize Input
|
||||
|
||||
- Sanitize and validate all external inputs to secure your application.
|
||||
|
||||
**Example:**
|
||||
|
||||
```csharp
|
||||
using System.Web;
|
||||
|
||||
string input = Console.ReadLine();
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
throw new ArgumentException("Input cannot be null or whitespace.");
|
||||
}
|
||||
else
|
||||
{
|
||||
string sanitizedInput = HttpUtility.HtmlEncode(input);
|
||||
Console.WriteLine($"Processed input: {sanitizedInput}");
|
||||
}
|
||||
```
|
||||
|
||||
## ## 7. Documentation Comments
|
||||
|
||||
- Use XML documentation comments for functions or methods to improve maintainability and provide documentation.
|
||||
|
||||
**Example:**
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Sums two integers.
|
||||
/// </summary>
|
||||
/// <param name="a">The first integer.</param>
|
||||
/// <param name="b">The second integer.</param>
|
||||
/// <returns>The sum of the two integers.</returns>
|
||||
int Sum(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
```
|
||||
|
||||
## Example Using Top-Level Statements in .NET 6
|
||||
|
||||
Combining several of the above principles:
|
||||
|
||||
```csharp
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
string userInput = "45";
|
||||
if (!int.TryParse(userInput, out int number))
|
||||
{
|
||||
throw new FormatException("Invalid integer format.");
|
||||
}
|
||||
|
||||
Console.WriteLine($"Parsed number: {number}");
|
||||
|
||||
void ProcessDate(string dateString)
|
||||
{
|
||||
if (DateTime.TryParseExact(dateString, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date))
|
||||
{
|
||||
Console.WriteLine($"Parsed date: {date}");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FormatException("Invalid date format.");
|
||||
}
|
||||
}
|
||||
|
||||
ProcessDate("2023-10-31");
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue