Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

Follow these rules:

  • ⚠ Copy pasting the code is not allowed; to share functionality use functions.

  • All code reflects the auto-format, see /wiki/spaces/LEARN/pages/2651979915.

  • Always use curly brackets for if, for, while , e.g.:

    if (isCondition) {
      return null
    }
  • Reformatting of big amount of old code should be done within a separate commit, otherwise it is almost impossible to validate the merge request.

  • Follow the Recommended Logic Structure. Try to keep all input elements in the beginning of the logic.

  • Use out.SomeElement instead of (deprecated) api.getElement("SomeElement").

  • Use input.SomeInputName instead of (deprecated) api.input("SomeInputName").

  • Avoid api.local, api.global where possible. For small amount of data, use a dedicated element – this will help you trace the logic more easily. Big data can cause a slowdown. Should not be used in functions (except e.g. caching).

  • Use field names in filters or use api.namedEntities() if possible.

  • Use real data type when declaring the variable instead of def. Mandatory use in functions – both parameters and the return type.

  • Prevent api.isSyntaxCheck Issues by having the AbortSyntaxCheck element in the logic.

  • Keep functions simple. Shorter methods are better than a big one.

  • Where to place functions?
    1. In the element – if used only once.
    2. In the Library element – if used only within the logic.
    3. In Groovy Library – if used between logics.

  • Use Input Builders – mandatory for configurators and header logics, but recommended also for ordinary logics.

  • Use @Field constants (no use for fields, table names, configurator names in customer projects). Mandatory use for important values used in conditions or repeatedly used constant Strings or used in Accelerators.

  • Use api.findLookupTableValues("TableName") instead of api.find("MLTVx", ...).

  • Use consistently one approach for adding items to a list, do not mix various approaches. It is recommended to use List << value rather than List.add(value)(unless you night nullsafe operator).

  • Use the same approach for accessing a List item, do not mix various approaches. It is recommended to use List[index] rather than List.getAt(index)(unless you night nullsafe operator).

  • Use the same approach for accessing Map values, do not mix various approaches. It is recommended to use Map.key rather than Map[key] or Map.get(key).

  • BigDecimal should be the most commonly used data type for amount or percentage variables (never use floats for amounts). Use BigDecimal constants (e.g. 0.0 instead of 0) so you can rely on BigDecimal.

  • If casting is needed, e.g. ?.toBigDecimal() for amounts, do this at the first occurrence of the variable.

  • Use closures (collect, collectEntries, each, eachWithIndex, find, findAll, first, last, max, min, inject, sort, etc.) whenever applicable.
    Note: For better performance, use the sortBy parameter in api.find() rather than the sort() closure.

  • Use "find" (resp. "query") prefix for names of functions that query Master Data tables (resp. Analytics Data Sources / Datamarts). Do not mix data querying and calculation in the functions.

  • Use the library element alias when calling several Groovy library functions in an element or function: def CurrencyUtils = libs.MainLib.CurrencyUtils

  • For performance reasons, avoid returning big data in an element. Remember: in Groovy, the expression on the last line is the value returned!

  • Initialize Map directly. E.g. instead of

    def map = [:]
    map["key1"] = "value1"
    map["key2"] = "value2"
    map["key3"] = "value3"

    directly use (and following auto-format):

    def map = [
      key1: "value1"
      key2: "value2"
      key3: "value3"
    ]
  • Analogically, initialize List directly. E.g. instead of

    def list = []
    list << "value1"
    list << "value2"
    list << "value3"

    directly use (and following auto-format):

    def list = [
        "value1",
        "value2",
        "value3"
    ]
  • Split suuuuperlooooong lines. If the function has many parameters, put each parameter on a separate line.

  • Dot not commit commented code, api.log and api.trace in GIT.

  • Resolve the TODOs.

  • No labels