enum vs bool? when to choose what?

0
not sure what the pro's and cons are and when to choose what.   email validated purchase order draft planned running client payed etc   when do you choose enum vs booleans? seems like to flavors, but wanted to know what the experts say?
asked
4 answers
1

Hi Jason,

 

I use Booleans if I need it only in Microflows or if I don’t need to use a drop-down somewhere in the GUI.

 

I find Booleans also more attractive if it needs to be used in a filter (maybe a lack of knowledge though).

 

And in large datasets, having a Booleans in the Index makes it fast while retrieving or filtering (I would filter even over a variable in an XPath statement) 

 

When it comes to clustered Booleans, for example, the status example, an ENUM is less subject to making mistakes as I don’t need to “unset” the previous status.

 

Does this help?

 

Go Make It

answered
5

Hi Jason,

 

It depends on your project and how you are using that.

 

For Example:

  1. Planned, Running , completed this one you can use it ENUM
  2. Email validated – you can choose Boolean (isemalvalidated) choose for condition visibility.

If it is going to be Status or need to to choose the option means use ENUM . For setting conditions use Boolean.

 

For Boolean please visit here : https://docs.mendix.com/refguide/boolean-expressions/

For ENUM please visit here:  https://docs.mendix.com/refguide/enumerations/

 

I hope this one helps :)

answered
2

One addition to the previous answers: boolean does not allow empty, it is always true or false.

If you need something to indicate empty you need an enum.

answered
0

I believe this should not merely be a technical question, as I think the answer lies within the process you’re trying to facilitate.

Using enums is preferred when you’re trying to capture a process status, even when it only has 2 statusses right now. A process can grow over time and thus the status should be an Enum. 

Using booleans is preferred when you’re 100% sure that even in the future there will only be a maximum of 2 options. Facilitating a process status with booleans is offcourse an option, however to facilitate the same process status with a single enum, you’d allready need 2 booleans. This will unnecessarily create complexity, hence is not the preffered solution.

answered