Determining if List is Empty

Thanks @romanmg for finding my response to that other question. @sudsy: Please note: the question posed at Is "first item is not empty" faster than "count > 0"? is different than the one you post above.

Your question here asks about two list conditions that WOULD NEVER interrupt a Search (regardless of whether Bubble does that optimization or not). A list can only be evaluated for first item’s emptiness when the list is fully constructed. Similarly, we can only evaluate that a list’s length is 0 after the list is fully constructed.

Both depend on the list being fully constructed to evaluate. But there are conditions that do give a reason to stop a Search in progress. Both of the following conditions are candidates for that (and these are the ones asked about in the older post:

Which is faster?: some_lists's:first item **is not empty** or some_lists's:**count > 0**… where both lists are constructed via a Search. (Let’s call these conditions C and D.)

I stand by my answer to the original question. I think that what :count represents in Bubble is “get the length of a list like a function”. The irony is that, internally, lists always have a .length property (as we can discover when we start working with actions in the plugin builder (especially server-side actions).

So :count > 0 is a condition that actually could be “looked ahead”. (“length” isn’t a function there, it’s a property)

Most folks get that C (first item is not empty) provides a good reason to stop a Search while in progress. In the first case: The condition logically becomes true as soon as the list has 1 item in it. As soon as there is even 1 item, Bubble could stop searching (but does it? I think it does).

Expression D (:count > 0) is less obvious. Because Bubble calls this property “count”, a lot of folks take that to be a verb. Mentally they think, oh well you can only “count” the number of things after we have all the things. (And, if :count means “grab the lists length like a function” then this is correct thinking.)

Ironically, internally, if you have a list (an object like properties.theList) and you want to know: “is that list empty?”, the way you do that is check for properties.theList.length < 1 or properties.theList.length = 0. You do not need to have the values in the list to know that fact. (And, to retrieve the values in the list, you have to do a function call to the list’s .get() function. So, you’d never go about determining a lists’s emptiness by sorting it and then looking at the emptiness of its first element!

(What I’m saying above is: Some of the things you would do when designing an algorithm in Bubble editor are, in fact, the exact opposite of how you would do things in JavaScript/node when working with Bubble internals.)

1 Like