SlideShare uma empresa Scribd logo
1 de 58
Baixar para ler offline
Designing Code
Beautiful, simple, and usable text.




Great Lakes Ruby Bash, Lansing MI   Steve Smith
April 17, 2010                        Ordered List
Things to Cover
1. Why design your code?
2. Balance
3. Clarity
4. Harmony
5. Wrap Up
Why Design Code?
Reasons to care about beauty.
“
Design is the application
of intent - the opposite of
happenstance, and an
antidote to accident.

               Robert L. Peters
Design for

Your Own Sanity
Design for

Future Growth
Design for the

User Experience
Things to Cover
1. Why design your code?
2. Balance
3. Clarity
4. Harmony
5. Wrap Up
Balance
Alignment and Order
Balance Using Grids to

Increase Scanability
config.gem   'bcrypt-ruby', :lib => 'bcrypt', :version => '2.1.1'
config.gem   'RedCloth', :lib => 'redcloth', :version => '4.2.2'
config.gem   'mongo_ext', :lib => false, :version => '0.19.1'
config.gem   'will_paginate', :version => '2.3.11'
config.gem   'state_machine', :version => '0.8.0'
config.gem   'newrelic_rpm', :version => '2.10.6'
config.gem   'mongo_mapper', :version => '0.7.1'
config.gem   'mime-types', :lib => 'mime/types'
config.gem   'exceptional', :version => '2.0.1'
config.gem   'rspreedly', :version => '0.1.11'
config.gem   'multipass', :version => '1.1.4'
config.gem   'defensio', :version => '0.9.1'
config.gem   'sanitize', :version => '1.1'
config.gem   'maruku', :version => '0.6.0'
config.gem   'faker', :version => '0.3.1'
config.gem   'navvy', :version => '0.1.0'
config.gem   'less', :version => '1.2.21'
config.gem   'wand', :version => '0.2.1'
config.gem   'rio', :version => '0.4.1'
Balance Method Sizes for

Lucidity
Things to Cover
1. Why design your code?
2. Balance
3. Clarity
4. Harmony
5. Wrap Up
Clarity
Simplicity and Understanding
Clarify Using

Consistent Names
class Post
  key :title, String
end

class Category
  key :name, String
end

class Theme
  key :moniker, String
end
class Post
  key :title, String
end

class Category
  key :title, String
end

class Theme
  key :title, String
end
class Site
  key :authorizations, Array

  def add_authorization(user)
    # do stuff
  end
end

class Account
  key :memberships, Array

  def add_membership(user)
    # do stuff
  end
end
class Site
  key :authorizations, Array

  def add_user(user)
    # do stuff
  end
end

class Account
  key :memberships, Array

  def add_user(user)
    # do stuff
  end
end
Clarify Using

Positive Grammar
class User
  include MongoMapper::Document

  key :name,     String
  key :email,    String
  key :inactive, Boolean, :default => false

end
class User
  include MongoMapper::Document

  key :name,     String
  key :email,    String
  key :inactive, Boolean, :default => false

  def active?
    !inactive?
  end

end
class User
  include MongoMapper::Document

  key :name,     String
  key :email,    String
  key :inactive, Boolean, :default => false

  def active?
    !inactive?
  end

  def activate!
    self.inactive = false
  end

end
class User
  include MongoMapper::Document

  key :name,   String
  key :email, String
  key :active, Boolean, :default => true

end
class User
  include MongoMapper::Document

  key :name,   String
  key :email, String
  key :active, Boolean, :default => true

  def inactive?
    !active?
  end

end
class User
  include MongoMapper::Document

  key :name,   String
  key :email, String
  key :active, Boolean, :default => true

  def inactive?
    !active?
  end

  def activate!
    self.active = true
  end

end
Clarify Using

Method Extraction
def do_something_important
  if foo? && foo == bar && baz != wik
    # do something
  end
end
def do_something_important
  # are specific conditions met?
  if foo? && foo == bar && baz != wik
    # do something
  end
end
def do_something_important
  if conditions_met?
    # do something
  end
end

def conditions_met?
  foo? && foo == bar && baz != wik
end
Things to Cover
1. Why design your code?
2. Balance
3. Clarity
4. Harmony
5. Wrap Up
Harmony
Integration and Experience
Harmonize with

Integration
Your Code




End User Application
Your Code
  WARNING



End User Application
Your Code




End User Application
Harmonize with

User Experience
“
Simplicity does not
precede complexity, but
follows it.

                 Alan Perlis
<title>
  Project Title - Portfolio - Ordered List
</title>
Our First Thought

item.breadcrumb
<title>
  {{ item.breadcrumb | map: 'title' | join: ' - ' }}
</title>
Our Next Thought

Too Much Code
{% title %}
<title>
  Project Title - Portfolio - Ordered List
</title>
{% title '//' %}
<title>
  Project Title // Portfolio // Ordered List
</title>
Things to Cover
1. Why design your code?
2. Balance
3. Clarity
4. Harmony
5. Wrap Up
Wrapping Up
A Few Takeaways
Write, Then Simplify, then

Write, Then Simplify
Before You Write the Code

Design the Experience
Remember that

Simplicity Wins
Thank you!
steve@orderedlist.com
@orderedlist



Great Lakes Ruby Bash, Lansing MI   Steve Smith
April 17, 2010                        Ordered List

Mais conteúdo relacionado

Semelhante a Designing code

20141210 rakuten techtalk
20141210 rakuten techtalk20141210 rakuten techtalk
20141210 rakuten techtalkHiroshi SHIBATA
 
Testing Has Many Purposes
Testing Has Many PurposesTesting Has Many Purposes
Testing Has Many PurposesAlex Sharp
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018Mike Harris
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principlesEdorian
 
Kohana 3.2 documentation
Kohana 3.2 documentationKohana 3.2 documentation
Kohana 3.2 documentationdmthuan1
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolmentRajib Ahmed
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainKen Collins
 
WordPress theme frameworks
WordPress theme frameworksWordPress theme frameworks
WordPress theme frameworksEddie Johnston
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)Thinkful
 
Tech_writing-akademy18.ppt
Tech_writing-akademy18.pptTech_writing-akademy18.ppt
Tech_writing-akademy18.pptips0vb2ub
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Brian Hogan
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010singingfish
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)David Coulter
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Scott Keck-Warren
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::ManagerJay Shirley
 

Semelhante a Designing code (20)

Ruby For Startups
Ruby For StartupsRuby For Startups
Ruby For Startups
 
20141210 rakuten techtalk
20141210 rakuten techtalk20141210 rakuten techtalk
20141210 rakuten techtalk
 
Testing Has Many Purposes
Testing Has Many PurposesTesting Has Many Purposes
Testing Has Many Purposes
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principles
 
Refactoring
RefactoringRefactoring
Refactoring
 
Kohana 3.2 documentation
Kohana 3.2 documentationKohana 3.2 documentation
Kohana 3.2 documentation
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolment
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own Domain
 
Good Coding Practices with JavaScript
Good Coding Practices with JavaScriptGood Coding Practices with JavaScript
Good Coding Practices with JavaScript
 
WordPress theme frameworks
WordPress theme frameworksWordPress theme frameworks
WordPress theme frameworks
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
 
Tech_writing-akademy18.ppt
Tech_writing-akademy18.pptTech_writing-akademy18.ppt
Tech_writing-akademy18.ppt
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 

Designing code