Clay Icon

Reiterating Function Logic in Code: Early Returns Explained

ยท
ยท

I've suggested this before but wanted to reiterate: sheets would be much simpler if you could "return early" This is a common best practice in coding. It makes functions much simpler / easier to manage. Example function (mimicks a row in Clay)

const company = testCompany
const employeeCount = getEmployeeCount()
const funding = getFunding() 

if (funding < 10 && employeeCount > 20) {
  const aiDescription = getAiDescription() // must add run condition based on funding employee count
  const rating = getRating() // must add run condition based on funding employee count
  if (rating > 5) {
    const contacts = findContacts(company) // must add run condition based on funding employee count and rating
    const emails = find emails() // must add run condition based on funding employee count and rating
  }
}

But if you "return early" the function is a lot simpler

const company = testCompany
const employeeCount = getEmployeeCount() // returns FTE count
const funding = getFunding() 

if (funding > 10 || employeeCount < 20) {
  return // ends "row functions"
}

const aiDescription = getAiDescription() // no run conditions needed
const rating = getRating() // no run conditions needed

if (rating < 5) {
  return 
} 

const contacts = findContacts(company)
const emails = find emails()
const contacts = findContacts(company)
const emails = find emails()

If you could do this in a sheet (i.e. "end" the row based on a condition) it would save you a TON of complexity in have to add run conditions to every subsequent column

  • Avatar of LuisArturo
    LuisArturo
    ยท
    ยท

    Hey there Mathew thanks for reaching out and thank you for the feedback as well. Can see how this could be useful to users, will go and bring this up with the team so that they can take a look at this.

  • Avatar of Channeled
    Channeled
    APP
    ยท
    ยท

    Hi Mathew I.! This thread was recently closed by our Support team. If you have a moment, please share your feedback: