Architecting is Difficult: London Web March 2014

Architecting is Difficult: London Web March 2014

Aea964cf59c0c81fff752896f070cbbb?s=128

Jack Franklin

March 20, 2014
Tweet

Transcript

  1. 2.

    Any fool can write code that a computer can understand.

    Good programmers write code that humans can understand. ! Martin Fowler [@martinfowler]
  2. 4.
  3. 6.

    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]
  4. 13.

    There are only two hard things in Computer Science: cache

    invalidation and naming things. ! Phil Karlton
  5. 14.

    There are only two hard things in Computer Science: cache

    invalidation, naming things and off by one errors. ! ???
  6. 22.

    Not one thing well class EmailSender def initialize(csv) ! def

    parse_csv_for_emails ! def send_email end
  7. 25.

    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
  8. 26.

    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
  9. 31.
  10. 36.

    You don’t fix code smells. You look at them and

    see if they indicate a problem you can fix. ! Joe Ferris [@joe_ferris]
  11. 37.

    class SomeMapThing def initialize(x, y) end ! class LatLong def

    self.get_lat_long(x, y) end ! class User def coords [x, y] end
  12. 39.

    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)
  13. 43.

    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
  14. 45.

    <% if user != nil %> <h2><%= user.welcome_message %></h2> <%

    else %> <h2>Please sign in</h2> <% end %>
  15. 47.
  16. 49.

    class NullUser def welcome_message “Please sign in” end ! user

    = current_user || NullUser.new <h2><%= user.welcome_message %></h2>
  17. 63.
  18. 65.

    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
  19. 67.

    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
  20. 69.

    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 }
  21. 73.

    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
  22. 75.

    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
  23. 79.

    Every time you work with some code, leave it a

    tiny bit better than when you left it