clean-code-dotnet
БесплатноБез исполняемых скриптовНе проверенClean Code principles adapted for C#/.NET including naming, variables, functions, SOLID, error handling, and async patterns. Use when: (1) reviewing C# code…
Об этом скилле
Clean Code .NET
Clean Code principles from Robert C. Martin, adapted for C#/.NET. Use as checklist during code reviews and refactoring.
Naming
Use Meaningful Names
// ❌ Bad
int d;
var dataFromDb = db.GetFromService().ToList();
// ✅ Good
int daySinceModification;
var employees = _employeeService.GetEmployees().ToList();
Avoid Hungarian Notation
// ❌ Bad
int iCounter;
string strFullName;
public bool IsShopOpen(string pDay, int pAmount) { }
// ✅ Good
int counter;
string fullName;
public bool IsShopOpen(string day, int amount) { }
Use Pronounceable Names
// ❌ Bad
public class Employee
{
public DateTime sWorkDate { get; set; }
public DateTime modTime { get; set; }
}
// ✅ Good
public class Employee
{
public DateTime StartWorkingDate { get; set; }
public DateTime ModificationTime { get; set; }
}
Use Domain Names
// ✅ Good - Use patterns developers know
var singletonObject = SingleObject.GetInstance();
var factory = new PatientFactory();
var repository = new PatientRepository();
Variables
Return Early, Avoid Deep Nesting
// ❌ Bad - Deep nesting
public bool IsShopOpen(string day)
{
if (!string.IsNullOrEmpty(day))
{
day = day.ToLower();
if (day == "friday")
{
return true;
}
else if (day == "saturday")
{
return true;
}
// ... more nesting
}
return false;
}
// ✅ Good - Guard clauses + early return
public bool IsShopOpen(string day)
{
if (string.IsNullOrEmpty(day))
return false;
var openingDays = new[] { "friday", "saturday", "sunday" };
return openingDays.Contains(day.ToLower());
}
Avoid Magic Strings
// ❌ Bad
if (userRole == "Admin") { }
// ✅ Good
const string AdminRole = "Admin";
if (userRole == AdminRole) { }
// ✅ Better - Use enum
public enum UserRole { Admin, User, Guest }
if (userRole == UserRole.Admin) { }
Don't Add Unneeded Context
// ❌ Bad - Redundant prefix
public class Car
{
public string CarMake { get; set; }
public string CarModel { get; set; }
public string CarColor { get; set; }
}
// ✅ Good
public class Car
{
public string Make { get; set; }
public string Model { get; set; }
public string Color { get; set; }
}
Use Default Arguments
// ❌ Bad
public void CreateMicrobrewery(string name = null)
{
var breweryName = !string.IsNullOrEmpty(name) ? name : "Hipster Brew Co.";
}
// ✅ Good
public void CreateMicrobrewery(string breweryName = "Hipster Brew Co.")
{
// breweryName is always valid
}
Functions
Functions Should Do One Thing
// ❌ Bad - Multiple responsibilities
public void SendEmailToListOfClients(string[] clients)
{
foreach (var client in clients)
{
var clientRecord = db.Find(client);
if (clientRecord.IsActive())
{
Email(client);
}
}
}
// ✅ Good - Single responsibility
public void SendEmailToActiveClients(string[] clients)
{
var activeClients = GetActiveClients(clients);
activeClients.ForEach(client => Email(client));
}
public List<Client> GetActiveClients(string[] clients)
{
return db.Find(clients).Where(c => c.IsActive).ToList();
}
Avoid Side Effects
// ❌ Bad - Modifies global state
var name = "Ryan McDermott";
public void SplitAndEnrichFullName()
{
var temp = name.Split(" ");
name = $"First: {temp[0]}, Last: {temp[1]}"; // Side effect!
}
// ✅ Good - Pure function
public string SplitAndEnrichFullName(string name)
{
var temp = name.Split(" ");
return $"First: {temp[0]}, Last: {temp[1]}";
}
Avoid Negative Conditionals
// ❌ Bad
public bool IsDOMNodeNotPresent(string node) { }
if (!IsDOMNodeNotPresent(node)) { } // Double negative!
// ✅ Good
public bool IsDOMNodePresent(string node) { }
if (IsDOMNodePresent(node)) { }
Avoid Flag Parameters
// ❌ Bad - Flag indicates multiple responsibilities
public void CreateFile(string name, bool temp = false)
{
if (temp)
Touch("./temp/" + name);
else
Touch(name);
}
// ✅ Good - Separate methods
public void CreateFile(string name) => Touch(name);
public void CreateTempFile(string name) => Touch("./temp/" + name);
Limit Function Arguments (2 or fewer)
// ❌ Bad
public void CreateMenu(string title, string body, string buttonText, bool cancellable) { }
// ✅ Good - Use object
public class MenuConfig
{
public string Title { get; set; }
public string Body { get; set; }
public string ButtonText { get; set; }
public bool Cancellable { get; set; }
}
public void CreateMenu(MenuConfig config) { }
Encapsulate Conditionals
// ❌ Bad
if (article.state == "published") { }
// ✅ Good
if (article.IsPublished()) { }
Remove Dead Code
// ❌ Bad
public void OldRequestModule(s
Установить clean-code-dotnet в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл clean-code-dotnet?
Clean Code principles adapted for C#/.NET including naming, variables, functions, SOLID, error handling, and async patterns. Use when: (1) reviewing C# code, (2) refactoring for clarity, (3) writing new code, (4) code review feedback.
Как установить скилл clean-code-dotnet?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл clean-code-dotnet запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic