What is the most efficient between IF and showWhen=False ?

Certified Senior Developer

Hi,

My question is maybe a little naive but for increasing performance I was asking myself if use the showWhen attribute on 10 components is as good using an IF condition to masking all these components.

I took 3 examples :

1/ Case showWhen on all components :

ColumnsLayout(
    columnLayout
        TextField_1label: "1", showWhen: false)
    columnLayout(
        TextField_2(label: "2", showWhen: false)

    ...

    columnLayout(
         TextField_10(label: "10", showWhen: false)
)

2/ Case showWhen on layout component :

ColumnsLayout(
    columnLayout
        TextField_1(label: "1")

    columnLayout(
        TextField_2(label: "2")
    ...

    columnLayout(
        TextField_10(label: "10")
    ),
    showWhen : false
)

3/ Case with an IF condition :

local!value: false,
if(local!value,
   ColumnsLayout(
      columnLayout
          TextField_1(label: "1")

      columnLayout(
          TextField_2(label: "2")
      ...

      columnLayout(
          TextField_10(label: "10")
     )
  ),
  {}
)

Is the 3/ more efficient as Appian do not need to load anything ?  

  Discussion posts and replies are publicly visible

Parents
  • Certified Lead Developer

    Premature optimization is the root of all evil.  I just use showWhen quite extensively.  I did find one case, however, where showWhen didn't behave as I intended, but if condition worked quite well.  I think there can be a difference between when a component and related code is hidden from the user, and when the if returns false so absolutely NONE of the associated code even runs.

    Unless you need to if(), a good example is when the component doesn't have a showWhen, I would use showWhen.  It probably is the tiniest bit better, and certainly more maintainable, or Appian wouldn't have bothered inventing it.

Reply
  • Certified Lead Developer

    Premature optimization is the root of all evil.  I just use showWhen quite extensively.  I did find one case, however, where showWhen didn't behave as I intended, but if condition worked quite well.  I think there can be a difference between when a component and related code is hidden from the user, and when the if returns false so absolutely NONE of the associated code even runs.

    Unless you need to if(), a good example is when the component doesn't have a showWhen, I would use showWhen.  It probably is the tiniest bit better, and certainly more maintainable, or Appian wouldn't have bothered inventing it.

Children