Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Architecting is Difficult: London Web March 2014

Architecting is Difficult: London Web March 2014

Avatar for Jack Franklin

Jack Franklin

March 20, 2014
Tweet

More Decks by Jack Franklin

Other Decks in Technology

Transcript

  1. Any fool can write code that a computer can understand.

    Good programmers write code that humans can understand. ! Martin Fowler [@martinfowler]
  2. Defer concrete decisions as late as possible - you'll never

    again know less about the problem than you do right now and the correct abstraction will become clearer over time. ! Andy Appleton [@appltn]
  3. There are only two hard things in Computer Science: cache

    invalidation and naming things. ! Phil Karlton
  4. There are only two hard things in Computer Science: cache

    invalidation, naming things and off by one errors. ! ???
  5. Not one thing well class EmailSender def initialize(csv) ! def

    parse_csv_for_emails ! def send_email end
  6. class EmailSender def initialize(csv) def parse_csv_for_emails Parser.new(csv).emails def send_email end

    ! class Parser def initialize(csv) def emails end This knowledge isn’t needed here
  7. class EmailSender def initialize(emails) def send_email end ! class Parser

    def initialize(csv) def emails end ! emails = Parser.new(csv).emails EmailSender.new(emails).send_email knows how to send an email to an array of emails knows how to parse a CSV and get the email addresses
  8. You don’t fix code smells. You look at them and

    see if they indicate a problem you can fix. ! Joe Ferris [@joe_ferris]
  9. class SomeMapThing def initialize(x, y) end ! class LatLong def

    self.get_lat_long(x, y) end ! class User def coords [x, y] end
  10. class SomeMapThing def initialize(coords) ! class LatLong def self.get_lat_long(coords) !

    class User def coords ! class Coords def x def y ! coords = Coords.new(2, 3) LatLong.get_lat_long(coords)
  11. class GraphDrawer GRAPH_HEIGHT_PADDING = 170.2 GRAPH_WIDTH_PADDING = 165 def draw

    width = GRAPH_WIDTH_PADDING * bar_width height=GRAPH_HEIGHT_PADDING + bar_height end
  12. <% if user != nil %> <h2><%= user.welcome_message %></h2> <%

    else %> <h2>Please sign in</h2> <% end %>
  13. class NullUser def welcome_message “Please sign in” end ! user

    = current_user || NullUser.new <h2><%= user.welcome_message %></h2>
  14. class ModuleA def init(b) def a_thing do_a_thing b.do_thing ! !

    class ModuleB def do_thing # has to happen after ModuleA#a_thing
  15. class ModuleA def init(event) def a_thing do_a_thing event.publish(‘a_thing_complete’) ! !

    class ModuleB def init(event) event.subscribe(‘a_thing_complete’) { do_thing } ModuleA doesn’t know (or care) what modules listen to a_thing_complete
  16. class ModuleA def init(event) def a_thing do_a_thing event.publish(‘a_thing_complete’) ! class

    ModuleB … class ModuleC def init(event) event.subscribe(‘a_thing_complete’) { do_thing }
  17. A method of an object should only invoke only the

    methods of the following kinds of objects: ! 1. itself 2. its parameters 3. any objects it creates 4. its direct component objects
  18. class User def posts_by_user blog.posts_by_user(id) end ! class Blog def

    posts_by_user(id) posts.where(user_id: id) end
  19. Every time you work with some code, leave it a

    tiny bit better than when you left it