Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

If you fear that the appearance of many Groovy Library function calls may make your code unreadable, consider creating an alias function. An alias allows you to call a local function that reroutes to a library, giving you more flexibility with how your code looks.

...

To improve readability, always assign the library element instances to a variable before using them:

Code Block
languagegroovy
final roundingUtils = libs.MathLuib.RoundingUtils

final someNumber = ...

roundingUtils.round(someNumber, 2)

This practice dramatically improves the readability of your code as it grows in size.

Tip

Do this:

Code Block
final productUtils = libs.ProductLib.ProductUtils
final pricinUtils = libs.PricingLib.PricingUtils

final product = productUtils.getProduct(...)
final cost = productUtils.getCost(...)
final margin = pricingUtils.getMargin(...)

final listPrice = pricingUtils.calculatePrice(product, cost, margin)

Warning

Don’t do this:

Code Block
final productUtils = libs.ProductLib.ProductUtils.getProduct(...)
final costUtils = libs.ProductLib.ProductUtils.getCost(...)
final marginUtils = libs.PricingLib.PricingUtils.getMargin(...)

final listPrice = libs.PricingLib.PricingUtils.calculatePrice(product, cost, margin)