A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5427 below:

Avoid Boolean Method Parameters · Issue #5427 · pmd/pmd · GitHub

Proposed Rule Name: [apex] Avoid Boolean Method Parameters

Proposed Category: Design

Description: This rule discourages the use of Boolean parameters in global or public methods. In Apex, Boolean values can be true, false, or null. Using a Boolean parameter can lead to ambiguity and potential errors if the null case is not explicitly handled. This rule suggests creating two separate methods with meaningful names that clearly define the intended behavior, instead of relying on a Boolean parameter.

Code Sample:

// Violates the rule: Uses a Boolean parameter
public class MyClass {
  public static void doSomething(Boolean isSomething) {
    if (isSomething == true) {
      // Do something
    } else { 
      // Do something else, or maybe do nothing if isSomething is null? 
    }
  }
}

// Compliant code: Two separate methods
public class MyClass {
  public static void doSomething() {
    // Do something
  }

  public static void doSomethingElse() {
    // Do something else
  }
}

Possible Properties:
N/A

jongpie, Logeshm72, benjaminloerincz, scolladon, szymon-halik and 1 moregdecaen-klintjongpie and benjaminloerincz


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4