82
Don’t Settle for Poor Names Alistair McKinnell @ amckinnell

Don't Settle for Poor Names

Embed Size (px)

Citation preview

Page 1: Don't Settle for Poor Names

Don’t Settle for Poor Names

Alistair McKinnell@ amckinnell

Page 2: Don't Settle for Poor Names

Namingis deeply

connected to

Designing

Page 3: Don't Settle for Poor Names

Designingis deeply

connected to

Naming

Page 4: Don't Settle for Poor Names

Example fromQCloud

Page 5: Don't Settle for Poor Names

QCloud has forms, sheets, and inspections

Page 6: Don't Settle for Poor Names

QCloud has forms, sheets, and inspections

Page 7: Don't Settle for Poor Names
Page 8: Don't Settle for Poor Names
Page 9: Don't Settle for Poor Names
Page 10: Don't Settle for Poor Names
Page 11: Don't Settle for Poor Names
Page 12: Don't Settle for Poor Names
Page 13: Don't Settle for Poor Names

A sheet is composed of a reviewed and a submitted

{ something or other }

Page 14: Don't Settle for Poor Names
Page 15: Don't Settle for Poor Names

class Sheet < ActiveRecord::Base

composed_of :submitted_attribution_event, class_name: ’AttributionEvent', allow_nil: true, mapping: [ ['submitted_by_name', 'name'], ['submitted_by_email', 'email'], ['submitted_by_id', 'user_id'], ['submitted_at', 'event_at'] ]

composed_of :reviewed_attribution_event, class_name: 'AttributionEvent', allow_nil: true, mapping: [ ['reviewed_by_name', 'name'], ['reviewed_by_email', 'email'], ['reviewed_by_id', 'user_id'], ['reviewed_at', 'event_at'] ]

Page 16: Don't Settle for Poor Names

# # Represents the information required to attribute # an event to a user. # class AttributionEvent attr_reader :name, :email, :user_id, :event_at

def initialize(name, email, user_id, at) @name = name @email = email @user_id = user_id @event_at = at end end

composed_of :submitted_attribution_event, class_name: ’AttributionEvent', allow_nil: true, mapping: [ ['submitted_by_name', 'name'], ['submitted_by_email', 'email'], ['submitted_by_id', 'user_id'], ['submitted_at', 'event_at'] ]

Page 17: Don't Settle for Poor Names

A sheet is composed of a reviewed and a submitted

attribution event

Page 18: Don't Settle for Poor Names

An attribution event identifies a user and

has a timestamp

Page 19: Don't Settle for Poor Names

An attribution event identifies a user and

has a timestamp

Page 20: Don't Settle for Poor Names

An attribution event identifies a user and

has a timestamp

Page 21: Don't Settle for Poor Names

# # Represents the information required to attribute # an event to a user. # class AttributionEvent attr_reader :name, :email, :user_id, :event_at

def initialize(name, email, user_id, at) @name = name @email = email @user_id = user_id @event_at = at end end

An attribution event identifies a user and

has a timestamp

Page 22: Don't Settle for Poor Names

sheet.submitted_attribution_event = AttributionEvent.new( inspector.name, inspector.email, inspector.id, Time.zone.now )

sheet.submitted_by_name = inspector.name sheet.submitted_by_email = inspector.email sheet.submitted_by_id = inspector.id sheet.submitted_at = Time.zone.now

Before

After

Page 23: Don't Settle for Poor Names

sheet.submitted_attribution_event = AttributionEvent.new( inspector.name, inspector.email, inspector.id, Time.zone.now )

sheet.submitted_by_name = inspector.name sheet.submitted_by_email = inspector.email sheet.submitted_by_id = inspector.id sheet.submitted_at = Time.zone.now

Before

After

Page 24: Don't Settle for Poor Names

# # Represents the information required to attribute # an event to a user. # class AttributionEvent attr_reader :name, :email, :user_id, :event_at

def initialize(name, email, user_id, at) @name = name @email = email @user_id = user_id @event_at = at end end

An attribution event identifies a user and

has a timestamp

Page 25: Don't Settle for Poor Names

# # Represents the information required to attribute # an event to a user. # class AttributionEvent attr_reader :name, :email, :user_id, :event_at

def self.build(user, at: Time.zone.now) new(user.name, user.email, user.id, at) end

def initialize(name, email, user_id, at) @name = name @email = email @user_id = user_id @event_at = at end end An attribution event

identifies a user andhas a timestamp

Page 26: Don't Settle for Poor Names

sheet.submitted_attribution_event = AttributionEvent.build(inspector)

sheet.submitted_by_name = inspector.name sheet.submitted_by_email = inspector.email sheet.submitted_by_id = inspector.id sheet.submitted_at = Time.zone.now

Before

After

Page 27: Don't Settle for Poor Names

sheet.submitted_attribution_event = AttributionEvent.build(inspector)

sheet.submitted_by_name = inspector.name sheet.submitted_by_id = inspector.id sheet.submitted_at = Time.zone.now

Before

After

!

Page 28: Don't Settle for Poor Names

sheet.submitted_attribution_event = AttributionEvent.build(inspector)

sheet.submitted_by_name = inspector.name sheet.submitted_by_email = inspector.email sheet.submitted_by_id = inspector.id sheet.submitted_at = Time.zone.now

Before

After

Page 29: Don't Settle for Poor Names

sheet.submitted_attribution_event = AttributionEvent.build(inspector)

sheet.submitted_by_name = inspector.name sheet.submitted_by_email = reviewer.email sheet.submitted_by_id = inspector.id sheet.submitted_at = Time.zone.now

Before

After

!

Page 30: Don't Settle for Poor Names

sheet.submitted_attribution_event = AttributionEvent.build(inspector)

sheet.submitted_by_name = inspector.name sheet.submitted_by_email = reviewer.email sheet.submitted_by_id = inspector.id sheet.submitted_at = Time.zone.now

Before

After

Page 31: Don't Settle for Poor Names

# # Represents the information required to attribute # an event to a user. # class AttributionEvent attr_reader :name, :email, :user_id, :event_at

def self.build(user, at: Time.zone.now) new(user.name, user.email, user.id, at) end

def initialize(name, email, user_id, at) @name = name @email = email @user_id = user_id @event_at = at end end

Page 32: Don't Settle for Poor Names

class Sheet < ActiveRecord::Base

composed_of :reviewed_attribution_event, class_name: 'AttributionEvent', allow_nil: true, mapping: [ ['reviewed_by_name', 'name'], ['reviewed_by_email', 'email'], ['reviewed_by_id', 'user_id'], ['reviewed_at', 'event_at'] ]

composed_of :submitted_attribution_event, class_name: ’AttributionEvent', allow_nil: true, mapping: [ ['submitted_by_name', 'name'], ['submitted_by_email', 'email'], ['submitted_by_id', 'user_id'], ['submitted_at', 'event_at'] ]

Page 33: Don't Settle for Poor Names

class Sheet < ActiveRecord::Base

composed_of :reviewed_attribution_event, class_name: ’AttributionEvent', allow_nil: true, mapping: [ [‘reviewed_by_name’, 'name'], [‘reviewed_by_email', 'email'], [‘reviewed_by_id', 'user_id'], [‘reviewed_at', 'event_at'] ]

composed_of :submitted_attribution_event, class_name: ’AttributionEvent', allow_nil: true, mapping: [ [‘submitted_by_name', 'name'], [‘submitted_by_email’, 'email'], [‘submitted_by_id', 'user_id'], [‘submitted_at’, 'event_at'] ]

Page 34: Don't Settle for Poor Names

class Sheet < ActiveRecord::Base

attribution_event :reviewed attribution_event :submitted attribution_event :discarded

Page 35: Don't Settle for Poor Names
Page 36: Don't Settle for Poor Names

module Models module AttributionEvents extend ActiveSupport::Concern

module ClassMethods def attribution_event(type, allow_nil: true) attribution_event = <<-ATTRIBUTION_EVENT composed_of :#{type}_attribution_event, class_name: 'AttributionEvent', allow_nil: #{allow_nil}, mapping: [ ['#{type}_by_name', 'name'], ['#{type}_by_email', 'email'], ['#{type}_by_id', 'user_id'], ['#{type}_at', 'event_at'] ] ATTRIBUTION_EVENT

class_eval(attribution_event) end end end end

Page 37: Don't Settle for Poor Names

module Models module AttributionEvents extend ActiveSupport::Concern

module ClassMethods def attribution_event(type, allow_nil: true) attribution_event = <<-ATTRIBUTION_EVENT composed_of :#{type}_attribution_event, class_name: 'AttributionEvent', allow_nil: #{allow_nil}, mapping: [ ['#{type}_by_name', 'name'], ['#{type}_by_email', 'email'], ['#{type}_by_id', 'user_id'], ['#{type}_at', 'event_at'] ] ATTRIBUTION_EVENT

class_eval(attribution_event) end end end end

Page 38: Don't Settle for Poor Names

module Models module AttributionEvents extend ActiveSupport::Concern

module ClassMethods def attribution_event(type, allow_nil: true) attribution_event = <<-ATTRIBUTION_EVENT composed_of :#{type}_attribution_event, class_name: 'AttributionEvent', allow_nil: #{allow_nil}, mapping: [ ['#{type}_by_name', 'name'], ['#{type}_by_email', 'email'], ['#{type}_by_id', 'user_id'], ['#{type}_at', 'event_at'] ] ATTRIBUTION_EVENT

class_eval(attribution_event) end end end end

Page 39: Don't Settle for Poor Names

module Models module AttributionEvents extend ActiveSupport::Concern

module ClassMethods def attribution_event(type, allow_nil: true) attribution_event = <<-ATTRIBUTION_EVENT composed_of :#{type}_attribution_event, class_name: 'AttributionEvent', allow_nil: #{allow_nil}, mapping: [ ['#{type}_by_name', 'name'], ['#{type}_by_email', 'email'], ['#{type}_by_id', 'user_id'], ['#{type}_at', 'event_at'] ] ATTRIBUTION_EVENT

class_eval(attribution_event) end end end end

Page 40: Don't Settle for Poor Names

module Models module AttributionEvents extend ActiveSupport::Concern

module ClassMethods def attribution_event(type, allow_nil: true) attribution_event = <<-ATTRIBUTION_EVENT composed_of :#{type}_attribution_event, class_name: 'AttributionEvent', allow_nil: #{allow_nil}, mapping: [ ['#{type}_by_name', 'name'], ['#{type}_by_email', 'email'], ['#{type}_by_id', 'user_id'], ['#{type}_at', 'event_at'] ] ATTRIBUTION_EVENT

class_eval(attribution_event) end end end end

Page 41: Don't Settle for Poor Names

include Models::AttributionEvents

attribution_event :reviewed

composed_of :reviewed_attribution_event, class_name :'AttributionEvent', allow_nil: true, mapping: [ ['reviewed_by_name', 'name'], ['reviewed_by_email', 'email'], ['reviewed_by_id', 'user_id'], ['reviewed_at', 'event_at'] ]

Before

After

Page 42: Don't Settle for Poor Names

An attribution event identifies a user and

has a timestamp

And there are different types of attribution events

Page 43: Don't Settle for Poor Names

sheet.submitted_attribution_event = AttributionEvent.build(inspector)

sheet.reviewed_attribution_event = AttributionEvent.build(supervisor)

class Sheet < ActiveRecord::Base include Models::AttributionEvents

attribution_event :reviewed attribution_event :submitted

...

end

Page 44: Don't Settle for Poor Names

How do we { log, capture, assign, save, or record } an attribution event ?

Page 45: Don't Settle for Poor Names

sheet.log_attribution_event( type: :reviewed, user: inspector, at: reviewed_at )

sheet.capture_attribution_event( type: :submitted, user: inspector, at: submitted_at )

header.assign_attribution_event( type: :reviewed, user: inspector, at: reviewed_at )

inspection.save_attribution_event( type: :submitted, user: inspector, at: reviewed_at )

inspection.record_attribution_event( type: :reviewed, user: inspector, at: reviewed_at )

Page 46: Don't Settle for Poor Names

sheet.log_attribution_event( type: :reviewed, user: inspector, at: reviewed_at )

sheet.capture_attribution_event( type: :submitted, user: inspector, at: submitted_at )

header.assign_attribution_event( type: :reviewed, user: inspector, at: reviewed_at )

inspection.save_attribution_event( type: :submitted, user: inspector, at: reviewed_at )

inspection.record_attribution_event( type: :reviewed, user: inspector, at: reviewed_at )

Page 47: Don't Settle for Poor Names

sheet.log_attribution_event( type: :reviewed, user: inspector, at: reviewed_at )

sheet.capture_attribution_event( type: :submitted, user: inspector, at: submitted_at )

sheet.assign_attribution_event( type: :reviewed, user: inspector, at: reviewed_at )

inspection.save_attribution_event( type: :submitted, user: inspector, at: reviewed_at )

sheet.record_attribution_event( type: :reviewed, user: inspector, at: reviewed_at )

Page 48: Don't Settle for Poor Names

module Models module AttributionEvents extend ActiveSupport::Concern

included do def capture_attribution_event(type:, user:, at: Time.zone.now) send("#{type}_attribution_event=", AttributionEvent.build(user, at: at)) end end

module ClassMethods

...

end end end

Page 49: Don't Settle for Poor Names

module Models module AttributionEvents extend ActiveSupport::Concern

included do def capture_attribution_event(type:, user:, at: Time.zone.now) send("#{type}_attribution_event=", AttributionEvent.build(user, at: at)) end end

module ClassMethods

...

end end end

Page 50: Don't Settle for Poor Names

module Models module AttributionEvents extend ActiveSupport::Concern

included do def capture_attribution_event(type:, user:, at: Time.zone.now) send("#{type}_attribution_event=", AttributionEvent.build(user, at: at)) end end

module ClassMethods

...

end end end

Page 51: Don't Settle for Poor Names

sheet.capture_attribution_event( type: :submitted, user: inspector )

Before

After

sheet.submitted_by_name = inspector.name sheet.submitted_by_email = inspector.email sheet.submitted_by_id = inspector.id sheet.submitted_at = Time.zone.now

Page 52: Don't Settle for Poor Names

Example fromQCloud

composed_of Concern

Page 53: Don't Settle for Poor Names

An attribution event identifies a user and

has a timestamp

And we capture different types of attribution events

Page 54: Don't Settle for Poor Names

class Sheet < ActiveRecord::Base include Models::AttributionEvents attribution_event :reviewed attribution_event :submitted

sheet.capture_attribution_event( type: :submitted, user: inspector )

An attribution event identifies a user and

has a timestamp

And we capture different types of attribution events

Page 55: Don't Settle for Poor Names

class Sheet < ActiveRecord::Base include Models::AttributionEvents attribution_event :reviewed attribution_event :submitted

sheet.capture_attribution_event( type: :submitted, user: inspector )

Page 56: Don't Settle for Poor Names

Namingis deeply

connected to

Designing

Page 57: Don't Settle for Poor Names
Page 58: Don't Settle for Poor Names

Ubiquitous Language

The language used by everyone on the team to describe the domain model when speaking, writing user stories, and in the source code.

Page 59: Don't Settle for Poor Names

• Passes the tests• Reveals intention

Simple Design

• No duplication• Fewest elements

Page 60: Don't Settle for Poor Names

• Passes the tests• Reveals intention

Simple Design

• No duplication• Fewest elements

Page 61: Don't Settle for Poor Names

• Passes the tests• Reveals intention

Simple Design

• No duplication• Fewest elements

Page 62: Don't Settle for Poor Names

• Passes the tests• Improves names

Simple Design

• No duplication• Fewest elements

Page 63: Don't Settle for Poor Names

• Improves names

Simple Design

• Removes duplication

Page 64: Don't Settle for Poor Names

• Improves names

Simple Design

• Removes duplication

Page 65: Don't Settle for Poor Names

The Simple Design Dynamo™

Page 66: Don't Settle for Poor Names

Example fromQCloud

Page 67: Don't Settle for Poor Names
Page 68: Don't Settle for Poor Names

class Sheet < ActiveRecord::Base

composed_of :reviewed_attribution_event, class_name: 'AttributionEvent', allow_nil: true, mapping: [ ['reviewed_by_name', 'name'], ['reviewed_by_email', 'email'], ['reviewed_by_id', 'user_id'], ['reviewed_at', 'event_at'] ]

composed_of :submitted_attribution_event, class_name: ’AttributionEvent', allow_nil: true, mapping: [ ['submitted_by_name', 'name'], ['submitted_by_email', 'email'], ['submitted_by_id', 'user_id'], ['submitted_at', 'event_at'] ]

Page 69: Don't Settle for Poor Names

# # Represents the information required to attribute # an event to a user. # class AttributionEvent attr_reader :name, :email, :user_id, :event_at

def initialize(name, email, user_id, at) @name = name @email = email @user_id = user_id @event_at = at end end

sheet.submitted_attribution_event = AttributionEvent.new( inspector.name, inspector.email, inspector.id, Time.zone.now )

Page 70: Don't Settle for Poor Names

# # Represents the information required to attribute # an event to a user. # class AttributionEvent attr_reader :name, :email, :user_id, :event_at

def self.build(user, at: Time.zone.now) new(user.name, user.email, user.id, at) end

def initialize(name, email, user_id, at) @name = name @email = email @user_id = user_id @event_at = at end end An attribution event

identifies a user andhas a timestamp

Page 71: Don't Settle for Poor Names

class Sheet < ActiveRecord::Base

composed_of :reviewed_attribution_event, class_name: ’AttributionEvent', allow_nil: true, mapping: [ [‘reviewed_by_name’, 'name'], [‘reviewed_by_email', 'email'], [‘reviewed_by_id', 'user_id'], [‘reviewed_at', 'event_at'] ]

composed_of :submitted_attribution_event, class_name: ’AttributionEvent', allow_nil: true, mapping: [ [‘submitted_by_name', 'name'], [‘submitted_by_email’, 'email'], [‘submitted_by_id', 'user_id'], [‘submitted_at’, 'event_at'] ]

Page 72: Don't Settle for Poor Names

module Models module AttributionEvents extend ActiveSupport::Concern

module ClassMethods def attribution_event(type, allow_nil: true) attribution_event = <<-ATTRIBUTION_EVENT composed_of :#{type}_attribution_event, class_name: 'AttributionEvent', allow_nil: #{allow_nil}, mapping: [ ['#{type}_by_name', 'name'], ['#{type}_by_email', 'email'], ['#{type}_by_id', 'user_id'], ['#{type}_at', 'event_at'] ] ATTRIBUTION_EVENT

class_eval(attribution_event) end end end end

Page 73: Don't Settle for Poor Names
Page 74: Don't Settle for Poor Names

class Sheet < ActiveRecord::Base include Models::AttributionEvents

attribution_event :reviewed attribution_event :submitted

sheet.capture_attribution_event( type: :submitted, user: inspector )

sheet.capture_attribution_event( type: :reviewed, user: supervisor )

Page 75: Don't Settle for Poor Names

The Simple Design Dynamo™

Page 76: Don't Settle for Poor Names

Don’t Settle for Poor Names

Page 77: Don't Settle for Poor Names

Don’t Settle for Poor Names

Pretty Please

Page 78: Don't Settle for Poor Names
Page 79: Don't Settle for Poor Names

The Simple Design Dynamo™

Page 80: Don't Settle for Poor Names
Page 81: Don't Settle for Poor Names

Resources

Page 82: Don't Settle for Poor Names

http://blog.jbrains.ca/permalink/the-four-elements-of-simple-design

http://blog.thecodewhisperer.com/permalink/putting-an-age-old-battle-to-rest

One of the best thinkers around on effective software development: J. B. Rainsberger.