---
name: "Code Positivity"
type: topic
source: https://community.bistudio.com/wiki/Code_Positivity
revid: 376868
updated: 2025-12-09T16:34:16Z
---

# Code Positivity

This page provides some insights into what it means to try and write code in a positive way, with the least negation as possible.

### Overview

Code negation is (usually) using [not](../commands/not.md) (in [SQF](../topics/SQF_Syntax.md)/[SQS](../topics/SQS_Syntax.md)) or `!` (in both [SQF](../topics/SQF_Syntax.md)/[SQS](../topics/SQS_Syntax.md) and Enforce Script); all in all, it is about searching for the opposite of what one wants. Examples:

| SQF | Enforce Script |
|---|---|
| ```sqf<br>if (not alive player) then<br>{<br>    hint "you are dead";<br>}<br>else<br>{<br>    hint "you are alive";<br>};<br>``` | ```enforce<br>if (value < minValue)<br>{<br>    Print("Value is invalid");<br>}<br>else<br>{<br>    Print("Value is valid");<br>}<br>``` |

Research (ref: https://www.researchgate.net/publication/10733819_Effects_of_Negation_and_Situational_Presence_on_the_Accessibility_of_Text_Information)
has (ref: https://www.researchgate.net/publication/221438570_Some_Issues_on_Detecting_Negation_from_Text)
shown (ref: https://medium.com/@Cuadraman/why-to-stop-writting-negavite-code-af5ffb17195)
that **negation** in general (not just in code but also in reading, teaching etc) makes processing sentences more difficult for the human brain, making its message less impactful
(although not in all cases (ref: https://www.psychologicalscience.org/news/releases/true-or-false-how-our-brain-processes-negative-statements.html)).

### Examples

| Do | Don't |
|---|---|
| ```sqf<br>// this is called Early Return / Bouncer pattern<br>if (isNull _control1) exitWith {};<br>if (isNull _control2) exitWith {};<br>if (isNull _control3) exitWith {};<br>// do something<br>``` | ```sqf<br>if (not isNull _control1) then<br>{<br>    if (not isNull _control2) then<br>    {<br>        if (not isNull _control3) then<br>        {<br>            // finally do something<br>            // <- this is called Hadouken code style as per<br>            // the shape drawn by the brackets<br>        };<br>    };<br>};<br>``` |
| ```enforce<br>// whenever possible without rewriting everything<br>// or doubling the methods, of course<br>if (unit.IsAlive() && unit.IsInjured())<br>    DoHealThing();<br>```<br>```enforce<br>// alternatively<br>if (unit.IsDead())<br>    DoDeathThing();<br>else if (unit.IsPerfectHealth())<br>    DoPerfectThing();<br>else // injured<br>    DoHealThing();<br>``` | ```enforce<br>// sometimes, only negative methods are available<br>if (!unit.IsPerfectHealth() && !unit.IsDead())<br>    DoHealThing();<br>``` |

### Counter Examples

As most if not all rules of development, this rule is a rule of thumb that is **not** to be enforced at all cost.

| Don't | Do |
|---|---|
| ```sqf<br>if (isNull _control) then<br>{<br>}<br>else<br>{<br>    systemChat "the control exists";<br>};<br>// or, even more convoluted and less performance-friendly<br>if (str _control find "NULL" == -1) then<br>{<br>    systemChat "the control exists";<br>};<br>``` | ```sqf<br>if (not isNull _control) then // neater<br>{<br>    systemChat "the control exists";<br>};<br>``` |
| ```enforce<br>if (m_aElements.Count() > 0)<br>    Print("There are elements!");<br>// note that in some cases, storing the count in a variable<br>// saves further calculations in below code<br>``` | ```enforce<br>if (!m_aElements.IsEmpty())<br>    Print("There are elements!");<br>``` |

### See Also

- [Code Optimisation](../topics/Code_Optimisation.md)
- [Mission Optimisation](../topics/Mission_Optimisation.md)
- [Multiplayer Scripting](../topics/Multiplayer_Scripting.md)

<sub>Source: [BI Community Wiki — Code Positivity](https://community.bistudio.com/wiki/Code_Positivity) (revision 376868).</sub>
