develwoutacause’s avatardevelwoutacause’s Twitter Archive—№ 1,418

  1. #goto is such an anti-pattern, but refactoring to a function with early returns is so tedious. Isn't there a better way? Talk to your doctor today about using throw in the middle of a function to manage control flow. All the illegibility of goto, without all the work!
    A screenshot of a TypeScript function called `logOut` which declares a variable `user` and then attempts to initialize it inside a `try` block. It checks two cases, if the user is logged in or if a refresh token is present. If either case is true, the `user` variable is initialized and a `new Error('done')` is thrown, which is caught inside the same function. The `catch` doesn't do anything and merely contains a comment reading "Got a user, stop running the `try` block". Finally, `user.logOut()` is called.
    1. …in reply to @develwoutacause
      4 out of 5 tech leads agree, this is a terrible idea.