← Back to context

Comment by shevy-java

17 hours ago

I find that so much harder to read compared to if/else or case/when in ruby.

The ? is basically an attempt to use fewer if/else, at the cost of condensed if-else like structure. I always need to look at both parts after the ? whereas in a single if or elsif I don't. case/when in ruby is even better here e. g. regex check:

   def foo(i)
     case i
     when /^cat/
       handle_cats
     when /^dog/
       handle_dogs

(I ommitted the "end"s here to just focus on the conditional logic.)