> For the complete documentation index, see [llms.txt](https://vala.gitbook.io/vala/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vala.gitbook.io/vala/advanced-features/contract-programming.md).

# Ассерты и контрактное программирование

С ассертами программист может проверять допущения во время работы программы. Синтакс при этом - assert(условие). Если ассерт не верен, то выполнение программы прекратиться с соответствующим сообщением об ошибке. Существует еще несколько видов ассертов в стандартном пространстве имен GLib:

| assert\_not\_reached()      |
| --------------------------- |
| return\_if\_fail(bool expr) |
| return\_if\_reached()       |
| warn\_if\_fail(bool expr)   |
| warn\_if\_reached()         |

Вы можете попытаться использовать ассерты для проверки аргументов метода на null. Однако это вовсе не обязательно, т.к. Vala неявно проверяет все методы, которые не помечены ?.

```csharp
void method_name(Foo foo, Bar bar) {
    /* Не обязательно, Vala делает это за вас:
    return_if_fail(foo != null);
    return_if_fail(bar != null);
    */
}
```

Vala поддерживает базовые возможности контрактного программирования. Метод может имет предусловия(требования) и постусловия (удостоверение), которые должны пройти до и после выполнения метода соответственно:

```csharp
double method_name(int x, double d)
        requires (x > 0 && x < 10)
        requires (d >= 0.0 && d <= 1.0)
        ensures (result >= 0.0 && result <= 10.0)
{
    return d * x;
}
```

`результатом` является специальная переменная, представляющая возвращаемое значение.<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://vala.gitbook.io/vala/advanced-features/contract-programming.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
