---
title: 'Max lines for class. Default: 100 lines'
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Max lines for class. Default: 100 lines
---

# Max lines for class. Default: 100 lines

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `swift-code-style/max-class-lines`

**Language:** Swift

**Severity:** Warning

**Category:** Best Practices

## Description{% #description %}

This rule states that Swift classes should not exceed 1000 lines of code (by default). The purpose of this guideline is to ensure code remains readable and maintainable. Large classes can become difficult to understand, debug, and maintain, increasing the likelihood of bugs and inefficiencies.

Following this rule promotes clean code practices and fosters efficient software development. It encourages developers to adopt modularity by breaking down complex problems into smaller, more manageable pieces.

To prevent classes from becoming too large, it is good practice to split functionality into multiple smaller classes, each with a single, well-defined responsibility. If a class is growing too complex, evaluate whether some of its functionality can be moved to a separate class. You can use inheritance or composition to help distribute responsibilities. For example, if `MyClass` is too large, you could create a new class, `MySubClass`, and let `MyClass` inherit from it:

```gdscript3
class MySubClass {
    func foo() {}
}

class MyClass: MySubClass {
    override init() {
        super.init()
    }
}
```

The goal is to write code that is easy to read, understand, and maintain. By keeping classes concise and focused, you can improve code quality and make your software easier to work with.

## Arguments{% #arguments %}

- `max-lines`: Maximum number of lines. Default: 100.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```swift
// This class is NOT compliant because it is >100 lines long.
class Person {
    var name: String
    var age: Int
    var occupation: String?
    
    init(name: String, age: Int, occupation: String? = nil) {
        self.name = name
        self.age = age
        self.occupation = occupation
    }





















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































    func displayOccupation() {
        print(self.age);
    }
}
```

## Compliant Code Examples{% #compliant-code-examples %}

```swift
// This class is compliant because it is <=100 lines long.
class Person {
    var name: String
    var age: Int
    var occupation: String?
    
    init(name: String, age: Int, occupation: String? = nil) {
        self.name = name
        self.age = age
        self.occupation = occupation
    }

    func displayOccupation() {
        print(self.age);
    }
}
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 