logoalt Hacker News

tebberstoday at 7:23 AM6 repliesview on HN

I've been doing

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

Replies

mathgeektoday at 2:55 PM

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).

AlecSchuelertoday at 9:02 AM

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.

Sammitoday at 7:38 AM

Less likely to cause git merge conflict as you don't change the original line. You only add one.

show 1 reply
fuzzythinkertoday at 8:36 AM

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.

mantastoday at 7:34 AM

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.

zelphirkalttoday at 10:24 AM

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.