Line break

This page is a work in progress. TODO

Please watch this video to better understand the different things a method does.

It’s the norm that each new method begins with a new line. However, within a method, the question of when to have a line break has not standardized yet.

I prefer to have a line break before the real business processing happens.

Example 1

Code with no line break:

def initialize(showing, url)
  @showing = showing
  @listing = showing.spark_listing
  @url = url
end

In the following version, there is a line break after the data gathering is done. In this case, there is a better visual separation of data gathering vs. business processing.

def initialize(showing, url)
  @showing = showing
  @url = url

@listing = showing.spark_listing end

Example 2

Code with no line break:

def setup_analytics_tracking
  return unless tracking_enabled?
  Analytics.identify( user_id: user.id,
                      traits: { email: user.email,
                                name: user.name,
                                firstName: user.first_name,
                                lastName: user.last_name,
                                phone: user.phone } )
end

In the following version, there is a line break after we are done handling the case of tracking not being enabled. That first line is like validation logic to see if the main work is to be performed or not.

def setup_analytics_tracking
  return unless tracking_enabled?

Analytics.identify( user_id: user.id, traits: { email: user.email, name: user.name, firstName: user.first_name, lastName: user.last_name, phone: user.phone } ) end