SQE Boston - When Code Cries

591 views

Published on

In this talk from Boston's SQE Conference, Cory Foy talks about the strategies for developing and architecting quality code by changing how we learn about code and how we can let go of design and architecture in some ways to be able to listen to what the code is telling us - leading to happy code!

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
591
On SlideShare
0
From Embeds
0
Number of Embeds
49
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

SQE Boston - When Code Cries

  1. 1. When Code Cries Cory Foy @cory_foy foyc@coryfoy.com http://www.coryfoy.com @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Reading from Timeless Way. Then: All of us here are technologists in some way. We desire to build things that people will use. Living software. But if you look at our industry, the fruit of our labors is not living software. The majority of software out there has a common attribute. It is: 1
  2. 2. Bad Code @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Bad Code is the bane of the software industry. Why is it that, over time, code becomes harder and harder to work with - and how can we prevent ours from ending up with the same fate? To answer that, perhaps we should start with identifying what quality code is. So, is this quality code? 2
  3. 3. Is this quality code? @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Why do we like Easy to Change code? Because it is a lower cognitive burden. Because writing code is hard enough, as we’ll see. 3
  4. 4. Is this quality code? @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Why do we like Easy to Change code? Because it is a lower cognitive burden. Because writing code is hard enough, as we’ll see. 3
  5. 5. Cognitively Undemanding Where we want our software Context Embedded Context Reduced Modifying Software we wrote @cory_foy Modifying Software we didn’t write Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 We want code that is in the upper right quadrant. But, if we’re lucky to be modifying our own code, it’s in the lower left. Worse case, we don’t even have the context, so it’s in the lower right. Now, if we have tests, that helps increase the context. But when we don’t, we can end up with code that looks like 4
  6. 6. Cognitively Undemanding Where we want our software Context Embedded Context Reduced Modifying Software we wrote @cory_foy Modifying Software we didn’t write Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 We want code that is in the upper right quadrant. But, if we’re lucky to be modifying our own code, it’s in the lower left. Worse case, we don’t even have the context, so it’s in the lower right. Now, if we have tests, that helps increase the context. But when we don’t, we can end up with code that looks like 4
  7. 7. Cognitively Undemanding Where we want our software Context Embedded Context Reduced Modifying Software we wrote @cory_foy Modifying Software we didn’t write Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 We want code that is in the upper right quadrant. But, if we’re lucky to be modifying our own code, it’s in the lower left. Worse case, we don’t even have the context, so it’s in the lower right. Now, if we have tests, that helps increase the context. But when we don’t, we can end up with code that looks like 4
  8. 8. Cognitively Undemanding Where we want our software Context Embedded Context Reduced Modifying Software we wrote @cory_foy Modifying Software we didn’t write Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 We want code that is in the upper right quadrant. But, if we’re lucky to be modifying our own code, it’s in the lower left. Worse case, we don’t even have the context, so it’s in the lower right. Now, if we have tests, that helps increase the context. But when we don’t, we can end up with code that looks like 4
  9. 9. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 5 Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?
  10. 10. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 5 Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?
  11. 11. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 5 Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?
  12. 12. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 5 Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?
  13. 13. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 5 Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?
  14. 14. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 5 Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?
  15. 15. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 5 Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?
  16. 16. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 5 Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?
  17. 17. Code Smells @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 6 Right - “Smelly Code”. But what I’d like to do today is reframe the discussion slightly. Instead of telling our code that it smells, let’s recognize something else - our code is trying to talk to us.
  18. 18. Code Talks @cory_foy foyc@coryfoy.com Thursday, November 14, 13 And imagine trying to talk to someone about something important - say, the building is on fire - and them not understanding your strange gestures and telling you you are smelly. Would that make you happy? It doesn’t make our code happy. And if I can take some poetic license, I’d even say that code cries 7
  19. 19. Code Cries @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 8 And our code cries not because it is smelly, but because no one understands what it is trying to say. It’s trying to point out what it wants to do, what is important, and how to use it. And it isn’t happy about that! Too often we try to force what we want, what we think is best.
  20. 20. Code Cries Because No One Understands What It Is Saying @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 8 And our code cries not because it is smelly, but because no one understands what it is trying to say. It’s trying to point out what it wants to do, what is important, and how to use it. And it isn’t happy about that! Too often we try to force what we want, what we think is best.
  21. 21. “...we have so far beset ourselves with rules, and concepts, and ideas...that we have become afraid of what will happen naturally, and convinced that we must work within a “system” and with “methods” [or] our surroundings will come tumbling down in chaos.” Christopher Alexander - “The Timeless Way of Building” @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 9 We turn to our UML and architecture diagrams and design documents, trying to brute force a system that will work, afraid that if we don’t - chaos. But nature *dictates* an iterative design - one where the best path is not only discovered, but continually chosen. We literally can not build software any other way. 
  22. 22. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 10 This is a map of the Mississippi River in the United States. What’s special about it is that it is all of the routes the river has run through the years. We create a design. We settle down, build a house, have a family. But the code doesn't want that. It has plans beyond our design. And if we don't listen to those plans, our days will become filled with holding off the impending - and inevitable - change (http://www.adammandelman.net/tag/harold-fisk/)
  23. 23. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 11 For example, in 2011, the Mississippi River tried to change course, I believe to the Orange area. And it normally would have - except for the millions of dollars the Army Corp of Engineers spent to erect dams, flood farm fields and otherwise keep it on the course best for us - not for it. But trying to brute force design into nature’s iterative process isn’t the only problem. (10k next)
  24. 24. @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 12 There’s a common figure that is given to developers about what it takes to become great in software. Does anyone know that number? <Click> This is the number of hours to “master” a skill. But as much as we tout this, we don’t really act like this is important. People new to software either get this
  25. 25. Ten Thousand Hours @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 12 There’s a common figure that is given to developers about what it takes to become great in software. Does anyone know that number? <Click> This is the number of hours to “master” a skill. But as much as we tout this, we don’t really act like this is important. People new to software either get this
  26. 26. bloody @cory_foy Thursday, November 14, 13 So, confusion and frustration, or this foyc@coryfoy.com 13
  27. 27. @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Empty promises! (Beaker story). Can you imagine learning C++ in 24 hours? Well, you might be able to learn syntax, but building great software isn’t just about learning syntax. Or diagrams. At the start of the talk, I quoted Alexander talking about a Timeless Way of Building - and that this way - this timeless way - is the only way buildings - or software that are alive can be built. And if we go right to the kernel of that way, he says 14
  28. 28. @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Empty promises! (Beaker story). Can you imagine learning C++ in 24 hours? Well, you might be able to learn syntax, but building great software isn’t just about learning syntax. Or diagrams. At the start of the talk, I quoted Alexander talking about a Timeless Way of Building - and that this way - this timeless way - is the only way buildings - or software that are alive can be built. And if we go right to the kernel of that way, he says 14
  29. 29. @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Empty promises! (Beaker story). Can you imagine learning C++ in 24 hours? Well, you might be able to learn syntax, but building great software isn’t just about learning syntax. Or diagrams. At the start of the talk, I quoted Alexander talking about a Timeless Way of Building - and that this way - this timeless way - is the only way buildings - or software that are alive can be built. And if we go right to the kernel of that way, he says 14
  30. 30. @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Empty promises! (Beaker story). Can you imagine learning C++ in 24 hours? Well, you might be able to learn syntax, but building great software isn’t just about learning syntax. Or diagrams. At the start of the talk, I quoted Alexander talking about a Timeless Way of Building - and that this way - this timeless way - is the only way buildings - or software that are alive can be built. And if we go right to the kernel of that way, he says 14
  31. 31. “To make a building {alive}...the builder must let go of all his willful images, and start with a void...At this stage the building’s life will come directly from your language” Christopher Alexander - “The Timeless Way of Building” @cory_foy foyc@coryfoy.com Thursday, November 14, 13 So for us to be able to build great software, we have to be willing to let go of the diagrams. Of the syntax. Of the “Point A, Point B, flow”. And let go of the fear 15
  32. 32. “You are able to do this only when you no longer fear that nothing will happen” Christopher Alexander - “The Timeless Way of Building” @cory_foy foyc@coryfoy.com Thursday, November 14, 13 of the fear that if we let go, nothing will happen. Or chaos will happen. So, how do we get to the point where we feel comfortable enough to let go. And, more importantly, how do we teach others to get to that point? I think that the way that we do that is by recognizing that the heart of programming isn’t code, but communication. That’s why we call them programming languages. And we can learn a lot from how people learn languages to help us along our ten thousand hour path to get to the point where we can build alive systems by letting go 16
  33. 33. Imperative Programming Functional Programming Logic Programming Dynamic Typing Static Typing @cory_foy foyc@coryfoy.com Thursday, November 14, 13 This first is the understanding of how languages/paradigms affect our viewpoints. Roman Jakobson points out “Languages differ...must convey vs what they may convey”. “dinner with a neighbor last night”, doesn’t reveal if it was a male or female. But if I said in German, I would be obliged to (Nachbar vs Nachbarin). Functional: context of reduction of terms. Imperative: statement of the process, and logic: statement of the result. Static: abstractions sooner, dynamic: abstraction to be held off 17
  34. 34. Coding Standards Define Dialects @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 18 The second is that even within languages we have dialects. We have to agree on what that common dialect is going to be. This is traditionally the essence of coding standards - what is our agreed upon dialect?
  35. 35. Coding Standards Define Dialects @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 18 The second is that even within languages we have dialects. We have to agree on what that common dialect is going to be. This is traditionally the essence of coding standards - what is our agreed upon dialect?
  36. 36. Coding Standards Define Dialects @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 18 The second is that even within languages we have dialects. We have to agree on what that common dialect is going to be. This is traditionally the essence of coding standards - what is our agreed upon dialect?
  37. 37. BICS CALP @cory_foy foyc@coryfoy.com Thursday, November 14, 13 The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code 19
  38. 38. BICS CALP @cory_foy foyc@coryfoy.com Thursday, November 14, 13 The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code 19
  39. 39. BICS Context Embedded Context Reduced CALP @cory_foy foyc@coryfoy.com Thursday, November 14, 13 The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code 19
  40. 40. Cognitively Undemanding - Copying from the board - Reading a Map - Face to Face Conversation - Selecting food in the lunchroom BICS Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code 19
  41. 41. Cognitively Undemanding - Copying from the board - Reading a Map - Face to Face Conversation - Selecting food in the lunchroom BICS - Following a class schedule - Telephone Conversation - Oral Presentations - Getting an absence excuse Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code 19
  42. 42. Cognitively Undemanding - Copying from the board - Reading a Map - Face to Face Conversation - Selecting food in the lunchroom BICS - Following a class schedule - Telephone Conversation - Oral Presentations - Getting an absence excuse Context Embedded Context Reduced - Demonstrations - Basic Math Computations - Science Experiments CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code 19
  43. 43. Cognitively Undemanding - Copying from the board - Reading a Map - Face to Face Conversation - Selecting food in the lunchroom BICS - Following a class schedule - Telephone Conversation - Oral Presentations - Getting an absence excuse Context Embedded Context Reduced - Demonstrations - Basic Math Computations - Science Experiments - Standardized Tests - Math Concepts and Applications - Listening to a Lecture CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code 19
  44. 44. Cognitively Undemanding BICS Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more. 20
  45. 45. Foy-Z Cognitively Undemanding BICS Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more. 20
  46. 46. Foy-Z Cognitively Undemanding BICS Katas Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more. 20
  47. 47. Foy-Z Cognitively Undemanding BICS Katas Koans Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more. 20
  48. 48. Foy-Z Cognitively Undemanding BICS Katas Koans Context Embedded Context Reduced Principles CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more. 20
  49. 49. Foy-Z Cognitively Undemanding BICS Katas Koans Context Embedded Context Reduced Principles Patterns CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more. 20
  50. 50. Katas @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Let’s start with Katas. First described in the software world by Pragmatic Dave Thomas, they offer the ability to practice without the solution being the cognitive challenge. In short, they allow developers to practice varying externally motivated viewpoints. 21
  51. 51. Conway’s Game of Life - Infinite Grid of Cells - Each Cell has two states - alive or dead - Interacts with neighbors in a well known way http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 22
  52. 52. Conway’s Game of Life - Infinite Grid of Cells - Each Cell has two states - alive or dead - Interacts with neighbors in a well known way http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 22
  53. 53. Conway’s Game of Life - Infinite Grid of Cells - Each Cell has two states - alive or dead - Interacts with neighbors in a well known way http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 22
  54. 54. Conway’s Game of Life - Infinite Grid of Cells - Each Cell has two states - alive or dead - Interacts with neighbors in a well known way http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 22
  55. 55. Conway’s Game of Life - If Statement @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 23
  56. 56. Conway’s Game of Life - If Statement @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 23
  57. 57. Conway’s Game of Life - No Conditional @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 24
  58. 58. Foy-Z Cognitively Undemanding BICS Katas Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 So Katas allow us to not focus on solving the problem, but instead using the problem to explore the space of viewpoints. The context is very high - we cognitively understand the problem, so we can focus on practice. But at some point we need more - and that’s where 25
  59. 59. Foy-Z Cognitively Undemanding BICS Katas Koans Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 So Katas allow us to not focus on solving the problem, but instead using the problem to explore the space of viewpoints. The context is very high - we cognitively understand the problem, so we can focus on practice. But at some point we need more - and that’s where 25
  60. 60. Koans @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 26 Koans come in. Koans provide language-specific nuances - the grammar if you will. They tend to be language specific, but lower context. It’s like practicing nouns and verbs - great to do, but much better if you have some context to put them in. For example (next Edgecase Koans)
  61. 61. https://github.com/neo/ruby_koans @cory_foy foyc@coryfoy.com Thursday, November 14, 13 one of the more famous software Koans was by Edgecase (now called Neo). You can see in the structure it was very specific to the Ruby language - arrays, assets, blocks, etc. 27
  62. 62. Ruby Koans Asserts @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 28
  63. 63. Ruby Koans Arrays @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 29
  64. 64. Foy-Z Cognitively Undemanding BICS Katas Koans Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 So far, we’ve stayed in the BICS realm. BUT! We’ve learned something interesting. The Koans taught us Ruby array management, and we needed that for our exercise, so let’s revisit the Katas 30
  65. 65. Conway’s Game of Life - With Map @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 31
  66. 66. Conway’s Game of Life - With Map @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 31
  67. 67. Foy-Z Cognitively Undemanding BICS Katas Koans Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 At this point, we have enough basic skills that we can begin to get into cognitively demanding work. We have the context, and the grammar, but we don’t know the optimal ways to apply the grammar. That’s where coding principles come in to play 32
  68. 68. Foy-Z Cognitively Undemanding BICS Katas Koans Context Embedded Context Reduced Principles CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 At this point, we have enough basic skills that we can begin to get into cognitively demanding work. We have the context, and the grammar, but we don’t know the optimal ways to apply the grammar. That’s where coding principles come in to play 32
  69. 69. Principles @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Our principles guide us in how we apply our code within the context of what we’re writing. 33
  70. 70. SOLID Principles Do we have duplication (implementation or conceptual)? Single responsibilities? LoD violations? LSP violations? @cory_foy Thursday, November 14, 13 Transition to patterns foyc@coryfoy.com 34
  71. 71. 4 Rules of Simple Design Does this code express all of the ideas we want to express? @cory_foy Thursday, November 14, 13 Patterns. 4 Rules of Simple Design. Fowler. SOLID foyc@coryfoy.com 35
  72. 72. 4 Rules of Simple Design Does this code express all of the ideas we want to express? @cory_foy Thursday, November 14, 13 Patterns. 4 Rules of Simple Design. Fowler. SOLID foyc@coryfoy.com 35
  73. 73. 4 Rules of Simple Design Does this code express all of the ideas we want to express? @cory_foy Thursday, November 14, 13 Patterns. 4 Rules of Simple Design. Fowler. SOLID foyc@coryfoy.com 35
  74. 74. 4 Rules of Simple Design Does this code express all of the ideas we want to express? Are there concepts from our domain that can be expressed? @cory_foy Thursday, November 14, 13 Patterns. 4 Rules of Simple Design. Fowler. SOLID foyc@coryfoy.com 35
  75. 75. 4 Rules of Simple Design Does this code express all of the ideas we want to express? Are there concepts from our domain that can be expressed? @cory_foy Thursday, November 14, 13 Patterns. 4 Rules of Simple Design. Fowler. SOLID foyc@coryfoy.com 35
  76. 76. Fowler’s Perspectives (from UML Distilled) Are we operating at the right level Conceptual, Specification or Implementation? @cory_foy Thursday, November 14, 13 Patterns. 4 Rules of Simple Design. Fowler. SOLID foyc@coryfoy.com 36
  77. 77. Fowler’s Perspectives (from UML Distilled) Are we operating at the right level Conceptual, Specification or Implementation? @cory_foy Thursday, November 14, 13 Patterns. 4 Rules of Simple Design. Fowler. SOLID foyc@coryfoy.com 36
  78. 78. Foy-Z Cognitively Undemanding BICS Katas Koans Context Embedded Context Reduced Principles CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 At this point, we have enough basic skills that we can begin to get into cognitively demanding work. As I mentioned earlier, Design Patterns 37
  79. 79. Foy-Z Cognitively Undemanding BICS Katas Koans Context Embedded Context Reduced Principles Patterns CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 At this point, we have enough basic skills that we can begin to get into cognitively demanding work. As I mentioned earlier, Design Patterns 37
  80. 80. Patterns @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 38 Design Patterns provide a guide for the forces encountered. What does that mean? We have a tendency to think of Design Patterns as recipes to make our code look a certain way. But
  81. 81. @cory_foy Thursday, November 14, 13 Patterns are something else. foyc@coryfoy.com 39
  82. 82. Naming something the name of a pattern does not make it that pattern @cory_foy Thursday, November 14, 13 Patterns are something else. foyc@coryfoy.com 39
  83. 83. Naming something the name of a pattern does not make it that pattern Putting patterns in our code does not make our code good @cory_foy Thursday, November 14, 13 Patterns are something else. foyc@coryfoy.com 39
  84. 84. Porch Swing @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 40
  85. 85. Porch Swing @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 40
  86. 86. Swimming Pool @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 41
  87. 87. Swimming Pool @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 41
  88. 88. Hedge Trimmer @cory_foy Thursday, November 14, 13 Not a pattern, but a death trap (next GoF Book / Structure of Patterns) foyc@coryfoy.com 42
  89. 89. Hedge Trimmer @cory_foy Thursday, November 14, 13 Not a pattern, but a death trap (next GoF Book / Structure of Patterns) foyc@coryfoy.com 42
  90. 90. • Pattern Name • Intent • Also Known As • Motivation / Forces • Applicability • Structure • Participants • Collaboration • Consequences • Implementation • Sample Code • Known Uses • Related Patterns @cory_foy foyc@coryfoy.com Thursday, November 14, 13 The GoF Book wasn’t a beginners guide. It was Erich’s PhD Thesis. Patterns are designed to put into form the forces you may run into while building code. What does that mean? 43
  91. 91. Server @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions. 44
  92. 92. - Countries - Products - Locations Server @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions. 44
  93. 93. - Countries - Products - Locations - Send Data - Receive Data Server @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions. 44
  94. 94. Multiple Pictures - Countries - Products - Locations - Send Data - Receive Data Server @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions. 44
  95. 95. Multiple Pictures - Countries - Products - Locations Send Pictures - Send Data - Receive Data Server @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions. 44
  96. 96. Multiple Pictures - Countries - Products - Locations Send Pictures - Send Data - Receive Data Server @cory_foy Storage Options foyc@coryfoy.com Thursday, November 14, 13 Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions. 44
  97. 97. Offline @cory_foy foyc@coryfoy.com Thursday, November 14, 13 One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline? 45
  98. 98. Offline Not allow send @cory_foy Queue items to send foyc@coryfoy.com Thursday, November 14, 13 One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline? 45
  99. 99. Offline Not allow send Automatically @cory_foy Queue items to send Manually foyc@coryfoy.com Thursday, November 14, 13 One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline? 45
  100. 100. Offline Not allow send Automatically Queue items to send Manually Forces: - User has to remember to send - User can’t do other tasks until sent - User has to send each one @cory_foy foyc@coryfoy.com Thursday, November 14, 13 One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline? 45
  101. 101. Offline Not allow send Automatically Forces: - Store multiple requests - Schedule to run them - Handle failed requests - Allow user to see status @cory_foy Queue items to send Manually Forces: - User has to remember to send - User can’t do other tasks until sent - User has to send each one foyc@coryfoy.com Thursday, November 14, 13 One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline? 45
  102. 102. http://www.soapatterns.org/asynchronous_queuing.php @cory_foy foyc@coryfoy.com Thursday, November 14, 13 So the patterns we choose are a result of the forces we are trying to resolve - the forces inherent in the solution itself. 46
  103. 103. Foy-Z Cognitively Undemanding BICS Context Embedded Context Reduced CALP @cory_foy Cognitively Demanding foyc@coryfoy.com Thursday, November 14, 13 So now that we’ve got a framework on how to get the point of understanding, now what? Well, our code is getting happier, because 47
  104. 104. @cory_foy Thursday, November 14, 13 we’ve begun addressing some of the key issues in being able to listen to it. foyc@coryfoy.com 48
  105. 105. We don’t understand the language @cory_foy Thursday, November 14, 13 we’ve begun addressing some of the key issues in being able to listen to it. foyc@coryfoy.com 48
  106. 106. We don’t understand the language We don’t have common context @cory_foy Thursday, November 14, 13 we’ve begun addressing some of the key issues in being able to listen to it. foyc@coryfoy.com 48
  107. 107. We don’t understand the language We don’t have common context We don’t know the grammar @cory_foy Thursday, November 14, 13 we’ve begun addressing some of the key issues in being able to listen to it. foyc@coryfoy.com 48
  108. 108. We don’t understand the language We don’t have common context We don’t know the grammar We don’t know how to apply the grammar @cory_foy Thursday, November 14, 13 we’ve begun addressing some of the key issues in being able to listen to it. foyc@coryfoy.com 48
  109. 109. We don’t understand the language We don’t have common context We don’t know how to apply the grammar We don’t know the grammar We don’t know what’s appropriate @cory_foy Thursday, November 14, 13 we’ve begun addressing some of the key issues in being able to listen to it. foyc@coryfoy.com 48
  110. 110. http://www.flickr.com/photos/jakeandlindsay/5524669257 @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 49 So how to we apply it? How do we use that to now let go? First, diagrams aren’t bad. There’s nothing wrong with sketching out a plan. But, “No plan survives first contact with the enemy”. So pay attention to the forces more than the plan.
  111. 111. http://www.soapatterns.org/asynchronous_queuing.php @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 50 For example, looking at this pattern again, notice the impacts. We may say to ourselves, we want an Aysnc Queue, so fine, be on the lookout for that. But don’t blindly just shove an async queue in. Watch for your code to tell you it needs it. (This also applies to databases and many other things we “Know we need”)
  112. 112. http://marchoeijmans.blogspot.com/2013/03/test-driven-development-tdd.html (Although I disagree with the article) @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Second: If you haven’t done TDD, or aren’t doing it, I’d highly recommend spending some time with Katas trying it out. What I find powerful is that it makes no qualms about your design. Don’t write a design, and then write tests to prove you are writing your design. Let the tests guide you. See what design emerges from them. 51
  113. 113. @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  114. 114. Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  115. 115. Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  116. 116. Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  117. 117. API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  118. 118. Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  119. 119. Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  120. 120. Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  121. 121. Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  122. 122. Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  123. 123. Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets” 52
  124. 124. Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 There’s nothing wrong with a vision. And as you work on slices, you can check against the overall vision to see if you are on the path you expected, or if your vision needs to change. Not the code, but the vision. 53
  125. 125. Vision Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 There’s nothing wrong with a vision. And as you work on slices, you can check against the overall vision to see if you are on the path you expected, or if your vision needs to change. Not the code, but the vision. 53
  126. 126. Vision Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 There’s nothing wrong with a vision. And as you work on slices, you can check against the overall vision to see if you are on the path you expected, or if your vision needs to change. Not the code, but the vision. 53
  127. 127. Vision Front End Layer API Layer Service Layer Stored Procedures Database @cory_foy foyc@coryfoy.com Thursday, November 14, 13 There’s nothing wrong with a vision. And as you work on slices, you can check against the overall vision to see if you are on the path you expected, or if your vision needs to change. Not the code, but the vision. 53
  128. 128. Pay attention to the forces Let the code (and tests!) guide your design Develop a vision, but use it as a guide, not a whipping post @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 54 These things together, along with the solid understanding of the different paradigms and approaches are going to get you to the point where you can let go of the “willful images” and start really listening to your code. And when you listen to your code
  129. 129. @cory_foy foyc@coryfoy.com Thursday, November 14, 13 you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen. 55
  130. 130. if coder_listens? @cory_foy foyc@coryfoy.com Thursday, November 14, 13 you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen. 55
  131. 131. if coder_listens? puts “:-)” @cory_foy foyc@coryfoy.com Thursday, November 14, 13 you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen. 55
  132. 132. if coder_listens? puts “:-)” else @cory_foy foyc@coryfoy.com Thursday, November 14, 13 you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen. 55
  133. 133. if coder_listens? puts “:-)” else puts “:`-(“ @cory_foy foyc@coryfoy.com Thursday, November 14, 13 you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen. 55
  134. 134. if coder_listens? puts “:-)” else puts “:`-(“ end @cory_foy foyc@coryfoy.com Thursday, November 14, 13 you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen. 55
  135. 135. if coder_listens? puts “:-)” else puts “:`-(“ end @cory_foy foyc@coryfoy.com Thursday, November 14, 13 you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen. 55
  136. 136. Cory Foy (@cory_foy) foyc@coryfoy.com www.coryfoy.com @cory_foy Thursday, November 14, 13 foyc@coryfoy.com 56

×