# Lambdas

Use lambda expressions and interfaces to increase modularity in your code.

{% tabs %}
{% tab title="C++" %}
Avoid catching all by value `[=]` or by reference `[&]` when declaring a lambda function. Try to list out every variable your lambda will need, and prefer to pass by reference as opposed to by value.

When using a function pointer, always put the `&` (dereference operator) to avoid any confusion.

BAD:

```
foo(frc5431::myLambda);
```

GOOD:

```
foo(&frc5431::myLambda);
```

{% endtab %}

{% tab title="Java" %}
When defining a functional interface, use the `@FunctionalInterface` annotation:

```
@FunctionalInterface
public interface Footerface {
  public void doFoo();
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: 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:

```
GET https://liavt.gitbook.io/styleguide/style/lambdas.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
