top | item 46382800

(no title)

tebbers | 2 months ago

I've been doing

  if condition1 && 
       condition2
       ...
  end
for ages and it seems to work find, what am I missing with this new syntax?!

discuss

order

AlecSchueler|2 months ago

I prefer the new way because if you want to remove one condition you just delete the line rather than having to edit in multiple places.

flopsamjetsam|2 months ago

I first picked up this style from the GNU C++ style guide, and it's so handy I use it in every language that accepts it.

fuzzythinker|2 months ago

In languages where placement don't matter, like c/js, I prefer leading booleans. It makes it much easier to see the logic, especially with layers of booleans.

mantas|2 months ago

Personally && in the new line seems to be much better readability. Can’t wait to use some smart cop to convert all existing multiline ifs in my codebase.

mathgeek|2 months ago

For folks who scan code bases based on the front of lines, it makes it easier to grok. Also helps with deleting and inserting lines (similar to leading or trailing commas in lists).

zelphirkalt|2 months ago

It's funny how I have been doing this way of writing the conditions in languages, where one can, like Python (if you use a pair of parentheses) and linters have yelled at me for ages to put the binary operator on the previous line. People herald these quite subjective things like truths, just because there is some tool, that they can delegate responsibility to.