Drawbacks of Using Functions

Learn about the disadvantages of using functions.

Running transactions with functions works reasonably well, but has some drawbacks:

  • The most serious problem, demonstrated in the last section, is that we have to be careful that we call Repo functions in the correct way. When we call insert rather than insert!, it breaks the behavior we are trying to achieve. The compiler can’t help us with something like this, so the one missed character could put our database into a bad state.
  • Another problem is that anonymous functions are not composable. This limits their reusability. Our last example changed an Artist record, saved a log of the change, and updated the search engine. It’s possible that in another part of the application, we might want to update the artist’s albums along with the artist record. It would be nice to take the logic we already have and add to it, but our anonymous function doesn’t lend itself to being extended.
  • There’s still another problem—we don’t know exactly what went wrong when a transaction fails.

Get hands-on with 1200+ tech skills courses.