Skip to content
kurnakovv edited this page Mar 28, 2025 · 1 revision

Tabs vs Spaces

We use tabs

Reason: because it is a more popular way for dotnet applications

Cancellation tokens (ct)

Alway put cancellation token in method signature even if this operation does not need it. In this case use default keyword

For example

[HttpPost]
public async Task<IActionResult> Add(
    // Other parameters...
    CancellationToken ct
)
{
    // Logic...
    await _db.SaveChangesAsync(ct);
    // or
    await _db.SaveChangesAsync(default);
    return Ok();
}

Reason: another developer who doesn't know the original idea won't understand what you wanted to do: either you didn't specify the ct on purpose, or you simply forgot to add it. If you use the default keyword, you clearly show that you didn't forget anything.

Braces

Use braces instead of single lines

For example

// Bad
if (a)
    M1();
else if (b)
    M2();
else
    M3();

// Good
if (a)
{
    M1();
}
else if (b)
{
    M2();
}
else
{
    M3();
}

Reason: if you add more logic to the methods, you will have to add curly brackets, and this is not very convenient, especially when solving git conflicts, and sometimes it is not very convenient to read. So saving lines does not make sense

if/else if vs switch

ToDo

Ternary operators

ToDo

(Reach vs Anemic) domain logic

ToDo

Clone this wiki locally