From a06b684e87a43e192850031e8e95501ee6a7e542 Mon Sep 17 00:00:00 2001 From: Michael Dieringer <65093775+MichaelDieringer@users.noreply.github.com> Date: Wed, 12 Aug 2026 22:30:47 +0200 Subject: [PATCH] Forslag: binary-choice-must-be-boolean --- .../style/binary-choice-must-be-boolean.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 custom/knowledge/style/binary-choice-must-be-boolean.md diff --git a/custom/knowledge/style/binary-choice-must-be-boolean.md b/custom/knowledge/style/binary-choice-must-be-boolean.md new file mode 100644 index 0000000..196e7ff --- /dev/null +++ b/custom/knowledge/style/binary-choice-must-be-boolean.md @@ -0,0 +1,59 @@ +--- +bc-version: [all] +domain: style +keywords: [boolean, option, yes-no, magic-number, variable-typing, field-typing] +technologies: [al] +countries: [w1] +application-area: [all] +--- + +# Binary yes/no choices must be typed as Boolean, not Option or Integer + +## Description + +When a field or variable represents exactly two states — yes/no, on/off, +active/inactive, blocked/not blocked — it must be typed `Boolean`. Modeling +that same two-state choice as an `Option`/`Enum` with two members, or as an +`Integer` with two magic-number values (0/1), adds a layer of indirection a +reader has to resolve before understanding the code, and it invites a +three-way branch (`if X = 0 then ... else if X = 1 then ...`) where a simple +`if X then ...` would do. + +This is distinct from a genuine multi-value choice — see +[[fixed-choice-set-must-use-enum-not-integer]] — where more than two named +states legitimately call for `Enum`. The line is the state count: exactly +two mutually exclusive states is a Boolean question, not an enumeration. + +## Best Practice + +```al +field(50; Blocked; Boolean) +{ +} + +var + IsOverdue: Boolean; +... +IsOverdue := DueDate < Today; +if IsOverdue then + ... +``` + +## Anti Pattern + +```al +field(50; Status; Option) +{ + OptionMembers = Active,Blocked; +} + +var + OverdueFlag: Integer; // 0 = No, 1 = Yes +... +if OverdueFlag = 1 then + ... +``` + +An `Option`/`Integer` standing in for a true yes/no forces every caller to +remember which value means what, and it leaves room for a third, meaningless +value that a `Boolean` cannot represent.