News for hackers. Stuff that matters.
Re:Read this post ‘unless’ you’re not a Ruby developer by weatherlight on Tuesday December 13, 2022 @10:11AM (#33969853)
When I write ruby, and I love ruby, I don't do too much condition branching of logic.

    - `if` and `unless` are for guards. The meat of every method, (the happy path) is at the bottom of that method.
    - If there are legitimately two options that branch on a conditional, I try to make sure that both branches return the same type. (feature flags, a/b feature testing, etc.)
    - If I can refactor code to a case statement, I will 95% of the time
This article screams, "I don't use a linter" or "I work at a company that doesn't have a style guide."
Re:Read this post ‘unless’ you’re not a Ruby developer by thomascgalvin on Tuesday December 13, 2022 @10:19AM (#33969978)
I don't write ruby at all, but this is how I write my Java, Kotlin, and Javascript; fail-fast at the top of the method, with the happy path following.

And I'll take it one step further: I see a multi-line branch as a code smell in and of itself. If something in a branch takes multiple statements, I am of the opinion that the body of that branch should probably broken out into a method.

So if we're going off the article title, my code might look something like

  val isNotRubyDev = !user.isRubyDev
  if(isNotRubyDev) return
  
  // ...read article