Coding standards
Coding conventions and style rules for Smartstore
Consistency keeps the Smartstore codebase approachable and maintainable. This guide summarizes the most important rules developers should follow when contributing code.
Naming conventions
Types, methods, properties:
PascalCase.Fields and locals:
camelCase; prefix private fields with_.Interfaces: prefix with
I(e.g.,IPriceCalculator).Async methods: suffix with
Async.Generics: use
Tprefixes (TContext,TEntity).Avoid abbreviations; if necessary, capitalize like
HttpClientorDbContext.
public interface IEmailSender
{
Task SendAsync(EmailMessage message, CancellationToken cancelToken = default);
}Layout and formatting
Indent with four spaces, never tabs.
Brace style: Allman – opening braces on their own line.
Place
usingdirectives at the top, sorted alphabetically withSystemfirst.Keep file length reasonable; split large classes into partials.
Enable nullable reference types in every file:
#nullable enable.
Guard clauses and exceptions
Validate arguments early to keep methods small and predictable. Throw ArgumentException derivatives for bad input and domain‑specific exceptions for business rules.
Asynchronous programming
All I/O operations should be asynchronous.
Use
async/await; never block with.Resultor.Wait().Propagate
CancellationTokenparameters.Prefer value tasks for hot paths returning synchronously.
Dependency injection
Prefer constructor injection and keep services focused on a single responsibility. Avoid service locators or static access. Controllers deriving from SmartController receive ICommonServices via the Services property and do not need manual injection.
Logging
Expose an optional logger property so DI can inject a contextual ILogger.
Client code
Use Bootstrap utility classes where possible.
Write JavaScript with progressive enhancement in mind and keep dependencies minimal.
Keep comments short and in English.
Following these standards helps ensure that Smartstore remains a clean, predictable, and enjoyable platform to work with.
Last updated
Was this helpful?