This product is not supported for your selected Datadog site. ().
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

ID: swift-code-style/increment-decrement-single-stmt

Language: Unknown

Severity: Notice

Category: Best Practices

Description

Increments (++) or decrements (--) should be single statements. This rule is important because it helps to avoid confusion and potential errors in your code. When increments or decrements are combined with other operations, it can be difficult to understand the order in which the operations are performed. This can lead to unexpected results and bugs in your code.

Non-Compliant Code Examples

foo = ++bar - baz--
foo = bar++

foo(bar++)

Compliant Code Examples

++foo
bar++
--foo
func factorial(_ n: Int) -> Int {
    guard n >= 0 else {
        foo++
    }
    --bar
    return n == 0 ? 1 : n * factorial(n - 1)
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains