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 10 Next »

  1. CRITICAL: Copy pasting the code is not allowed, functions should be used for to share functionality

  2. All code reflects the auto-format, see Unified Code Style and How to Auto Format;

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

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

  5. Follow the Recommended Logic Structure. Try to leep all input elements in the beginning of the logic.

  6. Use out.SomeElement prior to (deprecated) api.getElement("SomeElement")

  7. Use input.SomeInputName prior to (deprecated) api.input("SomeInputName")

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

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

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

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

  12. Keep functions simple. More smaller methods is better than a big one

  13. 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.

  14. Use https://pricefx.atlassian.net/wiki/spaces/DEV/pages/2946629934/Input+Builders - mandatory for configurators and header logics, but recommended also for ordinary logics

  15. Smartly use of @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.

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

  17. Use one approach for adding item to the list, do not mix the approaches. Recommendation is to use List << value prior to List.add(value)(unless you night nullsafe operator)

  18. Use the same approach for accessing List item, do not mix the approaches. Recommendation is to use List[index] prior to List.getAt(index)(unless you night nullsafe operator)

  19. Use the same approach for accessing Map values, do not mix approaches. Recommendation is to use Map.key prior to Map[key] or Map.get(key)

  20. BigDecimal should be the 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.

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

  22. Use closures (collect, collectEntries, each, eachWithIndex, find, findAll, first, last, max, min, inject, sort, etc.) whenever applicable. Note: utilize use of sortBy parameter in api.find() prior to sort() closure for a better performance.

  23. Use "find" (resp. "query") prefix for the name of a function that is querying PB tables (resp. PA datasources/datamarts) Do not mix data querying and calculation in the functions

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

  25. PERFORMANCE: avoid returning big data in an element. Remember: in Groovy, the expression on the last line is the value returned!

  26. 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"
    ]
  27. 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"
    ]
  28. Split suuuuperlooooong lines. If the function has many parameters, put each parameter on a separate line.

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

  30. Resolve the TODOs

  • No labels