Skip to main content
added 11 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25

It's obviously subjective, but IMOIMHO inline conditionals make code harder to readunderstand, indentation is very important to understand what's going on. So I'd definitely take the second approach, but writing it differently to use only one indentation level:

existing_transaction = database.find_transaction_by_id(transaction.id)
if !existing_transaction
  database.create_transaction(transaction)
elsif !existing_transaction.processed
  database.update_transaction(transaction)
end

It's obviously subjective, but IMO inline conditionals make code harder to read, indentation is very important to understand what's going on. So I'd definitely take the second approach, but writing it differently:

existing_transaction = database.find_transaction_by_id(transaction.id)
if !existing_transaction
  database.create_transaction(transaction)
elsif !existing_transaction.processed
  database.update_transaction(transaction)
end

It's obviously subjective, but IMHO inline conditionals make code harder to understand, indentation is very important. So I'd definitely take the second approach, but writing it differently to use only one indentation level:

existing_transaction = database.find_transaction_by_id(transaction.id)
if !existing_transaction
  database.create_transaction(transaction)
elsif !existing_transaction.processed
  database.update_transaction(transaction)
end
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25

It's obviously subjective, but IMO inline conditionals make code harder to read, indentation is very important to understand what's going on. So I'd definitely take the second approach, but writing it differently:

existing_transaction = database.find_transaction_by_id(transaction.id)
if !existing_transaction
  database.create_transaction(transaction)
elsif !existing_transaction.processed
  database.update_transaction(transaction)
end