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/tuples-too-large

Language: Unknown

Severity: Notice

Category: Best Practices

Description

Tuples should not be too large. This is because tuples are designed to be simple, quick ways to group related values. They are not meant to serve as data structures or record types, which are better suited to handle larger amounts of data.

To avoid the violation of this rule, you should consider using a struct or a class when you find yourself needing a tuple with more than two or three items. For example, instead of func myfunction() -> (Int, Int, Int, String) {}, you could define a struct like this: struct MyFunctionResult { let a: Int; let b: Int; let c: Int; let d: String }, and then have myfunction() return a MyFunctionResult. This makes your code more readable and easier to maintain.

Non-Compliant Code Examples

func myfunction() -> (Int, Int, Int, String) {}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains